#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=zx>0x--)
for(y=110y>0y--)//能使之延时接近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 = numindexTmp<=7indexTmp++)
{
W[indexTmp] = num%10
num /=10
}
P0 = (0x01<<showIndex)//位选
P2 = table[W[showIndex]]//段选
showIndex++
if(showIndex>=8)
showIndex=0
}
}
看了你的全图,修改后了,用Keil uVision 3或4都可以,编译后可以查看对应的汇编代码
程序稍大一点的,不会有人用汇编来给你蘑菇,汇编设计写编码太慢了,开发代价不值得
设置两个按钮,加按钮 *** 作属性,抬起功能,数据对象 *** 作:按0松1,add.脚本程序:if add =1 then
数据=数据+1
endif
减按钮 *** 作属性,抬起功能,数据对象 *** 作:按0松1,sud.脚本程序:
if sub =1 then
数据=数据-1
endif
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)