Demo entry 6730898

External_Trigger

   

Submitted by 徐浩 on Apr 09, 2018 at 12:45
Language: C. Code size: 992 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).