急求一个基于89C51单片机,8255A,用矩阵键盘输入数字,并在LCD1602上显示出来的C语言程序

2020-10-02 社会 223阅读

#include
#include
#define PA                                      XBYTE[0xF8FF]
#define PB                                      XBYTE[0xF9FF]
#define PC                                      XBYTE[0xFAFF]
#define COM                                     XBYTE[0xFBFF]
#define LCD1602_RS_SET() PB|=1<<0
#define LCD1602_RS_RST() PB&=~(1<<0)
#define LCD1602_RW_RST() PB&=~(1<<1)
#define LCD1602_E_SET() PB|=1<<2
#define LCD1602_E_RST() PB&=~(1<<2)
static void Delay_ms(unsigned char time)
{
unsigned char i;
while(time--)
{
for(i=0;i<100;i++);
}
}
static void LCD1602_WriteByte(unsigned char value,bit dataTypedef)
{
if(dataTypedef)
LCD1602_RS_SET();
else
LCD1602_RS_RST();
LCD1602_RW_RST();
PA = value;
LCD1602_E_SET();
Delay_ms(2);
LCD1602_E_RST();
}
static void LCD1602_Init(void)
{
LCD1602_WriteByte(0x38,0);
Delay_ms(10);
LCD1602_WriteByte(0x01,0);
Delay_ms(10);
LCD1602_WriteByte(0x06,0);
Delay_ms(10);
LCD1602_WriteByte(0x0C,0);
Delay_ms(10);
}
static void LCD1602_ShowString(unsigned char address,unsigned char *string)
{
LCD1602_WriteByte(address,0);
while(*string)
{
LCD1602_WriteByte(*string++,1);
}
}
static unsigned char bdata KeyStatus=0xFF;
sbit KEY1 = KeyStatus^4;
sbit KEY2 = KeyStatus^5;
sbit KEY3 = KeyStatus^6;
sbit KEY4 = KeyStatus^7;
static unsigned char KeyValue=48;
static void KEY_Testing(void)
{
PC = 0xFE;
KeyStatus = PC&0xFF;
if(KeyStatus!=0xFF)
{
if(!KEY1)KeyValue='7';
if(!KEY2)KeyValue='8';
if(!KEY3)KeyValue='9';
if(!KEY4)KeyValue='/';
}
PC = 0xFD;
KeyStatus = PC&0xFF;
if(KeyStatus!=0xFF)
{
if(!KEY1)KeyValue='4';
if(!KEY2)KeyValue='5';
if(!KEY3)KeyValue='6';
if(!KEY4)KeyValue='*';
}
PC = 0xFB;
KeyStatus = PC&0xFF;
if(KeyStatus!=0xFF)
{
if(!KEY1)KeyValue='1';
if(!KEY2)KeyValue='2';
if(!KEY3)KeyValue='3';
if(!KEY4)KeyValue='-';
}
PC = 0xF7;
KeyStatus = PC&0xFF;
if(KeyStatus!=0xFF)
{
if(!KEY1)KeyValue='?';
if(!KEY2)KeyValue='0';
if(!KEY3)KeyValue='=';
if(!KEY4)KeyValue='+';
}
}
void main()
{
COM  = 0x88;
PA   = 0xFF;
PB   = 0xFF;
PC   = 0xFF;
LCD1602_Init();
LCD1602_ShowString(0x82,"Hello World!");
LCD1602_ShowString(0xC0,"Key Pressed--->");
while(1)
{
KEY_Testing();
LCD1602_WriteByte(0xCF,0);
LCD1602_WriteByte(KeyValue,1);
}
}

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com