📄 0123456789.txt
字号:
#include<at89x52.h>
unsigned char code p[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90};
unsigned char k=0,k0=0,k1=0,k2=0,k3=0,k4=0,k5=0,k6=0,k7=0,k8=0,k9=0,k10=0,k11=0,k12=0,k13=0,k14=0,k15=0;
unsigned char temp0=0,temp1=0,temp2=0,temp3=0,temp4=0,temp5=0,temp6=0,temp7=0;
unsigned char temp8=0,temp9=0,temp10=0,temp11=0,temp12=0,temp13=0,temp14=0,temp15=0;//K值状态检测量
void delay(unsigned int re)//延时子程序
{
while(--re);
}
void key_press(void)//键盘扫描子程序
{
temp0=k0;temp1=k1;temp2=k2;temp3=k3;temp4=k4;temp5=k5;temp6=k6;temp7=k7;
temp8=k8;temp9=k9;temp10=k10;temp11=k11;temp12=k12;temp13=k13;temp14=k14;temp15=k15;//K值赋予检测量temp
P0_0=0;
if(P0_4==0){while(P0_4==0);k0=!k0;}
if(P0_5==0){while(P0_5==0);k1=!k1;}
if(P0_6==0){while(P0_6==0);k2=!k2;}
if(P0_7==0){while(P0_7==0);k3=!k3;}
P0_0=1;//键盘第一行扫描
P0_1=0;
if(P0_4==0){while(P0_4==0);k4=!k4;}
if(P0_5==0){while(P0_5==0);k5=!k5;}
if(P0_6==0){while(P0_6==0);k6=!k6;}
if(P0_7==0){while(P0_7==0);k7=!k7;}
P0_1=1;//键盘第二行扫描
P0_2=0;
if(P0_4==0){while(P0_4==0)k8=!k8;}
if(P0_5==0){while(P0_5==0);k9=!k9;}
if(P0_6==0){while(P0_6==0);k10=!k10;}
if(P0_7==0){while(P0_7==0);k11=!k11;}
P0_2=1; //键盘第三行扫描
P0_3=0;
if(P0_4==0){while(P0_4==0);k12=!k12;}
if(P0_5==0){while(P0_5==0);k13=!k13;}
if(P0_6==0){while(P0_6==0);k14=!k14;}
if(P0_7==0){while(P0_7==0);k15=!k15;}
P0_3=1;//键盘第四行扫描
}
void main()
{
unsigned char accont_way=0;
unsigned char i,n=0;
unsigned int x=0,cont=0;
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
while(1)
{
key_press();
if(temp0!=k0){n=0;x=10*x+n;}
if(temp1!=k1){n=1;x=10*x+n;}
if(temp2!=k2){n=2;x=10*x+n;}
if(temp3!=k3){n=3;x=10*x+n;}
if(temp4!=k4){n=4;x=10*x+n;}
if(temp5!=k5){n=5;x=10*x+n;}
if(temp6!=k6){n=6;x=10*x+n;}
if(temp7!=k7){n=7;x=10*x+n;}
if(temp8!=k8){n=8;x=10*x+n;}//检测到KZ值改变则执行操作
if(temp9!=k9){n=9;x=10*x+n;}//按键显数值累加
if(temp10!=k10) {cont=x;x=0;accont_way=0;}//按键加
if(temp11!=k11) {cont=x;x=0;accont_way=1;}//按键减
if(temp14!=k14) {cont=x;x=0;accont_way=2;}//按键乘
if(temp15!=k15) {cont=x;x=0;accont_way=3;}//按键除
if(temp12!=k12) {x=0;k=0;n=0;cont=0;}
if(temp13!=k13)
{
switch(accont_way)//选择计算方式
{
case 0 :x=x+cont;break;
case 1 :x=cont-x;break;
case 2 :x=cont*x;break;
case 3 :x=cont/x;break;
}
}
for(i=0;i<4;i++)
{
switch(i)
{
case 0 :P1=p[x%10];P2_0=0;delay(50);P2_0=1;break;
case 1 :P1=p[(x%100)/10];P2_1=0;delay(50);P2_1=1;break;
case 2 :P1=p[(x%1000)/100];P2_2=0;delay(50);P2_2=1;break;
case 3 :P1=p[x/1000];P2_3=0;delay(50);P2_3=1;break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -