#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
sbit key1=P2^0; //功能键
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
uint num1=0; //功能键按键次数
uint num,num2,num3,num4;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90}; //不带小数点数组
uchar code table1[]=
{0x40,0x79,0x24,0x30,0x19,
0x12,0x02,0x78,0x00,0x10}; //带小数点数组
void delayms(uint xms);
void keyscan(void);
void display();
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint num)
{
uint qian,bai,shi,ge;
qian=num/1000;
bai= num/100%10;
shi= num/10%10;
ge = num%10;
wei1=0;
wei2=1;
wei3=1;
wei4=1;
P1=table[ge];
delayms(1);
wei1=1;
wei1=1;
wei2=0;
wei3=1;
wei4=1;
P1=table[shi];
delayms(1);
wei2=1;
wei1=1;
wei2=1;
wei3=0;
wei4=1;
P1=table1[bai];
delayms(1);
wei3=1;
wei1=1;
wei2=1;
wei3=1;
wei4=0;
P1=table[qian];
delayms(1);
wei4=1;
}
void keyscan(void)
{
if((key2==0)) //start or stop
{
delayms(10);
if(key2==0)
{
while(!key2);
TR0=0;
}
if(key2==0)
{
while(!key2);
TR0=1;
}
}
if(key1==0)
{
delayms(10);
if(key1==0)
{
num1++;
while(!key1);
}
}
if((key3==0)&&(num1==2)) //秒表加减1ms,调节小数点后时间,我不会写
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==2))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
if((key3==0)&&(num1==3)) //秒表加减1s,调节小数点前面时间
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==3))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
}
void main()
{
TMOD=0x01;
TH0=(65535-4587)/256;
TL0=(65535-4587)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(num2);
keyscan();
}
}
void T1_
time() interrupt 1
{
TH0=(65536-4587)/256;
TL0=(65536-4587)%256;
num3++;
if(num3==2)
{
num3=0;
num2++;
if(num3==10000)
{
num3=0;
}
}
}
谢谢
一周热门 更多>