#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;
}
void int0() interrupt 0
{
TH0=0;重装
TL0=0;
TR1=1;
shu++;
if(shu==16)//计15
shu=0;
TR1=0;
EX0=0;
}
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;
}
自己试了之后,没加信号数码管就乱显.
一周热门 更多>