Help with HD44780-based Character-LCD
Posted: Wed Feb 18, 2009 2:20 pm
Reference: Tutorial 29, Assembly for PICMicro v2.
I'm trying to undestand the initialiastion codes you have configured for the LCD. I started out by reading several datasheets and Googling for help but when I write my initialisation routine it doesn't work and some of your coding does not appear to conform to the settings shown in the table below which is taken from one of the datasheets. Although your codes works I need help to understand how you selected bits in some of the instructions.
I have added coments against you codes. Your help would be much appreciated.
--------- initialisation starts------------------------------------------------------------------------
MOVLW B'00110011' ;initialise lcd - first byte
CALL LCDOUT
;comments - this is a 'Function Set' and you are using it as an 8-bit attention call to the lcd in its default state. I believe there is no need for
bits 0-1 to be set. In my program I use 0011 0000 and that appears to be ok
MOVLW B'00110011' ;2nd byte (repeat of first)
CALL LCDOUT
;comments - repeat attention call but again I use 0011 0000. Some people say this call should be made a third time but I think that unncessary.
MOVLW B'00110010' ;set for 4-bit operation
CALL LCDOUT
;comments - this I don't understand. To set 4-bit mode the datasheet shows use 'Function Set' 0010 0000. Lower nibble sets
;lines and font so I would have used 0010 N F ** = 0010 1100 (2 lines, 5x7 font) but this doesn't work. Therefore to set 4-bit
;mode I would use 0010 0000 but this don't work. Only your version works which is non standard
MOVLW B'00101100' ;function mode - 4-bit, 2 lines, 5x8 font
CALL LCDOUT
;comments - here the lines and font are now set but surely this should have been achieved in the previous instruction?
MOVLW B'00000110' ;entry mode (0000 01,ID,S) - ID:increment by 1 cursor move direction, S:NO display shift
CALL LCDOUT
;comments - I happy with this
MOVLW B'00001100' ;display control (0000 1,D,C,B)- D:display on, C:cursor off, B:blink off
CALL LCDOUT
; comments - I happy with this
MOVLW B'00000001' ;clear display (0000 0001)
CALL LCDOUT
comments - I happy with this
MOVLW B'00000010' ;return home (0000 001*), cursor home & set DDRAM address to zero
CALL LCDOUT
;comments - I happy with this but you initialiation routine appears longer than shown in datasheets
--------- initialisation ends ------------------------------------------------------------------------
Clear display 0 0 0 0 0 0 0 0 0 1 Clears display and returns cursor to the home position (address 0)
Cursor home 0 0 0 0 0 0 0 0 1 * Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged
Entry mode set 0 0 0 0 0 0 0 1 I/D S Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write
Display On/Off control 0 0 0 0 0 0 1 D C B Sets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B)
Cursor/display shift 0 0 0 0 0 1 S/C R/L * * Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM contents remains unchanged
Function set 0 0 0 0 1 DL N F * * Sets interface data length (DL), number of display line (N) and character font(F)
I/D 0 = Decrement cursor position 1 = Increment cursor position
S 0 = No display shift 1 = Display shift
D 0 = Display off 1 = Display on
C 0 = Cursor off 1 = Cursor on
B 0 = Cursor blink off 1 = Cursor blink on
S/C 0 = Move cursor 1 = Shift display
R/L 0 = Shift left 1 = Shift right
DL 0 = 4-bit interface 1 = 8-bit interface
N 0 = 1 line 1 = 2 lines
F 0 = 5x7 dots 1 = 5x10 dots
Reference: http://home.iae.nl/users/pouweha/lcd/lcd0.shtml Table 2.3
I'm trying to undestand the initialiastion codes you have configured for the LCD. I started out by reading several datasheets and Googling for help but when I write my initialisation routine it doesn't work and some of your coding does not appear to conform to the settings shown in the table below which is taken from one of the datasheets. Although your codes works I need help to understand how you selected bits in some of the instructions.
I have added coments against you codes. Your help would be much appreciated.
--------- initialisation starts------------------------------------------------------------------------
MOVLW B'00110011' ;initialise lcd - first byte
CALL LCDOUT
;comments - this is a 'Function Set' and you are using it as an 8-bit attention call to the lcd in its default state. I believe there is no need for
bits 0-1 to be set. In my program I use 0011 0000 and that appears to be ok
MOVLW B'00110011' ;2nd byte (repeat of first)
CALL LCDOUT
;comments - repeat attention call but again I use 0011 0000. Some people say this call should be made a third time but I think that unncessary.
MOVLW B'00110010' ;set for 4-bit operation
CALL LCDOUT
;comments - this I don't understand. To set 4-bit mode the datasheet shows use 'Function Set' 0010 0000. Lower nibble sets
;lines and font so I would have used 0010 N F ** = 0010 1100 (2 lines, 5x7 font) but this doesn't work. Therefore to set 4-bit
;mode I would use 0010 0000 but this don't work. Only your version works which is non standard
MOVLW B'00101100' ;function mode - 4-bit, 2 lines, 5x8 font
CALL LCDOUT
;comments - here the lines and font are now set but surely this should have been achieved in the previous instruction?
MOVLW B'00000110' ;entry mode (0000 01,ID,S) - ID:increment by 1 cursor move direction, S:NO display shift
CALL LCDOUT
;comments - I happy with this
MOVLW B'00001100' ;display control (0000 1,D,C,B)- D:display on, C:cursor off, B:blink off
CALL LCDOUT
; comments - I happy with this
MOVLW B'00000001' ;clear display (0000 0001)
CALL LCDOUT
comments - I happy with this
MOVLW B'00000010' ;return home (0000 001*), cursor home & set DDRAM address to zero
CALL LCDOUT
;comments - I happy with this but you initialiation routine appears longer than shown in datasheets
--------- initialisation ends ------------------------------------------------------------------------
Clear display 0 0 0 0 0 0 0 0 0 1 Clears display and returns cursor to the home position (address 0)
Cursor home 0 0 0 0 0 0 0 0 1 * Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged
Entry mode set 0 0 0 0 0 0 0 1 I/D S Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write
Display On/Off control 0 0 0 0 0 0 1 D C B Sets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B)
Cursor/display shift 0 0 0 0 0 1 S/C R/L * * Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM contents remains unchanged
Function set 0 0 0 0 1 DL N F * * Sets interface data length (DL), number of display line (N) and character font(F)
I/D 0 = Decrement cursor position 1 = Increment cursor position
S 0 = No display shift 1 = Display shift
D 0 = Display off 1 = Display on
C 0 = Cursor off 1 = Cursor on
B 0 = Cursor blink off 1 = Cursor blink on
S/C 0 = Move cursor 1 = Shift display
R/L 0 = Shift left 1 = Shift right
DL 0 = 4-bit interface 1 = 8-bit interface
N 0 = 1 line 1 = 2 lines
F 0 = 5x7 dots 1 = 5x10 dots
Reference: http://home.iae.nl/users/pouweha/lcd/lcd0.shtml Table 2.3