??? 03/23/12 12:49 Read: times |
#186828 - LCD 4 BIT Responding to: ???'s previous message |
I was using my phone yesterday so couldnt post my code. I had to change alot of it and im sending a string but it works anyway.The wait LCD label is redundant,better off using a delay routine but I was simulating on multism so didnt include it.
...$MOD51 ; This includes 8051 definitions for the Metalink assembler ; Please insert your code here. ; Please insert your code here. lcd_port equ P3 ;LCD connected to Port3 DB4 equ p3.0 DB5 equ p3.1 DB6 equ p3.2 DB7 equ p3.3 EN equ P3.7 ;Enable connected to P3.7 RS equ P3.5 ;Register select to P3.5 RW equ p3.6 temp equ 50h delay equ 51h lcd_init: acall lcd_reset ;Call LCD Reset sequence mov a,#28H ;4-bit, 2 line, 5x7 dots acall lcd_cmd ;Call LCD command mov a,#0CH ;Display ON cursor OFF acall lcd_cmd ;Call LCD command mov a,#06H ;Set entry mode (Auto increment) acall lcd_cmd ;Call LCD command mov a,#80H ;Bring cursor to line 1 acall lcd_cmd ;Call LCD command jmp main lcd_reset: ;LCD reset sequence mov lcd_port, #0FFH ;20mS delay acall delayms mov lcd_port, #83H ;Data = 30H, EN = 1, First Init mov lcd_port, #03H ;Data = 30H, EN = 0 ;Delay 15mS acall delayms mov lcd_port, #83H ;Second Init, Data = 30H, EN = 1 mov lcd_port, #03H ;Data = 30H, EN = 0 ;Delay 5mS acall delayms mov lcd_port, #83H ;Third Init mov lcd_port, #03H ;Delay 5mS acall delayms mov lcd_port, #82H ;Select Data width (20H for 4bit) mov lcd_port, #02H ;Data = 20H, EN = 0 ;Delay 5mS acall delayms ret ;program//////////////////////////////////////////////////// main: LCALL CLEAR_LCD ;clearing lcd. mov dptr,#my_string ACALL LCD_sendstring lcall line2 mov dptr,#my_string1 ACALL LCD_sendstring LCALL CLEAR_LCD ;//////////////////////////////////////////////////////////// WAIT_LCD: ret ;; Something wrong with this sub CLR EN ;bring EN low after every instruction CLR RS ;It's a command SETB RW ;it's a read command ;; MOV dta, #0FFH ;Set all pins(P1) High initially SETB EN ;Clock Out Command To LCD ;; MOV A, dta ;Read the return value ;; JB ACC.7, WAIT_LCD ;if bit 7 high, LCD Still busy CLR EN ;Finish the command CLR RW ;turn off RW for future commands RET ;return lcd_cmd: mov temp,a ;Save a copy of command to temp swap a ;Swap to use higher nibble anl a,#0FH ;Mask the first four bits add a,#80H ;Enable = 1, RS = 0 mov lcd_port,a ;Move it to lcd port anl a,#0FH ;Enable = 0, RS = 0 mov lcd_port,a ;Move to lcd port mov a,temp ;Reload the command from temp anl a,#0FH ;Mask first four bits add a,#80H ;Enable = 1 mov lcd_port,a ;Move to port anl a,#0FH ;Enable = 0 mov lcd_port,a ;Move to lcd port ret CLEAR_LCD: CLR RS MOV A,#01h LCALL lcd_cmd ;Write A as two separate nibbles to LCD LCALL WAIT_LCD RET line1: CLR RS MOV A,#80h LCALL lcd_cmd ;Write A as two separate nibbles to LCD LCALL WAIT_LCD RET line2: CLR RS MOV A,#0C0h LCALL lcd_cmd ;Write A as two separate nibbles to LCD LCALL WAIT_LCD ret lcd_dat: ;LCD data Routine mov temp,a ;Keep copy of data in temp swap a ;We need higher nibble anl a,#0FH ;Mask first four bits add a,#0A0H ;Enable = 1, RS = 1 mov lcd_port,a ;Move to lcd port nop clr EN ;Enable = 0 mov a,temp ;Reload the data from temp anl a,#0FH ;we need lower nibble now add a,#0A0H ;Enable = 1, RS = 1 mov lcd_port,a ;Move to lcd port nop clr EN ;Enable = 0 mov delay,#1 ;Delay 1mS acall delayms ret LCD_sendstring: clr a ;clear Accumulator for any previous data movc a,@a+dptr ;load the first character in accumulator jz exit ;go to exit if zero acall lcd_dat ;send first char inc dptr ;increment data pointer sjmp LCD_sendstring ;jump back to send the next character ret exit: ret delayms: ret my_string: DB 'LCD Tutorial',00H my_string1: DB 'LCD Tutorial',00H END |
Topic | Author | Date |
4 Bit LCD | 01/01/70 00:00 | |
I am no sherlock Holmes, but ... | 01/01/70 00:00 | |
LCD | 01/01/70 00:00 | |
Did you think about accesses using DATA1? | 01/01/70 00:00 | |
lcd | 01/01/70 00:00 | |
So you found a solution ... | 01/01/70 00:00 | |
LCD 4 BIT | 01/01/70 00:00 | |
where did you get that idea? | 01/01/70 00:00 | |
Using Read Cycle to LCD | 01/01/70 00:00 | |
of course, you can not use a signal that is not there | 01/01/70 00:00 | |
busy flad check | 01/01/70 00:00 | |
Why not solve your problem BEFORE trying to save pins? | 01/01/70 00:00 | |
Premature optimisation | 01/01/70 00:00 |