/* ****************************************************************************** * * @file sys_tim.c * @brief Timer module * * * @version 1.0 * @date 2022/09/05 15:00:40 * @author Alex Xu * * Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd. * All Rights Reserved * * History: * Revision Date Author Desc * 1.0.0 2022/09/05 Alex build this file ******************************************************************************/ /*_____ I N C L U D E S ____________________________________________________*/ #include "sys_tim.h" #include "vox_module.h" #include "system.h" #include "charger_module.h" #include "led.h" /******************************************************************************\ Macro definitions \******************************************************************************/ /******************************************************************************\ Variables definitions \******************************************************************************/ //uint8_t cnt_sys_tim_5ms = 0; #if 0 uint8_t cnt_sys_tim_500ms = 0; #endif uint8_t cnt_sys_tim_250ms = 0; uint8_t cnt_sys_tim_100ms = 0; uint8_t cnt_sys_tim_1s = 0; //bit F_sys_tim_5ms = 0; #ifdef LED_DISPLAY uint8_t cnt_sys_tim_10ms = 0; bit F_sys_tim_10ms = 0; #endif #if 0 bit F_sys_tim_500ms = 0; #endif bit F_sys_tim_250ms = 0; bit F_sys_tim_100ms = 0; bit F_sys_tim_1s = 0; uint8_t F_sys_tim0_tick = 0; //uint8_t cnt_sys_tim0_5ms = 0; #if TIMER1_ENABLE bit F_sys_tim1_tick = 0; #endif /******************************************************************************\ Functions definitions \******************************************************************************/ /* ******************************************************************************* * void Sys_Tim_Handler(void ) * * Description : Timer Handle * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ void Sys_Tim_Handler(void) { if(F_sys_tim0_tick == 0) return; F_sys_tim0_tick = 0; //system tick //---------------5ms---------------------------------------- #if 0 cnt_sys_tim_5ms++; if(cnt_sys_tim_5ms >= 5) { cnt_sys_tim_5ms = 0; F_sys_tim_5ms = 1; } #endif #ifdef LED_DISPLAY //---------------10ms---------------------------------------- cnt_sys_tim_10ms++; if(cnt_sys_tim_10ms >= 10) { cnt_sys_tim_10ms = 0; F_sys_tim_10ms = 1; } #endif //---------------100ms---------------------------------------- cnt_sys_tim_100ms++; if(cnt_sys_tim_100ms >= 100) { cnt_sys_tim_100ms = 0; F_sys_tim_100ms = 1; } //------------------------------------------------- cnt_sys_tim_250ms++; if(cnt_sys_tim_250ms>=250) { cnt_sys_tim_250ms = 0; F_sys_tim_250ms = 1; #if 0 //-----------------500ms------------------------- cnt_sys_tim_500ms++; if(cnt_sys_tim_500ms >= 2) { cnt_sys_tim_500ms = 0; F_sys_tim_500ms = 1; } #endif //-----------------1s------------------------- cnt_sys_tim_1s++; if(cnt_sys_tim_1s >= 4) { cnt_sys_tim_1s = 0; F_sys_tim_1s = 1; } } } /* ******************************************************************************* * void Delay200ms(void) //@11.0592MHz * * Description : 200ms软定时函数 * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ #if 0 void Delay200ms(void) //@11.0592MHz { unsigned char i, j, k; //_nop_(); //_nop_(); i = 9; j = 104; k = 139; do { do { while (--k); } while (--j); } while (--i); } #endif /** * @brief This function handles sys_tim Handler. * @param None * @retval None * 1ms */ void tim0_Interrupt(void) interrupt Interrupt_Vector_TF0 //interrupt address is 0x000B { //1ms TH0 += C_TIM0_Reload >> 8; TL0 += C_TIM0_Reload & 0xFF; F_sys_tim0_tick = 1; } /* ******************************************************************************* * void Sys_Tim0_Init(void) * * Description : TImer0 Mode1 16bit timer Initialization * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ #if 0 void Sys_Tim0_Init(void) { TMOD &= 0xF0; TMOD |= 0x01; //mode 1, 16bit timer TH0 = C_TIM0_Reload >> 8; TL0 = C_TIM0_Reload & 0xFF; ET0 = 1; //enable time0 interrupt TR0 = 1; //time0 run } #endif #if TIMER1_ENABLE /** * @brief This function handles sys_tim Handler. * @param None * @retval None * 1ms */ void tim1_Interrupt(void) interrupt Interrupt_Vector_TF1//interrupt address is 0x000B { //1ms TF1 = 0; TH1 += C_TIM1_Reload >> 8; TL1 += C_TIM1_Reload & 0xFF; #ifdef BREATHING_LIGHT /*todo*/ if ( Breathing_Light_On ) { LED_Breathing_Light(); } #endif #if DISPLAY_6PIN_188 Display_Scan_6Pin_188(); #endif #if DISPLAY_5PIN_188 LED_188_Drive(g_188_Num); //188数码管显示 #endif F_sys_tim1_tick = 1; } /* ******************************************************************************* * void Sys_Tim1_Init(void) * * Description : TImer1 Mode1 16bit timer Initialization * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ #if 0 void Sys_Tim1_Init(void) { TMOD &= 0x0F; TMOD |= 0x10; //mode 1, 16bit timer TH1 = C_TIM1_Reload >> 8; TL1 = C_TIM1_Reload & 0xFF; ET1 = 1; //enable time1 interrupt TR1 = 1; //time1 run } #endif #endif