Demo entry 6730900

1

   

Submitted by 徐浩 on Apr 09, 2018 at 12:49
Language: C. Code size: 821 Bytes.

/*
1、该程序通过利用Proteus产生方波输入INT1引脚(P3.3);
2、利用TMOD最高位GATE=1时候,T1在受INT1为高电平(Pin3.3)且TR1=1时才
能启动计数特性来测量输入INT1上正脉冲的宽度;
3、Proteus调整不同的方波频率,对程序进行验证。
*/

#include <REG52.H>
unsigned int count=0;	//T1定时器计时次数,每次0.2ms
unsigned int onems=0;	//单位是ms
sbit P33=P3^3;
int main(void)
{
	P1=100;	//赋初值,测试LED输出显示是否正常
	TMOD=0xA0;	//定时器T1,模式1,门控位GATE=1
	TL1=0x38;	//装入T1记数初值
	TH1=0x38;
	ET1=0x01;	//T1中断允许
	EA=0x01;	//总中断允许
	TR1=0x00;   //T1运行控制位关闭
	while(1)
	{	
	    while(P33);		//等待低电平
		while(!P33);	//等待高电平
		TR1=0x01;		//T1开始定时
		while(P33);     //等待低电平
		TR1=0x00;		//关闭T1定时
		P1=1000*(onems+(count*0.2))+(TL1-TH1); 	//计算高电平脉宽
		TL1=0x38; TH1=0x38;
	    count=0;onems=0;		
	}			
}
    //T1中断函数
void Interrupt_T1() interrupt 3
{
   count++;
   if(count==5)
   {
	   onems++;  
	   count=0;
   }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).