Help with HD44780-based Character-LCD

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Help with HD44780-based Character-LCD

Post by econnections »

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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Help with HD44780-based Character-LCD

Post by Benj »

Hello

Ok I think I see the problem now.

The 8-bit command that is being sent is

00110000

This is sent out 5 times before the 4-bit mode command is issued.

The command does not do anything other then get the LCD synchronised to accept the 4-bit command when it is issued. This ensures that the LCD is powered up and in the correct state to allow the 4-bit command to work. This is also why our driver always works rather then other peoples drivers that only sometimes work.

Hope this helps.

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: Help with HD44780-based Character-LCD

Post by econnections »

Hi Ben,

That clarifies things for me. I didn't realise you were sending the same command five times.

If I want to use the LCD to show temperature or any other value that needs to be written to the same character locations on the device what command do I use?
e.g. I want to write the temperature value 27C starting at line 2, char 4.
Do I write directly to three memory location in the LCD? And if so which command?

Thanks again for your help. I find the datasheet lacking any examples I can follow.

------Update---------------------------------------------------------------------------------------------------
I think I understand it - reference http://www.geocities.com/dinceraydin/lcd/intro.htm

Set DD RAM address where you want the data/cursor to appear. In this case the address is 43h
Therefore instruction code is:
RS RW 1 [### ####] address
0 0 1 1000011

Write data to DD RAM:
RS RW [#### ####] data
1 0 [character code in binary]
Last edited by econnections on Wed Feb 25, 2009 7:16 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Help with HD44780-based Character-LCD

Post by Benj »

Hello

I agree, the datasheets for these devices are useless. I remember having very similar problems when trying to get up and running with these displays. Also your code for the cursor function looks correct, glad you have managed to sort this.

Post Reply