//*********************************************************************************** // Ver 1.0 // 2020.03.05 1、新建文件。 //*********************************************************************************** #include "config.h" volatile TASK_TYPE Timers[TASK_ID_END]; volatile TASK_TYPE _Reg; void DELAY_Us(INT32U tUs) { while (tUs--) { NOP(); } } void DELAY_Ms(INT32U tMs) { INT32U tUs; //WDT_Clr(); while (tMs--) //使用定时器延时,误差 1ms { tUs = DLY_1mSCycle; while (tUs--) { NOP(); } } } void TASK_Init(void) { //定时器初始化,1ms中断一次 TASK_InitTasks(); TASK_TickInit(); TASK_TimerStart(TMR1, 10000); //定时器1定时10S TASK_TimerStart(TMR2, 12000); //定时器1定时12S IRQ_Enable(); } INT8U TASK_TimerState(INT8U Tx) { if(Timers[Tx] == 0) { return(TASK_STA_IDLE); //定时器停止状态 } else if(Timers[Tx] == TASK_TICK_MAX) { return(TASK_STA_SUSPEND); //定时器挂起状态 } return(TASK_STA_RUN); //定时器运行状态 } //定时器0中断 void SysTick_Handler(void) { TASK_Timers(); //切换任务 UART_IdleCnt(); //UART0超时计数 //TMR_ClrIntFlag(TMR0); //清除中断标志 #ifdef LED_SEG_MODE LED_SegRefresh(); //刷新显示数据 #endif } void WDT_IRQHandler(void) { WDT_Clr(); } //任务示例 /* TASK_TYPE TASK_LedSeg(void) { TASK_Start(); LED_SegRefresh(); //刷新显示数据 TASK_WaitX(2); //等待2ms TASK_End(); } */ #if 0 //半主机 #pragma import(__use_no_semihosting) void _sys_exit(int x) { x = x; } struct __FILE { int handle; /* Whatever you require here. If the only file you are using is */ /* standard output using printf() for debugging, no file handling */ /* is required. */ }; /* FILE is typedef’ d in stdio.h. */ FILE __stdout; #endif