📄 gk_timer0.c
字号:
/*------------------------------------------------------------------------------
uPSD_TIMER.C
------------------------------------------------------------------------------*/
//#pragma CODE // include assembler listing in .lst file
#include ".\include\gk_timer0.h"
#include ".\include\reg52.h"
#include ".\include\gk_extern_var.h"
#include <intrins.h>
#define TIMER0_INTERVAL 0xF8CC // set timer T0 for 1ms tick
static int kkkkk=100;
/*------------------------------------------------------------------------------
Local Variable Declarations
------------------------------------------------------------------------------*/
//static unsigned int timer0_tick;
/*------------------------------------------------------------------------------
static void timer0_isr (void);
This function is an interrupt service routine for TIMER 0. It should never
be called by a C or assembly function. It will be executed automatically
when TIMER 0 overflows.
------------------------------------------------------------------------------*/
static void gk_timer0_isr (void) interrupt 1 using 1
{
// TR0 = 0; // stop timer 0
// TL0 = TL0 + (TIMER_INTERVAL & 0x00FF); // Update LSB
// TH0 = TH0 + (TIMER_INTERVAL >> 8); // Update MSB
// TR0 = 1; // start timer 0
TL0 = (TIMER0_INTERVAL & 0x00FF); // set LSB timeout
TH0 = (TIMER0_INTERVAL >> 8); // set MSB timeout
if(COMM_INT_FALG_1) //通讯1超时监测
{
SERIAL_TIME_FACTOR_1++;
if(SERIAL_TIME_FACTOR_1>100) //30ms
{
START_FLAG_1=0;
FUNC_FLAG_1=0;
SYNC_FLAG_1=0;
LENG_FLAG_1=0;
SERIAL_TIME_FACTOR_1=0;
COMM_INT_FALG_1=0;
// SERIAL_R_COMPLETE_1=0; //
}
}
kkkkk++;
}
/*------------------------------------------------------------------------------
void timer0_initialize (void);
This function enables TIMER 0. TIMER 0 will generate a synchronous interrupt
once every 100Hz (10mS).
------------------------------------------------------------------------------*/
void gk_timer0_initialize (void) // Enable TMR0 for 10mS interrupts
{
// EA = 0; // disable interrupts
TR0 = 0; // stop timer 0
TMOD &= ~0x0F; // clear timer 0 mode bits
TMOD |= 0x01; // put timer 0 into 16-bit no prescale
TL0 = (TIMER0_INTERVAL & 0x00FF);// set LSB timeout
TH0 = (TIMER0_INTERVAL >> 8); // set MSB timeout
PT0 = 1; // timer0 is 1st priority
ET0 = 1; // enable timer 0 interrupt
TR0 = 1; // start timer 0
// EA = 1; // enable interrupts
IE&=0x7F;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -