程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit cc=P3^2;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^0;
sbit key2=P3^1;
unsigned long int aa,num,i,j,a,kk;
unsigned long int c,d;
uchar wan,qian,bai,shi,ge;
uchar code tabel1[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tabel2[]=
{0xff,0xfe,0xfd,0xfb,
0xf7,0xef,0xdf};
void delayms(uint);
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{
TMOD=0x19;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TH0=0;
TL0=0;
EA=1;
ET1=1;
TR1=1;
ET0=1;
TR0=0;
IT0=1;
EX0=1;
while(cc==1);
TR0=1;
while(cc==0);
while(cc==1);
TR0=0;
while(1)
{
display(wan,qian,bai,shi,ge);
}
}
void int0()interrupt 0
{
num++;
}
void T0_
time() interrupt 1
{
TH0=0;
TL0=0;
kk++;
}
void T1_time() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
j++;
if(j==20)
{
a=num;
num=0;
j=0;
}
}
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
aa=0;
c=a;
d=1.0*kk*65536+1.0*TH0*256+1.0*TL0;
if(key1==0)aa=c;
if(key2==0)aa=d*2;
wan=aa/10000;
qian=aa%10000/1000;
bai=aa%1000/100;
shi=aa%100/10;
ge=aa%100%10;
P0=tabel2[1];
wela=1;
wela=0;
P0=tabel1[wan];
dula=1;
dula=0;
delayms(1);
P0=tabel2[2];
wela=1;
wela=0;
P0=tabel1[qian];
dula=1;
dula=0;
delayms(1);
P0=tabel2[3];
wela=1;
wela=0;
P0=tabel1[bai];
dula=1;
dula=0;
delayms(1);
P0=tabel2[4];
wela=1;
wela=0;
P0=tabel1[shi];
dula=1;
dula=0;
delayms(1);
P0=tabel2[5];
wela=1;
wela=0;
P0=tabel1[ge];
dula=1;
dula=0;
delayms(1);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
-
测频率
-
不按键
-
测脉宽
一周热门 更多>