本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P3^4;
uchar temp;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z)
{
uint x,y;
for( x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uint temp)
{
uchar ge,shi,bai;
bai=temp/100;
shi=(temp%100)/10;
ge=temp%10;
P2=0xf8;
P0=table[bai];
delay(1);
P2=0xf9;
P0=table[shi];
delay(1);
P2=0xfa;
P0=table[ge];
delay(1);
}
uchar key()
{
uint num;
//num=11;
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
delay(5);
num++;
if(num==60)
num=0;
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
delay(5);
num-- ;
if(num<0)
num=0;
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
num+=2;
if(num==60)
num=0;
}
}
return num;
}
void main()
{
uchar flag;
while(1)
{
flag=key();
display(flag);
}
}
该程序每次运行时,当数码管加到9时往后在加就会自动清零。。。急求高手帮忙解释下这是为什么。。。需要怎么改 |