51单片机做频率计,为什么两个数码管一直是00无法检测到频率
夏773636711
2018-11-19
#include #define uchar unsigned char #define uint unsigned int uchar f,num,shi,ge; bit flag; sbit dula=P2^6; sbit wela=P2^7; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c... #include
#define uchar unsigned char
#define uint unsigned int
uchar f,num,shi,ge;
bit flag;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
}
void main()
{f=0;num=0;
IP=0x02; //T0优先级高
TMOD=0x15; //TI定时。T0计数
TH0=0; //T0初值
TL0=0;
TH1=(65535-45872)/256; //T1初值50ms
TL1=(65535-45872)%256;
EA=1; // 开总中断
ET0=1; // 开定时器T0中断
TR0=1; // 开T0自启动方式开关
ET1=1; // 开定时器T0中断
TR1=1;
while(1)
{if(flag==1)
{shi=f/10;
ge=f%10;
flag=0;
f=0;
TH0=0;
TL0=0;
TR1=1;
}
display(shi,ge);
}
}
void T0time() interrupt 1 using 0 //T0计数
{
f++;
}
void T1time() interrupt 3 using 1//定时器
{
TH1=(65535-45872)/256; // 重装初值
TL1=(65535-45872)%256;
num++; //自加一次 50ms
if(num==20) // 判断是否为一秒
{
num=0;
TR1=0;
flag=1;
}
}
全部评论
您可能感兴趣的社区主题
评论
选购仪器 上yiqi.com
仪器网络推广
品牌网上传播
长按识别二维码查看信息详情