本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar pulse=0,second3=0;
uint timecount=0,second=0;
uchar second_sign,f_sign,i;
long freq=0;
uchar code we[]={
0x08,0x04,0x02,0x01};
uchar code dula[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
uchar led[4];
void init();
void int0() interrupt 0
{
TR0=1;
f_sign=1;
pulse++;
if(pulse==3)
{
pulse=0;
TR0=0;
TH0=0;
TL0=0;
timecount=0;
}
}
void t0() interrupt 1
{
timecount++;
}
void display() interrupt 3
{
TH1=0xf6;
TL1=0x3c;
P0=0xff;
P2=we[i];
P0=led[i];
i++;
if(i==4)
i=0;
second++;
if(second==100)
{
second_sign=1;
second=0;
}
}
void init()
{
TMOD=0x11;
TH0=0;
TL0=0;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
ET0=1;
ET1=1;
EX0=1;
PX0=1;
IT1=1;
TR1=1;
}
void main()
{
init();
while(1)
{
freq=(timecount*65536+TH0*256+TL0)/2;
if(freq)
freq=1000000.0/freq;
led[0]=dula[freq/1000];
led[1]=dula[freq%1000/100];
led[2]=dula[freq%100/10];
led[3]=dula[freq%10];
if((f_sign==0)&&(second_sign))
{
second3++;
if(second3==3)
{
second3=0;
timecount=TH0=TL0=0;
freq=0;
}
second_sign=0;
}
else if(f_sign)
second3=0;
f_sign=0;
}
} |