LCD Configuration and Programming Liquid Crystal Display LCD

  • Slides: 27
Download presentation
LCD Configuration and Programming

LCD Configuration and Programming

Liquid Crystal Display (LCD) Two types of LCD Alphanumeric Graphic Selection depends on What

Liquid Crystal Display (LCD) Two types of LCD Alphanumeric Graphic Selection depends on What size and format is required to display the desired information What optical characteristics will look best in the package and attract the user to the product

Picture

Picture

Alphanumeric Liquid Crystal Display (LCD) Used to display numerical information, text massage and special

Alphanumeric Liquid Crystal Display (LCD) Used to display numerical information, text massage and special symbol Many variety 16 x 2 (16 characters per lines, 2 lines) 16 x 4 (16 characters per lines, 4 lines) Two types of displays 5 x 8 dot character fonts with cursor 5 x 10 dot character fonts with cursor Can be controlled in two ways, depending on availability of IO pins 8 pins (8 -bit interface) 4 pins (4 -bit interface)

LCD

LCD

LCD PINS Pin Name Function 1 VSS Ground 2 VDD Supply (+5 V) 3

LCD PINS Pin Name Function 1 VSS Ground 2 VDD Supply (+5 V) 3 VEE Contrast adjustment RS Register Select Signal 0: Instruction Register (write), Address Counter (read) 1: Data Register 5 R/W’ Read/Write Signal 0: Write 1: Read 6 E Enable Signal (H L) : Start data read/write 7 DB 0 8 DB 1 9 DB 2 10 DB 3 11 DB 4 12 DB 5 13 DB 6 14 DB 7 15 LED+ Anode for LED backlighting 16 LED- Cathode for LED backlighting 4 • Four low order bidirectional tristate data bus pins. • Used for data transfer and receive between controller and LCD driver. • These pins are not used during 4 -bits operation • Four high order bidirectional tristate data bus pins. • Used for data transfer and receive between controller and LCD driver. • DB 7 can be used as a busy flag

LCD Controller Function Description Instruction Register (IR) Store instruction codes and address information for

LCD Controller Function Description Instruction Register (IR) Store instruction codes and address information for display data RAM (DDRAM) and character generator RAM (CGRAM) Can only be written Data Register (DR) Temporarily stores data to be written into or to be read from DDRAM or CGRAM Busy Flag (BF) 1: indicates the controller is in internal operation mode, no further instruction can be written BF is output to DB 7 when RS = 0 and R/W’ = 1

LCD Controller Function Description Address Counter (AC) Assigns addresses to both DDRAM and CGRAM.

LCD Controller Function Description Address Counter (AC) Assigns addresses to both DDRAM and CGRAM. The selection of either DDRAM or CGRAM is determined concurrently by the instruction AC automatically incremented by 1 after writing data into DDRAM or CGRAM AC automatically decremented by 1 after reading data from DDRAM or CGRAM AC contents are output to DB 0 to DB 6 when RS = 0 and R/W’ = 1

LCD Controller Function Description Register Selection Table RS R/W’ Operation 0 0 Write to

LCD Controller Function Description Register Selection Table RS R/W’ Operation 0 0 Write to IR (write instruction) 0 1 Read busy flag (DB 7) and address counter (DB 0 – DB 6) 1 0 Write to DR (DDRAM or CGRAM) 1 1 Read from DR (DDRAM or CGRAM)

LCD Controller Function Description Display Data RAM (DDRAM) Store display data represented in 8

LCD Controller Function Description Display Data RAM (DDRAM) Store display data represented in 8 -bit character codes DDRAM address (ADD)is set in the AC as hexadecimal

LCD Controller Function Description Character Generator ROM (CGROM) Generates 5 x 8 or 5

LCD Controller Function Description Character Generator ROM (CGROM) Generates 5 x 8 or 5 x 10 dots character patterns from 8 -bit character codes. Can generate 208 5 x 8 dots character patterns and 32 5 x 10 dots character pattern Character Generator RAM (CGRAM) Used to rewrite (regenerate) character pattern by program 5 x 8 dots: max 8 character patterns can be written 5 x 10 dots: max 4 character patterns can be written

Character Code and Character Pattern

Character Code and Character Pattern

Character Code and Character Pattern

Character Code and Character Pattern

LCD Commands and Instruction Set MCU can only control IR and DR The internal

LCD Commands and Instruction Set MCU can only control IR and DR The internal operation of the LCD is determined by signals send from the MCU These signals, RS, R/W’ and data bus, make up the LCD instructions as shown in Table 3. There are four categories of instructions: Designate LCD functions such as display format, clear display, etc Set internal RAM addresses Perform data transfer with internal RAM Perform miscellaneous functions

LCD Commands and Instruction Set

LCD Commands and Instruction Set

LCD Commands and Instruction Set *DDRAM address is given in Slide 10 **CGRAM address

LCD Commands and Instruction Set *DDRAM address is given in Slide 10 **CGRAM address from 0 x 00 to 0 x 3 F, 0 x 00 to 0 x 07 for char 1 and so on

LCD Connection in PTK 40 A (8 -bit modes)

LCD Connection in PTK 40 A (8 -bit modes)

LCD Initialization Before using the LCD for display purpose, LCD has to be initialized

LCD Initialization Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands. Initialize by internal reset circuit Automatically initializes when the power is turn on. The BF is kept in busy state until the initialize ends The following instructions are executed during the initialization Display Clear Function Set: DL = 1 ; 8 -bit interface data N = 0; 1 -line display F = 0; 5 x 8 dot character font Display on/off control: D = 0; Display off C = 0; Cursor off B = 0; Blinking off Entry mode set: I/D = 1; increment by 1 S = 0; No shift

LCD Initialization Conditions below have to be met if want to used initialization by

LCD Initialization Conditions below have to be met if want to used initialization by internal reset Problem: highly dependent on power supply

LCD Initialization by instructions can be summarized as follow After power on, delay at

LCD Initialization by instructions can be summarized as follow After power on, delay at least 15 ms for properation Send Function Set command Send Display Control command Send set entry mode command

LCD Initialization Void LCD_init() { __delay_ms(15); LCD_data LCD_rs LCD_rw LCD_en __delay_ms(1); LCD_en __delay_ms(2); =

LCD Initialization Void LCD_init() { __delay_ms(15); LCD_data LCD_rs LCD_rw LCD_en __delay_ms(1); LCD_en __delay_ms(2); = 0 x 38; = 0; = 1; //Delay for stability //Function set: 2 line, 8 -bit, 5 x 7 dots //Selected command register //Writing in data register //Enable H L //wait for a while = 0; = 0 x 0 F; = 0; = 1; //wait for LCD to process the command //Display on, Cursor blinking command //Selected command register //Writing in data register //Enable H L //wait for a while = 0; //wait for LCD to process the command

LCD Initialization LCD_data LCD_rs LCD_rw LCD_en __delay_ms(1); LCD_en __delay_ms(2); } = 0 x 01;

LCD Initialization LCD_data LCD_rs LCD_rw LCD_en __delay_ms(1); LCD_en __delay_ms(2); } = 0 x 01; = 0; = 1; //Clear LCD //Selected command register //Writing in data register //Enable H L //wait for a while = 0; //wait for LCD to process the command = 0 x 06; //Entry Mode, auto increment with no shift = 0; //Selected command register = 0; //Writing in data register = 1; //Enable H L //wait for a while = 0; //wait for LCD to process the command

Sending Command Data to LCD Sending command Move data to LCD port Select command

Sending Command Data to LCD Sending command Move data to LCD port Select command register Select write operation Send enable signal Wait for LCD to process the command Void LCD_sendcommand(unsigned char cmd) { LCD_data = cmd; LCD_rs = 0; //Selected command register LCD_rw = 0; //Writing in data register LCD_en = 1; //Enable H L __delay_ms(1); //wait for a while LCD_en = 0; __delay_ms(2); //wait for LCD to process the command }

Sending Command Data to LCD Setting cursor position To set cursor position, send the

Sending Command Data to LCD Setting cursor position To set cursor position, send the DDRAM address Bit 7 always set to 1 and bit 0 to 7 are DDRAM address To put cursor on the first position in first line, the address will be ‘ 0 b 0000’ in binary and set the bit 7 to 1, so the address will be ‘ 0 x 80’ or ‘ 0 b 10000000’ To put cursor on the first position in second line, the address will be ‘ 0 b 01000000’ in binary and set the bit 7 to 1, so the address will be ‘ 0 x. C 0’ or ‘ 0 b 11000000’ Void LCD_gotoxy(unsigned char x, unsigned char y) { unsigned char pos; if(y==1) { pos=x|0 x 80; // or with 0 x 80 to set bit 7 = 1 }else { pos=x|0 x 80|0 x 40; // or with 0 x 80 to set bit 7 = 1 and //or with 0 x 40 because second line address start from 0 x 40 } LCD_sendcommand(pos); //call send command function }

Sending Command Data to LCD Sending data Move data to LCD port Select data

Sending Command Data to LCD Sending data Move data to LCD port Select data register Select write operation Send enable signal Wait for LCD to process the command Void LCD_senddata(unsigned char data) { LCD_data = cmd; LCD_rs = 1; //Selected data register LCD_rw = 0; //Writing in data register LCD_en = 1; //Enable H L __delay_ms(1); //wait for a while LCD_en = 0; __delay_ms(2); //wait for LCD to process the command }

Sending Command Data to LCD Sending string data String is a set of data

Sending Command Data to LCD Sending string data String is a set of data Sending string of data is actually sending multiple data one by one Void LCD_sendstringdata(unsigned char* data) { while(*data!=‘’) //till string ends { LCD_senddata(*data); //send characters one by one data++; } }

Q&A

Q&A