In this article, we will discuss the main program between relation of LCD and keyboard. For basic 16x2 character LCD article, visit this link and for basic 4x4 matrix keyboard visit this link.
This program is divided into 4 parts
In software delay program we are just defining software delay which will be used in all other 3 programs. LCD program deals with the required functions related to initialization of LCD, LCD commands and writing functions to LCD. Keyboard program deals with the checking of which key is pressed and main program has the code for task which should be carried.
in main code, we first check which key is pressed and for each key we can assign a specific task through switch case. Here we are printing the spelling of each pressed key on LCD. Each .c program has its own .h header for required definitions.
Follow the following code for main program.
//header files
#include<reg51.h>
#include"lcd.h"
#include"kbd.h"
#include"delay.h"
void process();
int main(void)
{
init_LCD();
while(1)
{
process();
}
}
void process()
{
unsigned char key;
//check if any key is pressed
key=getkey();
//check entered number
switch(key)
{
case 1:
//clear screen
wrcmd(0x01,0);
//move cursor to line 1's start
wrcmd(0x80,0);
//display entered number
write_to_LCD("one");
//minimum delay between 2 entries
delay(200);
break;
case 2:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("two");
delay(200);
break;
case 3:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("three");
delay(200);
break;
case 4:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("four");
delay(200);
break;
case 5:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("five");
delay(200);
break;
case 6:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("six");
delay(200);
break;
case 7:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("seven");
delay(200);
break;
case 8:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("eight");
delay(200);
break;
case 9:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("nine");
delay(200);
break;
case 10:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("ten");
delay(200);
break;
case 11:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("eleven");
delay(200);
break;
case 12:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("twelve");
delay(200);
break;
case 13:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("thirteen");
delay(200);
break;
case 14:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("fourteen");
delay(200);
break;
case 15:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("fifteen");
delay(200);
break;
case 16:
wrcmd(0x01,0);
wrcmd(0x80,0);
write_to_LCD("sixteen");
delay(200);
break;
default:
break;
}
}
8051 with LCD and Keybord |
Output video:
You can create other files using the articles 16x2 character LCD and 4x4 matrix keyboard or download them directly from here along with proteus file.
No comments:
Post a Comment