2. Learning Outcomes
1. Explain the basic concept of Liquid Crystal Display (LCD)
2. Interface the LCD with a microcontroller
3. Explain the basic concept of Keypad
4. Interface the keypad with a microcontroller
4. What are Alphanumeric LCDs?
• Alphanumeric LCD can display alphabet and numbers
• Graphic LCD can display shapes (e.g. Laptop screen)
Alphabets
(A,B, h,e,k,!)
Numerics
(0,1,2,3,…,9)
5. Types of LCDs
• Alphanumeric LCDs have Columns and Rows
• i.e 16 x 2 LCD has 16 characters (column) maximum in one line, total 2 lines (rows)
• LCD used in
With backlight
Without backlight
Color
16
2
6. Capability of LCDs
• Alphanumeric LCD can display a large
number of characters and symbols
• Based on the maximum Columns x Rows,
these characters can be displayed
simultaneously
• I.e. 16 x 2 LCD total of 32 characters
can be displayed at one time
7. LCD pins
• Most LCDs use Hitachi 44780 based
character LCD
• Has 14 pins; 3 control, 3 for supply, ground,
contrast and 8 for 8 bit data
• RS = set register (instruction or data)
• RW = read/write mode; 0 -> Write to LCD
• E = enable signal
• Some LCD has 16 pins, and two Hitachi
44780 controllers, extra 2 pins for backlight
(Vcc, Gnd)
8. LCD connections (4bit)
• LCD library
• 3 pins [Vdd (supply), Vss (ground),
Vee (contrast)]
• 3 pins (RS – register Select, RW –
read/write, EN – enable )
• 4 pins for data bus
9. Program (4bit)
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;;
Declare LCD Connections
char txt1[] = "Microcontroller";
char txt2[] = "Technology";
char txt3[] = "3BEKM";
char txt4[] = "2022/2023";;
Declare Texts to display
10. Program (4bit)
void main(){
TRISB = 0;
PORTB = 0;
Lcd_Init();
Initialize Ports and LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt3);
Clear LCD, write txt3 contents
while(1)
{
Lcd_Out(2,6,txt4);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt1);
Lcd_Out(2,5,txt2);
Delay_ms(1000);
}
}
Loop: Display different text
13. Displaying numbers
value = 9999;
• Assign the number to be displayed
WordToStr ( value, txt1);
• Converts the value into string (text)
LCD_Out ( 1, 1, txt1)
• Displays the text at row 1, column 1
14. Keypad
Keypad is an array of switches where 2 wires are
connected each time a button is pressed
The keypad pins need to be pulled up or pulled
down to avoid floating cases
The connections depend on the keypad matrix
Rows and Columns.
(4 x 4 8, 4 x 3 7) 8 connections
Column
pins
Row
pins
16. Keypad connections
7 pins for 4 x 3 keypad, 8 pins for 4 x
4 keypad
Needs pull down resistors for pins
Using voltage divider on the keypad
to PIC input
Column connected to PIC as input
and Row connected as output
18. Program (Keypad, LCD)
unsigned short kp, cnt, oldstate = 0;
char txt[6];
char keypadPort at PORTD;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
Declare LCD Connections
Declare PORT for keypad