📄 delay.c
字号:
#define delay_GLOBALS
#include "config.h"
#include "delay.h"
#include "zlg500S_comm.h"
#include "zlg500s.h"
/*****************************************************************************
FUNCTION: 定时器2定时中断设置
IN: resolution 分辨率
OUT: -
COMMENT:
if resolution=RCAP2_50us,then 定时器每50us中断一次
if resolution=RCAP2_5ms,then 定时器每5ms中断一次
if resolution=RCAP2_10ms,then 定时器每10ms中断一次
*****************************************************************************/
#if T2int_timeout_en
void T2_timeout_init(INT16U resolution)
{
ET2 = 0; // Disable Timer2 interrupt
TR2 = 0;
RCAP2LH = resolution;
T2LH = resolution;
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
ET2 = 1; // Enable Timer2 interrupt
}
/*****************************************************************************
FUNCTION: stop_timeout
IN: -
OUT: -
COMMENT: Stop Timer2 and clear timeout state
*****************************************************************************/
//void stop_timeout(void)
//{
// ET2 = 0; // disable Timer2 interrupt
// T2CON = 0x00; // 16-bit auto-reload, clear TF2, stop timer
//}
/*****************************************************************************
Interrupt Handler TIMER2
*****************************************************************************/
void T2_server(void) interrupt 5 using 2 //Timer2 interrupt
{
if(WaitRespDly)
WaitRespDly--;
TF2 = 0;
}
#endif
#pragma noaregs
/***********************************************************************
***********************************************************************/
#if delay_T0_en
void delay_T0(INT16U _T0HL)
{
TMOD &= 0xf0;
TMOD |= 0x01;
ET0 = FALSE;
TH0 = _T0HL>>8;
TL0 = _T0HL;
TR0 = TRUE;
TF0 = FALSE;
while(!TF0);
TR0 = FALSE;
}
#endif
/****************************************************************************
* *
* Function: delay_50us *
* *
* Input: _50us *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 50 us. *
* *
****************************************************************************/
#if delay_50us_en
void delay_50us (INT8U _50us)
{
RCAP2LH = RCAP2_50us;
T2LH = RCAP2_50us;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_50us--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
#endif
/****************************************************************************
* *
* Function: delay_1ms *
* *
* Input: _1ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 1 ms. *
* *
****************************************************************************/
#if delay_1ms_en
void delay_1ms (INT16U _1ms)
{
RCAP2LH = RCAP2_1ms;
T2LH = RCAP2_1ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_1ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
#endif
/****************************************************************************
* *
* Function: delay_10ms *
* *
* Input: _10ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 10 ms. *
* *
****************************************************************************/
#if delay_10ms_en
void delay_10ms (INT16U _10ms)
{
RCAP2LH = RCAP2_10ms;
T2LH = RCAP2_10ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_10ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
#endif
#pragma aregs
//The end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -