⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 输出视频的字符的软件
💻 C
字号:
/*-------------------------------------*/
/*
  THIS FOR TIMER SUBROUTINE USEED
  TO SET TIMER TO 4S, 60S, 10MS, &INTERRUPT WITH THE TIMEERS

*/
/*-------------------------------------*/
/*
   this routine to use the timer & respone timer interrupt


*/
/*------------------------------------*/
#include "defineh.h"
#include "timer.h"
/*-----------------------------------*/
extern void Clr_Rx(void);
/*----------------------------------------*/
 
void init_timer2()
{   // init the timer2 to 30ms to determine the answer-frame full or not, if not dompleted, delete it weather a message frame.
    //if not , free the comm line.if a message frame, count for 4s.if a right respone ,count 1min.
    //NOT confirm the data
 #if CRYSTALOID
  { //12MHZ
  TH2=0x8a;
  TL2=0xd0;
  }
 #else 
  {
   TH2=0x94;
   TL2=0x2f;
  }
 #endif

	 T2CON=0X03;    /*timer enble,*/
	 T2MOD=0x01;   /*timer reload mode*/
	 timeout2=0;

 T2CON=0;
 ET2=1;
 TR2=1;

}
/*------------------------------------------*/
/*            INIT TIMER0
Description: 
           timer0 use to count 3ms once a time, to determine a data received


*/

/*-----------------------------------------------*/
void init_timer0(void)
{
//TMOD=0x21;    //*定时器0工作方式1,16位定时
 #if CRYSTALOID   //定时器该为3ms定时
  { //12MHZ
  TH0=0xfC;  //TH0=0xf4;  //3MS
  TL0=0x18;  //TL0=0x48;
  
  }
 #else 
  {
   TH0=0xf5;
   TL0=0x50;
  }
 #endif

  TR0=1;       //To enable bit
  ET0=1;      //open To,enable it interrupt
  timeout0=0;
}
/*-------------------------------------------*/
/*     every received must less than 2ms,if a receiving action not wrong,
       when finished a receiving,clr the timer0


*/
/*--------------------------------------------*/
void timer0_out() interrupt 1
{
   TF0=0;
   
     if(Rxrun_bit)
	{
		if(Rx_count>timeout0)  //not late the data
		  {
		  	timeout0=Rx_count;

            #if CRYSTALOID   //定时器该为1ms定时
               { //12MHZ
                TH0=0xfC;  //TH0=0xf4;  //1MS
                TL0=0x18;  //TL0=0x48;
  
               }
           #else 
               {
               TH0=0xf5;
               TL0=0x50;
               }
            #endif
		   }
		else
		   {
			Clr_Rx();
   	        TR0=0;
		   }
     }
    else      //rx finish
	 {
	     TR0=0;
     }
}
/*--------------------------------------------*/
/*
                 timer2 count 1s, if lower than 15 bytes, the datas valid & not a message frame
                 if rx_count more than 16 byte, must be a message frames or a bad frame
                 And, timeout2 cout 25 times for 1s
                 timeout1 count for the cycle 
*/
/*-------------------------------------------*/
void timer2_out() interrupt 5
{
     TF2=0;
     timeout2++;
}
/*---------------------------------------------*/
void clr_timer2(void)
{

         T2CON=0X00;
         T2MOD=0x00; 
		 TR2=0;

		 TL2=0;
		 TH2=0;
		 timeout2=0;
               
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -