//用51單片機(jī)檢測(cè)方波的頻率
#include<reg51.h>
#include"lcd.h"
void TimerConfiguration();
void LcdDisplay();
void IntConfiguration();
unsigned char Time;
unsigned char count;
unsigned char shu[4];
/*******************************************************************************
* 函 數(shù) 名 : main
* 函數(shù)功能 : 主函數(shù)
* 輸 入 : 無(wú)
* 輸 出 : 無(wú)
*******************************************************************************/
void main(void)
{
LcdInit();
TimerConfiguration();
count=0;
IntConfiguration();
while(1)
{
if(Time==20)
{
LcdDisplay();
count=0;
Time=0;
}
}
}
void TimerConfiguration()
{
TMOD = 0x01; //選擇工作方式1
TH0 = 0x3C; //設(shè)置初始值,定時(shí)50MS
TL0 = 0xB0;
EA = 1; //打開(kāi)總中斷
ET0 = 1; //打開(kāi)定時(shí)器0中斷
TR0 = 1; //啟動(dòng)定時(shí)器0
}
void Timer0() interrupt 1
{
TH0 = 0x3C; //設(shè)置初始值
TL0 = 0xB0;
Time++;
}
void IntConfiguration()
{
EX0 = 1; /* 開(kāi)外部中斷0 */
IT0 = 1; /* 脈沖觸發(fā) */
EA = 1; /* 開(kāi)總中斷 */
}
void Int0() interrupt 0
{
count++;
}
void LcdDisplay()
{
unsigned char a,b,c;
shu[0]=count/1000;
a=count%1000;
shu[1]=a/100;
b=a%100;
shu[2]=b/10;
c=b%10;
shu[3]=c;
LcdWriteCom(0x80);
LcdWriteData('0'+shu[0]&0x0f);
LcdWriteData('0'+shu[1]&0x0f);
LcdWriteData('0'+shu[2]&0x0f);
LcdWriteData('0'+shu[3]&0x0f);
}
|