??? 04/23/05 01:35 Read: times |
#92213 - HD44780 showing garbage |
After successfully having implemented interrupt-driven delay-routines, I am now trying to attach an HD44780-compatible display (4x40) to my DS89C450.
I opted for a 4-bit connection using P1.0-3 for the data-legs (D4-D7) and P1.4-7 for EN1,EN2,RS,RW. Due to the size of the display it has to Chip Enable lines. The basic code, as found here http://www.8052.com/tutlcd2.phtml works, but the display shows garbage, which I cannot map to any of the font-tables in the Hitachi HD44780 datasheet. I had to modify the assembly-routines to take care of my different pinout, but considering that the display does in fact respond, I consider the cabling part a matter well done. I suspect the error to be in the software and thus I would appreciate any suggestions for corrections to the below code. /Thomas P1 EQU 090h DB4 EQU P1.0 DB5 EQU P1.1 DB6 EQU P1.2 DB7 EQU P1.3 EN1 EQU P1.4 EN2 EQU P1.5 RS EQU P1.6 RW EQU P1.7 DAT EQU P1 RSEG ?PR?READ_2_NIBBLES1?LCD_ROUTINES READ_2_NIBBLES1: ORL DAT,#00Fh ;Be sure to release datalines (set outputlatches ;to '1') so we can read the LCD SETB EN1 NOP MOV A,DAT ;Read first part of the return value (high nibble) CLR EN1 ANL A,#00Fh ;Only low nibble is usable SWAP A ;Last received is actually high nibble, so put it in place PUSH ACC SETB EN1 NOP MOV A,DAT ;Read second part of the return value (low nibble) CLR EN1 ANL A,#00Fh ;Only low nibble is usable MOV R7,A POP ACC ORL A,R7 ;And combine it with low nibble CLR RS CLR RW RET RSEG ?PR?READ_2_NIBBLES2?LCD_ROUTINES READ_2_NIBBLES2: ORL DAT,#00Fh ;Be sure to release datalines (set outputlatches ;to '1') so we can read the LCD SETB EN2 NOP MOV A,DAT ;Read first part of the return value (high nibble) CLR EN2 ANL A,#00Fh ;Only low nibble is usable SWAP A ;Last received is actually high nibble, so put it in place PUSH ACC SETB EN2 NOP MOV A,DAT ;Read second part of the return value (low nibble) CLR EN2 ANL A,#00Fh ;Only low nibble is usable MOV R7,A POP ACC ORL A,R7 ;And combine it with low nibble CLR RS CLR RW RET RSEG ?PR?WRITE_2_NIBBLES1?LCD_ROUTINES WRITE_2_NIBBLES1: PUSH ACC ;Save A for high nibble ORL DAT,#0Fh ;Bits 0..3 = 1 ORL A,#0Fh ;Don't affect bits 4-7 SWAP A ;Swap high nibble into low region ANL DAT,A ;High nibble to display SETB EN1 NOP CLR EN1 POP ACC ;Prepare to send the second nibble ORL DAT,#0Fh ; Bits 0...3 = 1 ORL A,#0Fh ; Don't affect bits 4...7 ANL DAT,A ;Low nibble to display SETB EN1 NOP CLR EN1 CLR RS CLR RW RET RSEG ?PR?WRITE_2_NIBBLES2?LCD_ROUTINES WRITE_2_NIBBLES2: PUSH ACC ;Save A for low nibble ORL DAT,#0Fh ;Bits 0..3 = 1 ORL A,#0Fh ;Don't affect bits 4-7 SWAP A ;Swap high nibble into low region ANL DAT,A ;High nibble to display SETB EN2 NOP CLR EN2 POP ACC ;Prepare to send the second nibble ORL DAT,#0Fh ; Bits 4...7 <- 1 ORL A,#0Fh ; Don't affect bits 0...3 ANL DAT,A ;Low nibble to display SETB EN2 NOP CLR EN2 CLR RS CLR RW RET RSEG ?PR?WAIT_LCD1?LCD_ROUTINES WAIT_LCD1: CLR RS ;It's a command SETB RW ;It's a read command LCALL READ_2_NIBBLES1 ;Take two nibbles from LCD in A JB ACC.7,WAIT_LCD1 ;If bit 7 high, LCD still busy CLR RW ;Turn off RW for future commands RET RSEG ?PR?WAIT_LCD2?LCD_ROUTINES WAIT_LCD2: CLR RS ;It's a command SETB RW ;It's a read command LCALL READ_2_NIBBLES2 ;Take two nibbles from LCD in A JB ACC.7,WAIT_LCD2 ;If bit 7 high, LCD still busy CLR RW ;Turn off RW for future commands RET RSEG ?PR?INIT_LCD1?LCD_ROUTINES INIT_LCD1: CLR RS CLR RW CLR EN1 MOV A,#2Ch SWAP A ORL A,#0Fh ANL DAT,A SETB EN1 ; Init 4-bit mode, take 1 NOP CLR EN1 LCALL WAIT_LCD1 MOV A,#2Ch ;Init display for 4-bit mode LCALL WRITE_2_NIBBLES1 ;Write A as two separate nibbles to LCD CLR EN1 LCALL WAIT_LCD1 MOV A,#0Eh LCALL WRITE_2_NIBBLES1 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD1 MOV A,#06h LCALL WRITE_2_NIBBLES1 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD1 CLR RS CLR RW RET RSEG ?PR?INIT_LCD2?LCD_ROUTINES INIT_LCD2: CLR RS CLR RW CLR EN2 MOV A,#2Ch SWAP A ORL A,#0Fh ANL DAT,A SETB EN2 ; Init 4-bit mode, take 1 NOP CLR EN2 LCALL WAIT_LCD2 MOV A,#2Ch ;Init display for 4-bit mode LCALL WRITE_2_NIBBLES2 ;Write A as two separate nibbles to LCD CLR EN2 LCALL WAIT_LCD2 MOV A,#0Eh LCALL WRITE_2_NIBBLES2 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD2 MOV A,#06h LCALL WRITE_2_NIBBLES2 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD2 CLR RS CLR RW RET RSEG ?PR?CLEAR_LCD1?LCD_ROUTINES CLEAR_LCD1: CLR RS MOV A,#01h LCALL WRITE_2_NIBBLES1 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD1 CLR RS CLR RW RET RSEG ?PR?CLEAR_LCD2?LCD_ROUTINES CLEAR_LCD2: CLR RS MOV A,#01h LCALL WRITE_2_NIBBLES2 ;Write A as two separate nibbles to LCD LCALL WAIT_LCD2 CLR RS CLR RW RET RSEG ?PR?_write_lcd1?LCD_ROUTINES _write_lcd1: MOV A,R7 SETB RS LCALL WRITE_2_NIBBLES1 LCALL WAIT_LCD1 RET RSEG ?PR?_WRITE_LCD2?LCD_ROUTINES _WRITE_LCD2: MOV A,R7 SETB RS LCALL WRITE_2_NIBBLES2 LCALL WAIT_LCD2 RET |
Topic | Author | Date |
HD44780 showing garbage | 01/01/70 00:00 | |
LCD problems | 01/01/70 00:00 | |
embarassing | 01/01/70 00:00 | |
Congradulations, You are the first. | 01/01/70 00:00 | |
honesty with respect to admitting errors | 01/01/70 00:00 | |
We're all human![]() | 01/01/70 00:00 |