#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar shu=0,count=0;
uchar qian,bai,shi,ge;
long f;
uchar code dutable[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void int0() interrupt 0
{
TR1=1;
shu++;
if(shu==16)//计15
shu=0;
TR1=0;
EX0=0;
}
void t0() interrupt 3
{
count++;
}
void init()
{
TMOD=0x10;
TH1=0;
TL1=0;
IE=1;
ET1=1;
EX0=1;
IT1=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
init();
while(1)
{
f=(count*65536+TH1*256+TL1)/15;
f=1000000/f;
qian=f/1000;
bai=f%1000/100;
shi=f%100/10;
ge=f%10;
display(qian,bai,shi,ge);
count=0;
TH1=0;
TL1=0;
TR1=1;
EX0=1;
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
P2=0x01;
P0=dutable[qian];
delay(5);
P2=0x02;
P0=dutable[bai];
delay(5);
P2=0x04;
P0=dutable[shi];
delay(5);
P2=0x08;
P0=dutable[ge];
delay(5);
}
写的是低频率计,加信号时没反应.如果要两位小数的,如何改??
此帖出自
小平头技术问答
写好了!
不知道对呢,对呢,对呢,还是对呢!
要是不对!
再说吧!
好吧!
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar qian,bai,shi,ge;
long f;
bit flag;
uint count;
sbit fin=P1^3;
sbit fout=P1^7; //用导线将P1_7脚(发生频率引脚)的频率输出连接P1_3脚(测量频率管脚)
uchar code dutable[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
P2=0X01;
P0=dutable[qian];
delay(5);
P2=0X02;
P0=dutable[bai];
delay(5);
P2=0X04;
P0=dutable[shi];
delay(5);
P2=0X08;
P0=dutable[ge];
delay(5);
}
void main()
{
uint temp;
EA=1;
IT0=1;
TMOD=0X11;
TH1=(65535-500)/256;
TL1=(65535-500)%256;
ET0=1;
ET1=1;
TR1=1;
while(1)
{
bit fin_before=0;
bit fin_now=0;
uchar flag=0;
// uint count;
// TH0=0;
// TL0=0;
while(1)
{
fin_now=fin;
if(fin_before&&!fin_now)
{
flag++;
EX0=1;
}
if(flag==2)
{
EX0=0;
f=1000000/count;
return;
}
fin_before=fin_now;
}
qian=f/1000;
bai=f%1000/100;
shi=f%100/10;
ge%10;
display(qian,bai,shi,ge);
}
}
void timer0() interrupt 0
{
count++;
}
void timer1() interrupt 3
{
TH1=(65535-1000)/256;
TL1=(65535-1000)%256;
}
一周热门 更多>