新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于單片機(jī)的頻率計(jì)的設(shè)計(jì)(C51語言)

基于單片機(jī)的頻率計(jì)的設(shè)計(jì)(C51語言)

作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
// 用定時(shí)器1定時(shí),使用方式一,晶振頻率為11.0592MHZ,常數(shù)為4C00;

//用外部中斷一計(jì)數(shù),每中斷一次,count加一

本文引用地址:http://butianyuan.cn/article/201611/321854.htm

//使用P1口接的八個(gè)發(fā)光二極管顯示

//本程序?yàn)橐粋€(gè)網(wǎng)友應(yīng)邀而寫,在硬件上測(cè)試通過,在低頻率時(shí),效果不錯(cuò).

#include
unsignedint t1oc=20;//5000;
unsignedintcount=0,precount;
void display(unsigned int dis)
{
P1=dis;//顯示語句
}
void t1int() interrupt 3
{
TR1=0;
t1oc--;
TH1=0x4c;//72;//56;
TL1=0x00;//72;//56;
if(t1oc==0)
{
t1oc=20;//5000;
precount=count;
count=0;
}
TR1=1;
}
void int0int() interrupt 0
{

EX0=1;
count++;
EX0=0;
}
void main(void)
{
TMOD=0x10;//0x20;
TH1=0x4c;//72;//56;
TL1=0x00;//72;//56;
EA=1;
EX0=1;IT0=1;
ET1=1;
TR1=1;
while(1)
{
display(precount);
}
}



評(píng)論


技術(shù)專區(qū)

關(guān)閉