急求一个基于89C51单片机,8255A,用矩阵键盘输入数字,并在LCD1602上显示出来的C语言程序 150
接线图如下图所示,51单片机P0口接D0-D7,LCD1602接PA0-PA7,矩阵键盘接PC0-PC7,LCDRS接PB0,RW接PB1,E接PB2,因为8255A没有...
接线图如下图所示,51单片机P0口接D0-D7,LCD1602接PA0-PA7,矩阵键盘接PC0-PC7,LCDRS接PB0,RW接PB1,E接PB2,因为8255A没有接触过,急求,真的很急。。
展开
展开全部
#include<reg52.h>
#include<absacc.h>
#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);
}
}
更多追问追答
追问
不好意思,能改一下让它显示最少两位数吗,你这个只能显示一位数,改好了给你加分,谢谢
追答
你想显示什么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询