??? 02/20/13 11:40 Read: times Msg Score: -1 -1 Didn't Search First |
#189413 - 4-bit lcd on 8051 |
I have written the following code to interface an LCD on 8051 using 4 bits. However, the code is not running. Please help.
U equ 31h ;memory location to hold upper nibble L equ 32h ;memory location to hold lower nibble Port equ P2 ;data port to connect LCD EN equ P2.6 ;RS pin connection RW equ P2.5 ;RW pin connection RS equ P2.4 ;EN pin connection ORG 0000h LJMP MAIN ORG 0100H MAIN: ACALL init MOV A, #'H' ; ACALL lcd_data ;in first line of LCD MOV A, #'E' ACALL lcd_data MOV A, #'L' ACALL lcd_data MOV A, #'L' ACALL lcd_data MOV A, #'O ' ACALL lcd_data MOV A, #'' ACALL lcd_data MOV A, #'W' ACALL lcd_data MOV A, #'O' ACALL lcd_data MOV A, #'R' ACALL lcd_data MOV A, #'L' ACALL lcd_data MOV A, #'D' ACALL lcd_data L1: SJMP L1 ;INFINITE LONG LOOP MASK: MOV L,A ;save A at temp location L ANL L,#00FH ;mask it with 0Fh SWAP A ;swap nibble ANL A,#00FH ;mask it with 0fh MOV U,A ;save it at temp location U RET ;return ;move to port subrotine loop: MOV Port,A ;put content of A to port SETB EN ;make EN high ACALL DELAY ;call a short delay routine CLR EN ;clear EN ACALL DELAY ;short delay RET ;return lcd_cmd: CLR RW CLR RS ;clear rs, going to send command ACALL MASK ;separate the command and save to U and L MOV A, U ;copy U to A ACALL loop ;move content of a to port MOV A, L ;copy L to A ACALL loop ;move content of a to port RET ;return lcd_data: CLR RW SETB RS ;RS=1, going to send DATA ACALL MASK ;separate the data and save to U & L MOV A, U ;copy U to A ACALL loop ;send it to LCD MOV A, L ;copy L to A ACALL loop ;send it to LCD RET ;return init: ACALL delay ;some delay to lcd after power on ACALL delay MOV A, #20h ;send 20h to lcd to set 4 bit mode CLR RS ;after that we can use lcd_cmd SETB EN ;make EN switching ACALL delay CLR EN MOV A, #20H ACALL lcd_cmd MOV A, #0CH; display on cursor off ACALL lcd_cmd MOV A, #06H;increment cursor ACALL lcd_cmd MOV A, #01H;clear display screen ACALL lcd_cmd RET delay: MOV R0, #30H L2: MOV R1,#0FAH L3: DJNZ R1, L3 DJNZ R0, L2 RET end |
Topic | Author | Date |
4-bit lcd on 8051 | 01/01/70 00:00 | |
Not protecting RS & RW | 01/01/70 00:00 | |
init forgets to send | 01/01/70 00:00 | |
Error correction | 01/01/70 00:00 | |
Even better... | 01/01/70 00:00 |