資源簡(jiǎn)介
基于單片機(jī)的4*4鍵盤的計(jì)算器,編譯正確,有protues仿真已運(yùn)行正確。用lcd1602顯示數(shù)字,可以實(shí)現(xiàn)+、—、*、出。

代碼片段和文件信息
#include
#include?
#define?uint?unsigned?int
#define?uchar?unsigned?char
sbit?lcden=P2^2;
sbit?lcdrw=P2^1;
sbit?lcdrs=P2^0;
uchar?numtempjia=0jian=0cheng=0chu=0qing=0;
uint?keykey1shu;
uchar?fuhaoflag1flag=0;
uchar?table[]={
0x3f0x060x5b0x4f
0x660x6d0x7d0x07
0x7f0x6f0x0};
void?delay(uint?z)
{
uint?xy;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
bit?lcd_bz()
{
bit?result;
lcdrs=0;
lcdrw=1;
lcden=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=(bit)(P0&0x80);?
lcden=0;
return?result;
}
void?write_com(uchar?com)
{
while(lcd_bz());
lcdrs=0;
lcden=0;
lcdrw=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void?write_date(uchar?date)
{
while(lcd_bz());
lcdrs=1;
lcden=0;
lcdrw=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void?lcd_init()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void?keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case?0xee:key=1;num=0;break;
case?0xde:key=2;num=0;break;
case?0xbe:key=3;num=0;break;
case?0x7e:num=1;break; //加號(hào)
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case?0xed:key=4;num=0;break;
case?0xdd:key=5;num=0;break;
case?0xbd:key=6;num=0;break;
case?0x7d:num=2;break; //減號(hào)
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case?0xeb:key=7;num=0;break;
case?0xdb:key=8;num=0;break;
case?0xbb:key=9;num=0;break;
case?0x7b:num=3;break; //乘號(hào)
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case?0xe7:key=0;num=0;break;
case?0xd7:num=6;break; //清除
case?0xb7:num=5;break; //等于號(hào)
case?0x77:num=4;break; //除號(hào)
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
void?display0(uint?shu)
{
uint?ge;
ge=shu;
write_date(0x30+ge);
}
void?display1(uint?shu)
{
uint?shige;
shi=shu/10;
ge=shu%10;
write_date(0x30+shi);
write_date(0x30+ge);
}
void?display2(uint?shu)
{
uint?baishige;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void?display3(uint?shu)
{
uint?qianbaishige;
qian=shu/1000;
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????85657??2013-04-24?12:54??計(jì)算器\a.DSN
?????文件????????768??2013-04-26?12:15??計(jì)算器\a.PWI
?????文件??????20716??2013-04-23?10:22??計(jì)算器\counter
?????文件???????6496??2013-04-23?10:22??計(jì)算器\counter.hex
?????文件?????????61??2013-04-23?10:22??計(jì)算器\counter.lnp
?????文件??????31282??2013-04-23?10:22??計(jì)算器\counter.M51
?????文件???????1068??2013-04-23?11:08??計(jì)算器\counter.Opt
?????文件???????1138??2013-04-23?10:22??計(jì)算器\counter.plg
?????文件???????2034??2013-04-23?11:08??計(jì)算器\counter.Uv2
?????文件??????????0??2013-04-23?10:01??計(jì)算器\counter_Uv2.Bak
?????文件???????6463??2013-04-23?10:21??計(jì)算器\couter.c
?????文件??????17788??2013-04-23?10:22??計(jì)算器\couter.LST
?????文件??????25774??2013-04-23?10:22??計(jì)算器\couter.OBJ
?????文件??????85657??2013-04-24?12:54??計(jì)算器\Last?Loaded?a.DBK
?????文件???????5115??2011-10-27?16:11??計(jì)算器\STARTUP.A51
?????文件??????11665??2013-04-23?10:22??計(jì)算器\STARTUP.LST
?????文件????????758??2013-04-23?10:22??計(jì)算器\STARTUP.OBJ
?????目錄??????????0??2013-04-26?12:15??計(jì)算器
-----------?---------??----------?-----??----
???????????????302440????????????????????18
評(píng)論
共有 條評(píng)論