mobile-it
Advanced Member level 1
![Advanced Member level 1](/styles/images/ranks/glevel1.gif)
reg2051.h
Can someone find the problem in my code for a LCD program?
Can someone find the problem in my code for a LCD program?
Code:
// With help from the following website:
// [I]**broken link removed**[/I]
//Definitions
DEF DB4 0
DEF DB5 1
DEF DB6 2
DEF DB7 3
DEF EN 4
DEF RS 5
DEF RW 6
//Load 0 to Accumulator
LOAD 0
$Main
CALL $INIT_LCD
CALL $CLEAR_LCD
RAMWRT 3 DAT 'H'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'E'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'L'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'L'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'O'
CALL $WRITE_TEXT
RAMWRT 3 DAT ' '
CALL $WRITE_TEXT
RAMWRT 3 DAT 'W'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'O'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'R'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'L'
CALL $WRITE_TEXT
RAMWRT 3 DAT 'D'
CALL $WRITE_TEXT
$READ_2_NIBBLES
BITSET EN
IOWRT ACC
IOREAD
RAMWRT 4
BITCLR EN
IOWRT ACC
BITSET EN
IOWRT ACC
IOREAD
BITCLR 7
BITCLR 6
BITCLR 5
BITCLR 4
RAMWRT 5
BITCLR EN
IOWRT ACC
RAMREAD 4
SHLE
SHLE
SHLE
SHLE
RAMWRT 4
RAMREAD 4
ADD RAM 5
RAMWRT 2
RETURN
$WRITE_2_NIBBLES
RAMREAD 3
BITSET EN
IOWRT ACC
BITCLR EN
IOWRT ACC
RAMREAD 3
ROL
ROL
ROL
ROL
BITSET EN
IOWRT ACC
BITCLR EN
IOWRT ACC
RETURN
$WAIT_LCD
BITCLR RS
IOWRT ACC
BITSET RW
CALL $READ_2_NIBBLES
RAMREAD 2
BITTST 7
JUMP IFNOT ZZERO $WAIT_LCD
BITCLR RW
IOWRT ACC
RETURN
$INIT_LCD
BITCLR RS
IOWRT ACC
BITCLR RW
IOWRT ACC
BITCLR EN
IOWRT ACC
BITSET EN
IOWRT ACC
OR 0x20
IOWRT ACC
//MOV DATA,#28h
BITCLR EN
IOWRT ACC
CALL $WAIT_LCD
RAMWRT 3 DAT 0x20
//MOV A,#28h
//Here writing to RAM is needed!!!
CALL $WRITE_2_NIBBLES
CALL $WAIT_LCD
//MOV A,#0Eh
RAMWRT 3 DAT 0x0E
CALL $WRITE_2_NIBBLES
CALL $WAIT_LCD
//MOV A,#06h
RAMWRT 3 DAT 0x06
CALL $WRITE_2_NIBBLES
CALL $WAIT_LCD
RETURN
$CLEAR_LCD
BITCLR RS
IOWRT ACC
//MOV A,#01h
CALL $WRITE_2_NIBBLES
CALL $WAIT_LCD
RETURN
$WRITE_TEXT
BITSET RS
IOWRT ACC
CALL $WRITE_2_NIBBLES
CALL $WAIT_LCD
RETURN