找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

哪位好心人能帮帮心啊,频率计加信号时乱显示!

[复制链接]
admin 发表于 2012-9-2 09:15:17 | 显示全部楼层 |阅读模式

本文包含原理图、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;
}
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 12:53 , Processed in 0.049612 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表