#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);
}
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/cefc1e178a82b901130b5648798da9773912ef23?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追问不好意思,能改一下让它显示最少两位数吗,你这个只能显示一位数,改好了给你加分,谢谢
追答你想显示什么
追问就是按键盘上的数字键,能显示12,34,45这种两位数的,你这个我仿真了一下,只能显示一位数,改好了给你加分,谢谢
追答按一个键直接显示12或34?按键跟显示的关系是什么?
追问按1,2显示12,按3,4显示34,按5,6显示56这种的。。。。。
追答太大了,发不了