LCD
Advantages of LCD LCD is finding widespread use replacing LEDs The declining prices of LCD The ability to display numbers, characters, and graphics Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD Ease of programming for characters and graphics
LCD 2 X16- Pin diagram 1 2 3 4 5 6 7 8 9 10 1112131415 }}}}}}}}}}}}}}} Pin No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Symbol GND VCC CONT RS R/ EN D0 D1 D2 D3 D4 D5 D6 D7 BL W
LCD 2 X16 (Features) 5 x 7 dots plus cursor, 5 x 10 dots per character 4 or 8 bit interface with MPU is possible Display Data RAM (DR) : 80 x 8 bit, Max 80 characters Character Generator (CG) ROM : 160, 5 x 7 Character fonts 32, 5 x 10 Character fonts Custom ROM codes available Character Generator RAM : Program write (64 x 8 bits) 8, 5 x 7 Character fonts 4, 5 x 10 Character fonts Both Display Data RAM & CG RAM can be read by MPU Wide variety of operating instructions : Display Clear, Cursor Home,Display ON / OFF, Display Cursor Blink, Cursor shift, display shift etc.
LCD 2 X16 (Pin Description) Signal In/Out Function D7 - D0 I/O 8 bit data bus used for bi-directional data D7 - D4 I/O transfer between µC & LCD module D7 O These lines are used as data bus in 4 bit RS I operation. Can be used as Busy Flag R/W I EN I Register Select 0 = Instruction Register (IR) 1 = Data Register (DR) Signal to select Read or Write 0 = Write, 1 = Read Enable signal is used to latch the information presented to its data pins.
LCD 2 X16 (Registers) Controller for LCD has two 8 bit registers, the instruction register (IR) and data register (DR) IR is write only register used to store only instruction codes like display Clear, cursor shift or address of DD RAM etc. DR is read / write register used to store temporary data into DD RAM or CG RAM by an internal operation of the display controller. RS R / W Operation 0 0 IR write, internal operation (Display clear, cursor position, function set etc.) 0 1 Busy Flag (D7) & address counter (D6-D0) read 1 0 DR write, internal operation (DD RAM or CG RAM) 1 1 DR read, internal operation (DD RAM or CG RAM)
Interfacing LCD (8 bit data length) P2.7 + 5V 15(BL) IR P2.6 P2.5 1K 14(D7) P2.4 13(D6) P2.3 + 5V 12(D5) P2.2 11(D4) P2.1 10(D3) P2.0 9(D2) 8(D1) P0.5 7(D0) P0.6 P0.7 6(EN) DR 8051 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) LCD
Interfacing LCD (4 bit data length ) P0.3 + 5V 15(BL) IR P0.2 P0.1 1K 14(D7) P0.0 13(D6) + 5V 12(D5) P1.3 11(D4) P0.5 10(D3) P0.4 9(D2) 8(D1) 8051 7(D0) 6(EN) DR 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) LCD
Write Operation (IR) To write data into IR 1. Select instruction Reg. (RS = 0) #data 15(BL) 2. Select write (R/W = 0) 14(D7) 3. Transfer instruction code to 13(D6) 12(D5) Port ( Via Data bus) 11(D4) 4. Enable signal to start write 10(D3) 9(D2) operation (EN = 1) 8(D1) 7(D0) IR program 0 6(EN) DR 0 CLR RS 5(R/W) CLR RW 4(RS) MOV Port, # data SETB EN 3(CONT) ACALL delay_1ms 2(VCC) CLR EN ACALL delay_5ms 1(GND) LCD
Write Operation (DR) To write data into DR #data 15(BL) 1. Select Data Reg. (RS = 1) 14(D7) IR 2. Select write (R/W = 0) 13(D6) 3. Transfer ASCII code of display 12(D5) 11(D4) character to Port 10(D3) 4. Enable signal to start write 9(D2) 8(D1) operation (EN = 1) 7(D0) program 0 6(EN) DR 1 SETB RS 5(R/W) CLR RW 4(RS) MOV Port, # data SETB EN 3(CONT) ACALL delay_1ms 2(VCC) CLR EN ACALL delay_5ms 1(GND) LCD
LCD instructions (8 bit instr. code) 1. Function Set: DL = Data Length (If DL=1, 8 bit & If DL=0, 4 bit) N = No. of display lines (If N=0, 1 Line & If N=1, 2 Line) F = Character Font (If F=0, 5x7 dot character font & F=1, 5x10 2. Display ON/OFF Control: D = 0 ; Display OFF & D = 1 ; Display ON C = 0 ; Cursor OFF & C = 1 ; Cursor ON B = 0 ; Blink OFF & B = 1 ; Blink ON 3. Clear Display 4. Entry Mode Set: I/D = 1 ; Increment Mode ( Increment DD RAM address by 1) S = 0 ; No display shift operation 5. Set DD RAM address: Sets the address counter to the DD RAM address AAAAAAA. Data is then written / read to from the DD RAM. For 2 line display module AAAAAAA = 00H to 27H for the first line & 40H to 67H for the second line.
LCD instructions… 1. Function Set D7 D6 D5 D4 D3 D2 D1 D0 0 0 1 DL N F X X DL: Sets interface data length If DL = 1, data is sent or received in 8 bit length (D7 - D0). if DL = 0, data is sent or received in 4 bit length (D7 - D4). When 4 bit length is selected data must be sent or received twice. N: Sets the number of lines e.g. For 8 bit data length, 2 line If N = 0 ; 1 line display display, 5 x 7 dots. If N = 1 ; 2 line display Function Set = 0011 1000 = 38H F: Sets character font If F = 1 ; 5 x 10 dots If F = 0 ; 5 x 7 dots
LCD instructions… 2. Display ON/OFF Control D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 1DCB D : If D = 1, display is ON. If D = 0, display is OFF C : If C = 1, cursor is displayed. If C = 0, cursor is not displayed. B : If B = 1, Cursor blink is ON, If B = 0, Cursor blink is OFF. e.g. For Display ON, Cursor display & blinking off. Display ON = 0000 1110 = 0EH 3. Clear Display D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 1 = 01H Writes the space code “20H” into all addresses of DD RAM.
LCD instructions… 4. Entry Mode Set D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 1 I/D S Sets the increment / decrement and shift modes to the desired settings. I/D : Increments (I/D = 1) or decrements (I/D = 0) the DD RAM address by 1 when a character code is written or read from the DD RAM. The cursor moves to the right when incremented by +1 S : Shift the entire display either to the right or to the left when S = 1. If I/D = 1, shift to the left. If I/D = 0, shift to the left. e.g. DD RAM address should be incremented, No display shift. Entry Mode Set = 0000 0110 = 06H
LCD instructions… 5. Set DD RAM Address D7 D6 D5 D4 D3 D2 D1 D0 1AAAAAAA Sets the address counter to the DD RAM address AAAAAAA. Data is then written / read to from the DD RAM. For 2 line display module AAAAAAA = 00H to 27H for the first line & 40H to 67H for the second line. e.g. To display characters in the first line Set DD RAM address = 1000 0000 = 80H e.g. To display characters in the second line Set DD RAM address = 1100 0000 = C0H
Summary of LCD instructions Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0 Function Set 0 0 0 0 1 DL N F X X 00 00 0 0 1DCB Display ON/OFF 00 00 0 0 0 0 0 1 0 0 0 0 0 0 0 1 I/D S Clear Display 00 1 AAAAAAA Entry Mode Set 10 Write data Set DD RAM address 11 Read data Write data to DD RAM Read data from DD RAM
Initialization of LCD (8 bit)
Initialization of LCD (4 bit)
LCD Program #1 Q.1. Interface 2X16 LCD with 8051.Use 8 bit data length and write program to display “NO” in first line P1.7 + 5V 15(BL) IR P1.6 P1.5 1K 14(D7) P1.4 13(D6) P1.3 + 5V 12(D5) P1.2 11(D4) P1.1 10(D3) P1.0 9(D 2) 8(D 1) P2.2 7(D 0) P2.1 P2.0 6(EN) DR 5(R/W) 8051 4(R S) 3(CONT) LCD 2(VCC) 1(GND)
Method 1(without busy flag) In which,calls a time delay before sending next data/command ;P1.0-P1.7 are connected to LCD data pins D0-D7 ;P2.0 is connected to RS pin of LCD ;P2.1 is connected to R/W pin of LCD ;P2.2 is connected to EN pin of LCD ORG 0000H ; INIT. LCD 2 LINES, 5X7 MATRIX MOV A,#38H ; call command subroutine ACALL COMNWRT ; give LCD some time ACALL DELAY ; display on, cursor on MOV A,#0EH ; call command subroutine ACALL COMNWRT ; give LCD some time ACALL DELAY ; clear LCD MOV A,#01 ; call command subroutine ACALL COMNWRT ; give LCD some time ACALL DELAY ; shift cursor right MOV A,#06H ; call command subroutine ACALL COMNWRT ; give LCD some time ACALL DELAY ; cursor at line 1, pos. 4 MOV A,#84H ; call command subroutine ACALL COMNWRT ; give LCD some time ACALL DELAY
MOV A,#’N’ ;display letter N ACALL DATAWRT ;call display subroutine ACALL DELAY ;give LCD some time MOV A,#’O’ ;display letter O ACALL DATAWRT ;call display subroutine AGAIN: SJMP AGAIN ;stay here COMNWRT: ;send command to LCD MOV P1,A ;copy reg A to port 1 CLR P2.0 ;RS=0 for command CLR P2.1 ;R/W=0 for write SETB P2.2 ;E=1 for high pulse CLR P2.2 ;E=0 for H-to-L pulse RET
DATAWRT : ;write data to LCD MOV P1,A ;copy reg A to port 1 CLR P2.0 ;RS=0 for command CLR P2.1 ;R/W=0 for write SETB P2.2 ;E=1 for high pulse CLR P2.2 ;E=0 for H-to-L pulse RET ;50 or higher for fast CPUs DELAY : ;R4 = 255 MOV R3,#50 ;stay until R4 becomes 0 HERE2: MOV R4,#255 HERE: DJNZ R4,HERE DJNZ R3,HERE2 RET END
Method 2 ( with Busy flag ) in which no delay are used • Busy flag is D7 bit of the command/instruction register. • To read the instruction register we make RS=0,R/W=1 and positive edge i.e. (L-to-H pulse) for the EN pin. • After reading the instruction register, if bit D7 ( the busy flag) is high, that means the LCD is busy and no information should be transfer to it. • When D7=0 we can send the data or command to the LCD • In this method no time delays are used since we are checking the busy flag before transferring commands or data to the LCD. • Note that the EN pin is negative edge triggered i.e.( H-to-L pulse ) for the writing operation while it is positive edge triggered i.e. (L-to-H pulse ) for the reading operation.
PROGRAM BY USING BUSY PIN ;Check busy flag before sending data, command to LCD ;p1=data pin ;P2.0 connected to RS pin ;P2.1 connected to R/W pin ;P2.2 connected to E pin ORG 0000H MOV A,#38H ;init. LCD 2 lines ,5x7 matrix ACALL COMMAND ;issue command MOV A,#0EH ;LCD on, cursor on ACALL COMMAND ;issue command MOV A,#01H ;clear LCD command ACALL COMMAND ;issue command MOV A,#06H ;shift cursor right ACALL COMMAND ;issue command MOV A,#86H ;cursor: line 1, pos. 6 ACALL COMMAND ;command subroutine MOV A,#’N’ ;display letter N ACALL DATA_DISPLAY MOV A,#’O’ ;display letter O ACALL DATA_DISPLAY HERE:SJMP HERE ;STAY HERE
COMMAND: ;is LCD ready? ACALL READY ;issue command code MOV P1,A ;RS=0 for command CLR P2.0 ;R/W=0 to write to LCD CLR P2.1 ;E=1 for H-to-L pulse SETB P2.2 ;E=0,latch in CLR P2.2 RET ;is LCD ready? ;issue data DATA_DISPLAY: ;RS=1 for data ACALL READY ;R/W =0 to write to LCD MOV P1,A ;E=1 for H-to-L pulse SETB P2.0 ;E=0,latch in CLR P2.1 SETB P2.2 CLR P2.2 RET
READY: SETB P1.7 ;make P1.7 input port CLR P2.0 ;RS=0 access command reg SETB P2.1 ;R/W=1 read command reg ;read command register and check busy flag BACK: SETB P2.2 ;E=1 for H-to-L pulse CLR P2.2 ;E=0 H-to-L pulse JB P1.7, BACK ;stay until busy flag=0 RET END
Search
Read the Text Version
- 1 - 26
Pages: