#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);
}
写的是低频率计,加信号时没反应.如果要两位小数的,如何改??
此帖出自
小平头技术问答
void int0() interrupt 0
{
TR1=1;
shu++;
if(shu==16)//计15
shu=0;
TR1=0;
EX0=0;
}
//这里,至少写成t1吧,我一般习惯写成TimerX
//但关系不大,只是0 和 1 总要分清楚吧,差点混淆了,幸好有个interrupt 3
void t0() interrupt 3
{
count++;
}
//额滴神!!
//兄弟,你拼命刷掉TH1 TL1,它能溢出才怪!
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;
}
“写的是低频率计,加信号时没反应.如果要两位小数的,如何改??”
你先把 反应 弄出来再说......
一周热门 更多>