#define uint unsigned int
#define uchar unsigned char
sbit d1=P1^0;
sbit duan=P2^6;
sbit wei=P2^7;
sbit key1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//数码管编码
uchar num;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
wei=1;
P0=0xfe;//打开两个数码显示管共阴极锁存
wei=0;
P3=0xff; //向P3口写1
while(1)
{
if(key1==0)
{
delay(5); //按键前消抖
if(key1==0)
{
d1=0;
num++;
if(num==16)
num=0;
}
while(!key1);
delay(5); //按键后消抖
while(!key1);
}
else
d1=1; //灭灯
duan=1;
P0=table[num]; //打开锁存器,数码管输出数字
duan=0;
}
}
- 本文固定链接: http://ttfde.top/index.php/post/100.html
- 转载请注明: admin 于 TTF的家园 发表
《本文》有 0 条评论