?? 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 + -