#include<absacc.h>
#define?PAXBYTE[0xF8FF]
#define?PBXBYTE[0xF9FF]
#define?PCXBYTE[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);
}
}