EKT222 Microprocessor System Northern Malaysia University College of Engineering
Lab 8: LCD Display Purpose
Interfacing to Liquid Crystal Display (LCD) module
Part A Introduction to LCD
Pin Assignment The pin assignment shown below is an industry standard for small (80 characters or less) alphanumeric LCD modules! "in number ' + . 0 4 6 8 8 '0 '' '+ '. '0 #ymbol (ss (cc (ee 1# 1$3 5 D70 D7' D7+ D7. D70 D7D74 D76 I$% &unction "ower supply ()*D) "ower supply (,-() Contrast ad/ust 0 2 Command input$output ' 2 Data input$output 0 2 3rite to LCD module ' 2 1ead from LCD module 5nable signal (Data strobe) Data bus line 0 (L#7) Data bus line ' Data bus line + Data bus line . Data bus line 0 Data bus line Data bus line 4 Data bus line 6 (9#7)
I I I I$% I$% I$% I$% I$% I$% I$% I$%
LCD Background The LCD module requires . control lines and either 0 or 8 I$% lines for the data bus! The user may select whether the LCD is to operate with a 0 bit data bus or an 8 bit data bus! If a 0 bit data bus is used: the LCD will require a total of 6 data lines (. control lines plus the 0 lines for the data bus)! If an 8 bit data bus is used: the LCD will require a total of '' data lines (. control lines plus the 8 lines for the data bus)! The three control lines are referred to as 5: 1#: and 1$3! The 5 line is called ;5nable!; This control line is used to tell the LCD that you are sending it data! To send data to the LCD: your program should first set this line high (') and then set the other two control lines (1# < 13) and put data on the data bus (D70 D78)! 3hen the other lines are completely ready: bring 5 low (0) again! The ' 0 transition tells the LCD to ta=e the data currently found on the other control lines and on the data bus and to treat it as a command! The 1# line is the ;1egister #elect; line! 3hen 1# is low (0): the data is to be treated as a command or special instruction (such as clear screen: position cursor: etc!)! 3hen 1# is high ('): the data being sent is te>t data which should be displayed on the LCD screen! &or e>ample: to display the letter ;T; on the screen you would set 1# high! The 13 line is the ;1ead$3rite; control line! 3hen 13 is low (0): the information on the data bus is being written to the LCD! 3hen 13 is high ('): the program is effecti?ely querying (or reading) the LCD! &inally: the data bus consists of 0 or 8 lines (depending on the mode of operation selected by the user)! In the case of an 8 bit data bus: the lines are referred to as D70: D7': D7+: D7.: D70: D7-: D74: and D76!
Microprocessor Laboratory
Page
EKT222 Microprocessor System Northern Malaysia University College of Engineering
Initializing the LCD 7efore the LCD can be used: the LCD module controller would need to be initiali@ed by a few instructions! This is accomplished by sending a number of initiali@ation instructions to the LCD! The following e>ample shows a suggested sequence of instructions to initiali@e the LCD with 8 bit operation: + lines: ->6 font and automatically incremented display! 1#20: 1320: .8A: .8A: .8A: 0CA: 04A
The initiali@ation procedure is shown below! '! #end Init Command .8A . times (8 bit data: + lines and ->6 fonts) 1# 1$3 D76 D74 D7D70 D7. D7+ 0 0 0 0 ' DL2' *2' &20 DL 2 Data Length 0 0 bit operation ' 8 bit operation * 2 *umber of BlinesC 0 for '$8 duty cycle ' line ' for '$'4 duty cycle D + line & 2 &ont: ' not used 0 for ->6 dot matri> E3ait 00us or till 7&20F +! #end Init Command 0CA (Display on: Cursor off: blin= off) 1# 0 1$3 0 D76 0 D74 0 D70 D70 0 D7. ' D7+ D2' D7' C20 D70 0 D7' 0 D70 0
D 2 Display %*$%&& 0 display %&& ' display %* C 2 Cursor %*$%&& 0 cursor %&& ' cursor %* E3ait 00us or till 7&20F .! #end Init Command 04A (Increment cursor to the right when writing: donCt shift screen) 1# 1$3 D76 D74 D7D70 D7. D7+ D7' D70 0 0 0 0 0 0 0 ' I$D2' #20 I$D 2 #et cursor direction 0 decrement ' increment #2 Display shift 0 disable ' enable E3ait 00us or till 7&20F
Microprocessor Laboratory
Page
EKT222 Microprocessor System Northern Malaysia University College of Engineering
Cursor Positioning The LCD module contains a certain amount of memory which is assigned to the display! Gll the te>t we write to the LCD module is stored in this memory: and the LCD module subsequently reads this memory to display the te>t on the LCD itself! This memory can be represented with the following diagram!
00 0' 0+ 0. 00 004 06 08 08 0G 07 0C 0D 05 0&
Line ' Line +
00 0' 0+ 0. 00 004 06 08 08 0G 07 0C 0D 05 0&
Gs you can see: it measures '4 characters per line by + lines! The numbers on top and bottom of each bo> is the memory address that corresponds to that screen position! Thus: the first character in the upper left hand corner is at address 00h! The following character position (character H+ on the first line) is address 0'h: etc! This continues until we reach the '4th character of the first line which is at address 0&h! Aowe?er: the first character of line + is at address 00h! Thus we need to send a command to the LCD that tells it to position the cursor on the second line! The ;#et Cursor "osition; instruction is 80h and we must add it with the address of the location where we wish to position the cursor! &or e>ample to start display character at line + address 0'h: we must send a ;#et Cursor "osition; instruction the ?alue of this command will be 80h (the instruction code to position the cursor) plus the address 0'h I 80h , 0'h 2 C'h! Thus sending the command C'h to the LCD will position the cursor on the second line at the second character position! E ercise 3rite a following sample program to display a message string te>t on the LCD module! I I C%**5CTI%* I Gll routines are written for controlling the module in a 8 bit mode! I D70 DD76 connect to "ort G I 1# "C0 I 1$3 "C' I 5 "C+ I cpu ;808-!tbl; org !+000h l>i sp:.ff0h IJ Initiali@ation routine for the 8+-I m?i a:80h Iall ports as o$p out 8.h IJ Initiali@ation routine for the LCD module I m?i a:.8h Irefer to LCD data sheet for call wrKcmd Iinitiali@ation sequences m?i a:.8h I8 bits: + rows: - > 6 dots call wrKcmd m?i a:.8h call wrKcmd m?i a:0ch call wrKcmd m?i a:04h call wrKcmd m?i a:80h I#et address to 80h (home position) call wrKcmd Iof the first line l>i h:msgKline' Istart write char to the first line line'L mo? a:m Iof the LCD cpi 0 /@ ne>tKline call wrKchar
Microprocessor Laboratory
Page
EKT222 Microprocessor System Northern Malaysia University College of Engineering
ne>tKlineL line+L
e>itL
in> h /mp line' m?i a:0c0h call wrKcmd l>i h:msgKline+ mo? a:m cpi 0 /@ e>it call wrKchar in> h /mp line+ 1#T '
Iset address to C0h (home position) Iof the second line Istart write char to the second line Iof the LCD
Ientry point to monitor program
IJ wrKcmd writes an instruction code to the LCD IJ The accumulator contains the instruction code! I wrKcmdL out 80h Isend instruction code data through port G m?i a:00000'00b I1#20:1$320:52' out 8+h m?i a:00000000b I1#20:1$320:520 out 8+h call delay+ Iinternal e>ecuting time for LCD ret IJ wrKchar writes a single character to the LCD! IJ The accumulator contains the character! I wrKcharL out 80h Isend character through port G m?i a:00000'0'b I1#2':1$320:52' out 8+h m?i a:0000000'b I1#2':1$320:520 out 8+h call delay' Iinternal e>ecuting time for LCD ret delay'L loopK'L m?i c:00 dcr c /n@ loopK' ret m?i c:+-dcr c /n@ loopK+ ret dfb dfb end ;808- De?elopment;:0 ;#ystem D MNMN9 ;:0
delay+L loopK+L
msgKline'L msgKline+L
Part B Design Problem
3rite a program to display the following te>t and count ?alue 0 8 on LCD module! C 9 % I N C * 1 T % 5 1 " 2 L G 0 7
Microprocessor Laboratory
Page