#include<reg52>
#define uchar unsigned char
#define uint unsigned int
sbit K1 = P1^4;
sbit K2 = P1^5;
uchar data K1state;
uchar data K2state;
uint data num,ntmp;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x06f,0x77,0x7c,0x39,0x5e,0x79,0x71} ;
uchar data showIndex,indexTmp;
uchar data W[8];
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);//能使之延时接近1毫秒就成 无需精确
}
void main()
{
K1state = 0xFF;
K2state = 0xFF;
num = 0;
while(1)
{
delay(1);//每毫秒轮询一回
//移位法,延时防抖
K1state = (K1state<<1);
K2state = (K2state<<1);
if(K1) K1state++;
if(K2) K2state++;
//检查开关状态饥睁衫
早旅if(K1state==0x80) num++;
if(K2state==0x80) num--;
for(indexTmp=0,ntmp = num;indexTmp<=7;indexTmp++)
{
W[indexTmp] = num%10;
num /=10;
}
P0 = (0x01<<showIndex);//位选
P2 = table[W[showIndex]];//段选
showIndex++;
if(showIndex>=8)
showIndex=0;
}
}
看了你的全图,修改后了,用Keil uVision 3或4都可以,编译后可以查看对烂腔应的汇编代码
程序稍大一点的,不会有人用汇编来给你蘑菇,汇编设计写编码太慢了,开发代价不值得