Interfacing 4×4 keypad with LCD using 8051 microcontroller - solucktech

Latest

solucktech

contact us :(+234)07019218599

Wednesday, July 22, 2020

Interfacing 4×4 keypad with LCD using 8051 microcontroller

Interfacing 4×4 keypad with LCD using 8051 microcontroller is very important step to enter big project. So here I have discussed regarding Interfacing4x4 keypad with LCD using 8051 microcontroller. In my previous post, I was discussed on Interfacing LCD with 8051 microcontroller using Mikro c for 8051. Now we can see how easily we interface keypad and send the data to LCD for display using MikroC for 8051.

Project Detail:

In this project we use AT 89c51 microcontroller and interface 4×4 keypad at port 0 and LCD at port 2.




From this Proteous simulation circuit diagram we can see that four resistors R1,R2,R3,R4 are connected in P0.0,P0.1,P0.2,P0.3. These resistors are work as a pull-up resistor. Because we know for input/output operation of port0 of 8051 microcontroller need pull-up resistor. For more details regarding ports in 8051 read my previous post “Ports in 8051 microcontroller”.

Here you see the complete embedded C code written in Mikroc for 8051 about this project “Interfacing 4×4 keypad with LCD using 8051 microcontroller”



Embedded C Code

______________________________________
// Name : Interfacing 4×4 keypad with LCD using 8051 microcontroller

unsigned short kp;// Keypad module connections
char keypadPort at P0; 
// End Keypad module connections// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connections
void main() {
cnt = 0; // Reset counter
Keypad_Init(); // Initialize Keypad
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1, 1, “Key :”); // Write message text on Lcd
Lcd_Out(2, 1, “Times:”);

do {
kp = 0; // Reset key code variable

// Wait for key to be pressed and released
do
// kp = Keypad_Key_Press(); // Store key code in kp variable
kp = Keypad_Key_Click(); // Store key code in kp variable
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;

case 1: kp = 55; break; // 1 // Uncomment this block for keypad4x4
case 2: kp = 56; break; // 2
case 3: kp = 57; 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
case 9: kp = 49; break; // 7
case 10: kp = 50; break; // 8
case 11: kp = 51; 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

}

Lcd_chr(2, 10, kp); // Display counter value on Lcd
} while (1);
}

_________________________________________

No comments:

Post a Comment