Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HITACHI 44780 which provides a simple interface between the controller & an LCD.
These LCD's are very simple to interface with the controller as well as are cost effective.
The most commonly used ALPHANUMERIC displays are
- 1x16 (Single Line & 16 characters),
- 2x16 (Double Line & 16 character per line),
- 4x20 (four lines & Twenty characters per line
Pin description of LCD: table show the pin description of LCD. 8 pins are required to send data on LCD and 3 pins are required to control the data/command and read/write operation
Pin | Symbol | Function |
1 | Vss | Ground |
2 | Vdd | Supply Voltage |
3 | Vo | Contrast Setting |
4 | RS | Register Select |
5 | R/W | Read/Write Select |
6 | En | Chip Enable Signal |
7-14 | DB0-DB7 | Data Lines |
15 | A/Vee | Gnd for the backlight |
16 | K | Vcc for backlight |
Mode of operation: there are two modes of operation 8 bit and 4 bit.
- 8 bit required 8 data lines to send data/command
- 4 bit required only 4 pins and pin D4-D7 are connected to Vcc
- EN - the ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed.
- R/W - when R/W is low , we are writing to LCD and when R/W is High we reading from LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to GND thus saving one controller line.
- RS - When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen.
To display data on LCD we first need to initialize the LCD by sending different command and then we send data to LCD
Initialization: table show to different value which are need to send on LCD when control pin RS is Low [ we are sending command ] and control pin EN goes High to Low [ show that we are sending some thing to LCD ]
"*" - Not Used/Ignored. This bit can be either "1" or "0"
Clear display:
Send 1 to pins to clear display
| |
Set Cursor Move Direction:
| |
Enable Display/Cursor:
| |
Move Cursor/Shift Display
| |
Set Interface Length
Move Cursor to CGRAM/Display
Read/Write ASCII to the Display
|
so we send different code to LCD to get different characteristic like Display on/off, Cursor blink on/off, Cursor move direction etc
now lets write some code to initialize our LCD but before it we need two subroutine (function) to send command and data on LCD
our LCD is connected to port P1 to send data
Send Data on LCD:
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_data: SETB RS ;Telling the LCD that the data which is being send is to be displayed MOV P1, A ;data to displayed is stored in A and now send to port P1 SETB EN ;EN is High ACALL delay ;a short delay CLR EN ;EN is low to make a high-low pulse RET ; return to main ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Send command to LCD:
i use multisim to simulate my code. and this is the circuit that i used (crystal and capacitor not needed in multisim so i no connect ). if you face any error a reply me.
i will attach .asm and multisim circuit file as soon as possible. thanx for reading......
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_cmd: CLR RS ;Telling the LCD that the data is a command MOV P1,A ; command is send to the port SETB EN ; make EN high ACALL DELAY ;a short delay CLR EN ;EN is low to make a higt-low pulse RET ;return ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Initialize LCD:
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_init: MOV A,#38h ;telling the LCD that we use 8 bit mode, ;2 line display and 5x7 font ;#38h because here DL=1,N=1 and F=0 ;in "set interface length" ACALL lcd_cmd ;sending command to LCD MOV A,#0Eh ;we use Display on,Cursor on and Cursor blinking off ;#0Ch to Display on,Cursor off and Cursor blinking off ACALL lcd_cmd ;sending command to LCD MOV A,#06h ; cursor position auto increment and move cursor to ;right #04 cursor moved to left ACALL lcd_cmd ;sending command to LCD RET ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Clear LCD: clear the lcd and move cursor to home position
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_clr: MOV A,#01h ;clear LCD ACALL lcd_cmd s ;sending command to LCD RET ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
l
now lets send to text to display LCD. we are sending "ElectroNets" to display .here we use simple method but you can also use DPTR to send a string to lcd.
if don't know how to use DPTR, leave a command i will add in post.
;.........................................
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $mod51
RW EQU P2.0 ;change pins according your design RS EQU P2.1 EN EQU P2.2 ORG 0000H CLR RW ;because we are writing to LCD ACALL lcd_clr ;clear display ACALL lcd_init ;initialize the LCD MOV A,'E' ;here we sending a single character at a time and then call lcd_data to tell ACALL lcd_data ;LCD that we sending some thing to display on LCD MOV A,'l' ACALL lcd_data MOV A,'e' ACALL lcd_data MOV A,'c' ACALL lcd_data MOV A,'t' ACALL lcd_data MOV A,'r' ACALL lcd_data MOV A,'o' ACALL lcd_data MOV A,'N' ACALL lcd_data MOV A,'e' ACALL lcd_data MOV A,'t' ACALL lcd_data MOV A,'s' ACALL lcd_data ;...................... all the subroutine goes here ;...................... END ; end of code ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i use multisim to simulate my code. and this is the circuit that i used (crystal and capacitor not needed in multisim so i no connect ). if you face any error a reply me.
i will attach .asm and multisim circuit file as soon as possible. thanx for reading......
don't forget to check LCD interfacing with 8051 in 4 bit mode
here is full working code, protues and keil project files.
hi, that's an excelente post ...
ReplyDeletecan you post te code of "Send command to LCD", isn't here.
tks.
Glad to know you like it.
ReplyDeletethe code is removed by blogger script, i will add it soon as possible because the original file is deleted from my system.
@/\/\/\/\/\/\/\ : i update code.. reply if you face any problem..
ReplyDeleteHello! Can you send me the simulation file please! carlitos_castro87@hotmail.com
ReplyDeleteReally nice post!
i'm Sorry CarlitosC, my computer is formatted due to a wrong software installation, all the files are deleted. I will send if I redo it soon.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@madiha: in which section you getting error and paste your error here. i think it run perfectly when i tested it.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletedo you use simulator (which one) or doing it one hardware.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteok, may be you got the error like "controller receiver command whilst busy" and same for lcd. this is due to insufficient delay between en=1 to en=0, (lcd process slow then controller). i will attach a zip file which include proteus ckt and .asm and .hex files.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletefill are added, you can download now.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteit is Proteus 7.6 SP0, i hope it works now
ReplyDelete(I also decide to write a tutorial in 4 bit mode it will be here soon)
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletesorry, i am busy little bit..
ReplyDeletethe ckt file is in the download.
and if still not work than rply me. or you can chat with me on facebook or gtalk..
glad to know that now you are able to interface lcd. :)
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@madiha, @madhu - why did you remove all your comments.
ReplyDeletehow could you edit this code so there is also a line of characters appearing on the bottom part of the lcd.
ReplyDeleteRead again DDRAM topic in this post..
ReplyDeleteyou can you command 0c0h to print on second line
i need an assembly language of the same program but its display must be animated!!! plz help
ReplyDelete