📄 fab.txt
字号:
#include "reg52.h"
unsigned char code Duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0X76,0X3e,0x55,0x37,0x77,0x5e,0x72};
unsigned char Data_Buffer[4]={1,2,0,0};
unsigned char PinLV_Out=10;//范围:10-90hz
unsigned char PinLV_In=0;
unsigned char th0,tl0;
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P13=P1^3;
sbit P23=P2^3;
sbit P32=P3^2;
sbit DOWN=P2^2;
sbit UP=P2^1;
bit flag=0;
unsigned char temp_th1,temp_tl1;
unsigned char count_t1=0,temp_count=0;
void Comute_pinlv()
{
float t;
unsigned int x;
t=1000/PinLV_Out/2;//计算高\低宽度时间ms为单位
t=t*921.6;
t=65535-t;
x=t;
th0=x/256;
tl0=x%256;
Data_Buffer[0]=PinLV_Out/10;
Data_Buffer[1]=PinLV_Out%10;
}
void main()
{
unsigned char Bit=0;
unsigned int xx;
float t;
bit x=1,y=1;
Comute_pinlv();
TMOD=0x11;
TH0=th0;
TL0=tl0;
TR0=1;
ET0=1;
EA=1;
IT0=1;
EX0=1;
TR1=1;
ET1=1;
while(1)
{
if(UP==1)x=1;//频率增加
else if(x==1)
{
x=0;
PinLV_Out+=5;
if(PinLV_Out>90)PinLV_Out=90;
Comute_pinlv(); //计算输出频率的定时器值
}
if(DOWN==1)y=1;//频率减小
else if(y==1)
{
y=0;
if(PinLV_Out>10)
PinLV_Out-=5;
Comute_pinlv();
}
if(flag)//重新计算频率
{
flag=0;
xx=temp_th1*256+temp_tl1;
t=xx+temp_count*65536;
t=t/921.6;//921.6代码对应1ms
t=1000/t;
PinLV_In=t;
Data_Buffer[2]=PinLV_In/10;//计算的频率在后两位数码管显示
Data_Buffer[3]=PinLV_In%10;
}
Bit++;//数码管扫描
if(Bit>=4)Bit=0;
P1|=0x0f;
P0=Duan[Data_Buffer[Bit]];
switch(Bit)
{
case 0: P10=0;break;
case 1: P11=0;break;
case 2: P12=0;break;
case 3: P13=0;break;
}
}
}
void timer0() interrupt 1 //方波发生定时器
{
TH0=th0;
TL0=tl0;
P23=!P23;//方波输出
P32=P23;//实际当中应用线连接
}
void int0() interrupt 0 //外部中断,P32作测频。
{
flag=1; //需要更新频率,即重新计算频率值
temp_th1=TH1;//临时存储计频数据
temp_tl1=TL1;
temp_count=count_t1;
TH1=0; //重新置0,重新启动方波宽度时间计时
TL1=0;
count_t1=0;
}
void timer1() interrupt 3
{
count_t1++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -