- #include "My_head.h"
- /**************************************************/
- #define TIMER_SIZE 6
- TIMER_EVENT idata Timer_s[TIMER_SIZE];
- BYTE Timer_Count=0; //for main and other.
- extern BYTE enble_send_count;
- extern BYTE receive_timer;//for uart!
- void timer0_int(void) interrupt 1 using 1
- {
- register BYTE i;
- TR0 = 0;
- TH0 = 0x70;//0xB8;//0x3C; //0x40 //0x3f
- TL0 = 0x00;//0x00;//0xB0; //0x40 //0x7f
- TR0 = 1;
- /**************************************/
- if(Timer_Count)Timer_Count--;
- /**************************************/
- if(receive_timer)if(--receive_timer==0)REN=TRUE;
- if(enble_send_count)enble_send_count--;
- /**************************************/
- for(i=0;i<TIMER_SIZE;i++)
- if((Timer_s[i].event & 0x80))
- {
- if(Timer_s[i].time)Timer_s[i].time--;
- else{
- Timer_s[i].event &= 0x7f;
- Timer_s[i].event |= 0x40;
- }
- }
- }
- /*--------------------------------------------------*/
- void Stop_Timer(BYTE evt)
- {
- BYTE i;
- for(i=0;i<TIMER_SIZE;i++)
- if(evt == (Timer_s[i].event & 0x3F))
- {
- Timer_s[i].event = NULL;
- Timer_s[i].time = 0;
- }
- }
- /*--------------------------------------------------*/
- void Stop_All_Timer(void)
- {
- BYTE i=TIMER_SIZE;
- while(i--)
- {
- Timer_s[i].event = NULL;
- Timer_s[i].time = 0;
- }
- }
- /*--------------------------------------------------*/
- #define MAX_TIMER_EVENT 0x3f
- bit Set_TimerEvent(BYTE event,WORD times_20ms)
- {
- BYTE i;
- if(event>MAX_TIMER_EVENT)return(FALSE);
- for(i=0;i<TIMER_SIZE;i++)
- if(!(Timer_s[i].event & 0xC0))
- {
- Timer_s[i].time = times_20ms;//time*50-1;
- Timer_s[i].event = event|0x80;
- return TRUE;
- }
- return FALSE;
- }
- /*--------------------------------------------------*/
- BYTE Check_Timer_Event(void)
- {
- BYTE i;
- for(i=0;i<TIMER_SIZE;i++)
- if((Timer_s[i].event & 0x40))
- {
- PostMessage(TIMER_COMED_EVENT,(Timer_s[i].event & 0x3f));
- Timer_s[i].event = NULL;
- Timer_s[i].time = 0;
- }
- return(0);
- }
- /*--------------------------------------------------*/
- void Init_Timer0(void)
- {
- EA = 0;
- ET0 = 0;
- TR0 = 0; //(定时器0运行控制位,1表开启0表关闭)
- TMOD &= 0xF0; //(定时器T0)
- TMOD |= 0x01; // Mode 1
- TH0 = 0x70; // 11.0592MHZ: 50ms--3ce1 (3ce1到ffff时大概为50ms)
- TL0 = 0x00; // 11.0592MHZ: 40MS--9C42 ,B800--20ms
- //Open_Timer0();
- ET0 = 1; //(定时器0的中断允许位,1表示允许0表示禁止)
- TR0 = 1; // TCON |= 0x10;ǘㄊ逼