本帖最后由 bhsdlmj 于 2012-5-17 09:36 编辑
、、、、、、、、、、、、、、、、、、、、、、、
#define TMR0_IRQ_INTERVAL_VALUE 1 //单位:毫秒
#if TMR0_IRQ_INTERVAL_VALUE > 2
#error "handsome boy, attention: TMR0_IRQ_INTERVAL_VALUE's maximum value is 296/100 ms"
#endif
#define TH0_RELOAD_VALUE (65536 - ((INT32U)SYSCLK * TMR0_IRQ_INTERVAL_VALUE) / 1000) / 256
#define TL0_RELOAD_VALUE (65536 - ((INT32U)SYSCLK * TMR0_IRQ_INTERVAL_VALUE) / 1000) % 256
/**------------------------------------------------------------
* @brief This function handles TIM0 interrupt request.
* @param TF0 is cleared by hardware
* @retval : None
--------------------------------------------------------*/
void TIM0_IRQHandler(void) interrupt PI_Order_TIM0
{
__IO INT8U SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = TIMER01_PAGE;
TH0 = TH0_RELOAD_VALUE;
TL0 = TL0_RELOAD_VALUE;
CBTime_g++;
SFRPAGE = SFRPAGE_SAVE;
}
/**-----------------------------------------------
* @brief TimeIntervalOut
* @param
* @note :
* @retval :
-------------------------------------------------*/
BOOLEAN CBTimeDly(INT8U tc, INT16U milli)
{
static __IO INT16U ticks[TC_TOTAL + 1] = {0};
static BOOLEAN time1st_OK = TRUE;
BOOLEAN timeOut_OK = FALSE;
INT8U loops = 0;
if (tc <= TC_TOTAL) {
CB_UsedTC_标志寄存器_g = (INT16U)((INT16U)CB_UsedTC_标志寄存器_g | (INT16U)((INT16U)(1 << tc)));
if (time1st_OK) {
time1st_OK = FALSE;
for (loops = 0; loops <= TC_TOTAL; loops++) {
ticks[loops] = CBTime_Get();
}
}
else {
if ((CBTime_Get() - ticks[tc]) >= milli) {
ticks[tc] = CBTime_Get();
timeOut_OK = TRUE;
}
else {
timeOut_OK = FALSE;
};
}
}
else {
timeOut_OK = FALSE;
}
return timeOut_OK;
}
/**-----------------------------------------------
* @brief CBTime_Get
* @param None
* @note :
* @retval : None
-------------------------------------------------*/
#pragma SAVE
#pragma OT(0)
INT16U CBTime_Get(void)
{
static __IO INT16U tmp = 0;
tmp = CBTime_g;
while (tmp != CBTime_g) {
tmp = CBTime_g;
}
return tmp;
}
#pragma RESTORE
、、、、、、、、、、、、、、、、、、、、、、、、、、
@@@@@@@@@@@@@@@@@@@@@@@
应用 让50个灯以不同的周期闪
//第0通道,10ms
if (CBTimeDly, 0,10) {
//灯1闪
}
//第1通道,17ms
if (CBTimeDly, 1,17) {
//灯2闪
}
//第2通道,8ms
if (CBTimeDly, 2,8) {
//灯3闪
}
,,,,,, |