Lab 4 Keypad LCD Interfacing
Lab 4 Keypad LCD Interfacing
L10.1 EXPERIMENT V: KEYPAD LCD INTERFACING In this experiment you will interface a keypad to a PIC microcontroller. This experiment is an extension of the previous week LCD interfacing application. You have to preserve the LCD interfacing circuit and only connect the keypad to PORTB. Note that you need to attach pull-down resistor of 10K to each keypad pins. NOTE: STUDY LCD AND KEYPAD LIBRARY HELP FILES
L4-1
Lab Notes 4
PIC16F877: KEYPAD LCD
L4-2
Mechatronics Lecture Notes PIC16F877: KEYPAD LCD by Dr. Can U. Dogruer L10.2KEYPAD LCD INTERFACING: Reading Keypad 1. 2. 3. 4. Construct the circuit shown in Figure 1. Note that pins of keypad is attached to pull-down resistors of 10K In this experiment keypad is interfaced to PORTB so Write a C code that display text on LCD display
Lab Notes 4
// Keypad module connections char keypadPort at PORTB; // End Keypad module connections // LCD module connections sbit LCD_RS at RC4_bit; sbit LCD_EN at RC5_bit; sbit LCD_D4 at RC0_bit; sbit LCD_D5 at RC1_bit; sbit LCD_D6 at RC2_bit; sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit; sbit LCD_EN_Direction at TRISC5_bit; sbit LCD_D4_Direction at TRISC0_bit; sbit LCD_D5_Direction at TRISC1_bit; sbit LCD_D6_Direction at TRISC2_bit; sbit LCD_D7_Direction at TRISC3_bit; // End LCD module connections
L4-3
Lab Notes 4
PIC16F877: KEYPAD LCD
Keypad_Init(); // Initialize Keypad
Lcd_Init(); Lcd_Cmd(_LCD_CLEAR);
// Wait for key to be pressed and released do // kp = Keypad_Key_Press(); kp = Keypad_Key_Click(); while (!kp); // Prepare value for output, transform key to it's ASCII value switch (kp) { //case 10: kp = 42; break; // '*' // Uncomment this block for keypad4x3 //case 11: kp = 48; break; // '0' //case 12: kp = 35; break; // '#' //default: kp += 48; // Store key code in kp variable // Store key code in kp variable
case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 case 4: kp = 65; break; // A case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 case 8: kp = 66; break; // B
L4-4
Lab Notes 4
PIC16F877: KEYPAD LCD
case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 12: kp = 67; break; // C case 13: kp = 42; break; // * case 14: kp = 48; break; // 0 case 15: kp = 35; break; // # case 16: kp = 68; break; // D }
if (kp != oldstate) { cnt = 1; oldstate = kp; } else { cnt++; } Lcd_Chr(1, 10, kp);
if (cnt == 255) { cnt = 0; Lcd_Out(2, 10, " "); } WordToStr(cnt, txt); Lcd_Out(2, 10, txt); } while (1); }
void interrupt() { }
L4-5