Wednesday, August 31, 2011

HD44780 16x2 Char LCD Interfacing with microcontroller

    An alphanumeric low cost LCD Display is very essential for may small and big projects to Display various type of information. Hitachi HD44780  Chipset based 16x2 char LCD is Really very cheap and easily available in the local market.

Project Description:-


  In this project we are going to learn various things about this chip set and displaying text on this LCD. The HD44780 16x2 char LCD screen Use 8bit and 4 bit parallel interface with backlight.

This Primary Objective in this project are:-


1.  Displaying  "Hello Word!! LCD " message on the scree.
2.   Interfacing The LCD to the Microcontroller Using 8bit  Mode and 4 Bit Mode.
3.  Generating and Displaying Custom Char on the LCD Screen. clik here for custom char



Operation 
     

      as i have mentioned  before this type of lcd are connected to microcontroller using parallel 8bit or 4bit lines.
using 8 bit method is quite simple but take 8 lines (for data or command)+ 3 control signal total 11 line , i guess few small microcontrollers don't even have that much of I/O lines ,so in 4 bit mode total 7 lines (sometimes 6 ) are required .  in this tutorial i will show you with both of the methods .

Pin description

PIN NUMBER SYMBOL FUNCTION
1 Vss GND
2 Vdd   + 3V or + 5V
3 Vo  Contrast Adjustment
4  RS H/L Register Select Signal
5 R/W H/L Read/Write Signal
6 E    H → L Enable Signal
7  DB0 H/L Data Bus Line
8  DB1 H/L Data Bus Line
9  DB2 H/L Data Bus Line
10  DB3 H/L Data Bus Line
11  DB4 H/L Data Bus Line
12  DB5 H/L Data Bus Line
13  DB6 H/L Data Bus Line
14  DB7 H/L Data Bus Line
15 A/Vee + 3.5V for LED/Negative Voltage Output
16 K K Power Supply for B/L (OV)

in 8 bit mode all the Data line DB0 to DB7 are being used for transferring the the data to lcd but in 4-bit mode only 4 line form DB4 to DB7 are being used to transfer the  8 bit wide data in two peaces one after another .

we can't display any data on the lcd until all the required internal command register of the lcd are not being properly initialized.
to know every thing about this lcd controller .. you can go through it's data sheet
click here to download HD44780 data sheet
so now we will learn how to initialize the lcd.


LCD Commands

Clear Display
clear  and place the cursor in the first position (address 0). The bit I / D to 1 by default.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
0
0
1



Return the cursor to Home
Place the cursor in the home position (address 0) and make the display starts to move from its original position. The contents of the RAM display data (DD RAM) remains unchanged. The address of the RAM for display data (DD RAM) is set to 0.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
0
1
X




Entry Mode in Set
Set cursor moving direction and specify that the display moves to the next position of the screen or not. These operations are performed during reading or writing of the DD RAM or CG RAM. To view usually set bit S = 0.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
1
I / D
S




Display ON / OFF Control
Turn on or off by turning ON / OFF both the LCD (D) as the cursor (C) and whether or not this last flash (B).

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
1
D
C
B




Cursor or Display Shift
Move the cursor to move the LCD without changing the memory contents of the display data DD RAM.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
1
S / C
R / L
X
X



Function Set
Set the size of interface with the data bus (DL), number of lines in the LCD (N) and character type (F).

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
1
DL
N
F
X
X




Set the CG RAM Address
The LCD module defined in addition to all the ASCII character set allows the user to define 4 or 8 characters. The composition of these characters is saved to a CG RAM memory called up to 64 bytes. Each user defined character consists of 16 or 8 bytes that are stored in successive positions of the CG RAM.

Using this instruction sets the CG RAM memory address from which the bytes will be stored that define a character. Running this command all the data that is subsequently read or write this memory made from CG RAM.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
1
CG RAM Address




Set the DD RAM Address
The characters or data to be displayed is stored in a memory called RAM DD then move on to the screen.

Using this instruction sets the address of DD RAM memory from which data will be stored to be displayed. Running this command all data being written to or read then they will from the DD RAM memory.

8Fh addresses 80h to 16 characters correspond to the first row and addresses C0h to CFH to 16 characters of the second row, for this model LCD.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
1
DD RAM Address




Read Busy Flag and Address
E l LCD module takes some time to execute instructions, at which time you should not send another instruction. This flag has a BUSY (busy) indicating that an instruction is being executed.

This reading instruction reports the status of the flag as well as providing the address counter value of the CG RAM or DD RAM according to the latest that has been used.
RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
1
BF
Address DD RAM or CG RAM



Write data to CG or DD RAM

Command to write to DD RAM memory the data to be presented on the screen in ASCII code.

Also written to CG RAM memory bytes to generate user-defined characters.

Previously DD RAM memory addresses or CG RAM memory where you want to write data.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1
0
Byte ASCII character or graphic 




Read Data from CG RAM or DD RAM

Command to read data stored in DD RAM, ASCII code.

Likewise, read CG RAM memory bytes of user-defined characters.

Previously, memory addresses or memory DD RAM CG RAM you want to read the data.

RS
R / W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1
1
Byte ASCII character or graphic




Diagrama de Conexión: Connection Diagram


Simulation ( only if you don't want to test this on the real harware);-


click here to download isis simulation model

DOWNLOAD SOURCE CODE and Firmware

click here to download: ---- 4 bit mode




you may also like  30 volts Panel Volt Meter Using Pic mcu


27 comments:

  1. Is it possible to use only the D port instead of C and D port? If so, what lines of code need to be changed? I am using this board http://www.olimex.com/dev/pic-mt-usb.html
    and have been unable to find any code to make the LCD work. I am quite the newbie.
    My chip is a PIC18F458 and my pin config is

    RS = D0
    RW = D1
    E = D2

    LCD7 = D7
    LCD6 = D6
    LCD5 = D5
    LCD4 = D4

    Thanks,
    Eric

    ReplyDelete
  2. @Eric

    sure you can use any port you like to chage the ports all you have to do is:-
    there is a header file in the source code
    name "lcd16.h"

    in this file there is are few lines
    like

    #define RS PORTDbits.RD5
    #define EN PORTDbits.RD7

    to chage the rs and en signal line just write
    #define RS PORTCbits.RC5

    just change them as you like

    and if you want to chage the D4 to D7 then
    change it in the lcd16.c file from portc to any port

    ReplyDelete
  3. Thanks for your reply. I unfortunately do not see any lines of code that specifies my port configuration in the lcd16.c file. Am I just not seeing it? I appreciate your patience with me.

    Thanks,
    Eric

    ReplyDelete
  4. Not lcd16.c, its lcd16.h .... ok?

    ReplyDelete
  5. Hi, i am Akram i am a new comer in the embeded system programing,i want to use HD-44780 LCD with AT89C51 microcontroller,is it possible to guide me Circut Diagram using AT 89C51 with HD-44780 interface.

    best regard

    Akram

    ReplyDelete
  6. sir,what is the code to read the data present on the 80 location of the 16x2 lcd?

    ReplyDelete
    Replies
    1. hi ,
      as you can see the schematic the R/W pin is grounded the , so first of all you need to connect this pin to a mcu port pin . and then pull this pin to high for read some value .

      Delete
    2. sir all i can see is black boxes can help me

      Delete
  7. sir,
    pls give me lcd circuit pic 16f676 or pic16f72

    rajeevexcelelectronics@gmail.com

    ReplyDelete
  8. you blog is very neat and clean. If you upload videos for the projects outputs it will bring the readers(like me) will enjoy more.
    http://www.npeducations.com

    ReplyDelete
  9. Hi, can you send me the source code for the 12F675, the link is failed!! Thanksssssss!! santiromeroayala@hotmail.com

    ReplyDelete
    Replies
    1. http://www.circuitvalley.com/2011/12/two-wire-serial-lcd-16x2-graphics.html

      Delete
  10. hey which simulator do you use? is possible send me the link to download it, preferably a freeware, i want to simulate LCD along with the internal ADC, i am using PIC18LF23k22 or PIC18f23k20.

    ReplyDelete
  11. Hi! We need to use 16x2 alphanumeric lcd based on hd44780 controller for our project but it is not available in our country, do you know what can we use as an alternative where in it has the same functions and specifications with hd44780. Thank you so much.

    ReplyDelete
  12. normally all 95% LCDs are based on this hd44780 controller, but it dosn't mean that same controller should be in the LCD. you try any LCD hope fully that will work.
    syed a.

    www.micromultitasking.comm

    ReplyDelete
  13. If I were to use a different pic controller and 4MHz crystal or internal oscillator from the pic. Just changing the configuration bits should do it? Would that created some kind of timing issues? I am trying to use PIC16F690. Thanks!

    ReplyDelete
  14. This code does not seem to be working for me. I am using the Pic18f4331 and a 10MHz external oscillator with 33pF capacitors. Does anyone have any suggestions?
    Thanks!

    ReplyDelete
  15. sir, may u plz show the lcd interfacing(4-bit interface) with pic16f877a..............thank u...........

    ReplyDelete
  16. Is it possible to use only the D port instead of C and D port? If so, what lines of code need to be changed?

    ReplyDelete
  17. you can use any port or any pin you like ,

    you have to modify few line in lcdCmd , lcdData, initlcd function , rs and en can also be mapped to different location

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. i want to know.. my project using LM016L Hitachi LCD like in protues.. my simulation was run very well.. but in real hardware.. if i want to use LCD type HD44780 16x2 it is ok??
    i mean the the coding that i use is same for these LCD??

    ReplyDelete
  20. Hi! after loading your #include file ( ldc16.h.) and compiling, I received and error " could not open source file p18f458.h" in your ldc16.h file. How can I fix this error.

    Art

    ReplyDelete
  21. hello ... can you please get me the source code for pic16f877 because the debug failed
    email : rami.live@hotmail.com
    yours faithfully

    ReplyDelete
  22. sir my project is main lcd digital clock display is there,and again two lcds are interfacing with that clock,is lcds are following that time it is how?it is possible sir?

    ReplyDelete