新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于单片机的频率计的设计(C51语言)

基于单片机的频率计的设计(C51语言)

作者: 时间:2016-11-26 来源:网络 收藏
// 用定时器1定时,使用方式一,晶振频率为11.0592MHZ,常数为4C00;

//用外部中断一计数,每中断一次,count加一

本文引用地址:https://www.eepw.com.cn/article/201611/321854.htm

//使用P1口接的八个发光二极管显示

//本程序为一个网友应邀而写,在硬件上测试通过,在低频率时,效果不错.

#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);
}
}



评论


技术专区

关闭