Both_Way_Comm_SY8833/TP3310_Demo.si4project/Backup/sys_tim(2098).c

248 lines
5.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @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;
uint8_t cnt_sys_tim_10ms = 0;
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;
bit F_sys_tim_10ms = 0;
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;
#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----------------------------------------
cnt_sys_tim_5ms++;
if(cnt_sys_tim_5ms >= 5)
{
cnt_sys_tim_5ms = 0;
F_sys_tim_5ms = 1;
}
//---------------10ms----------------------------------------
cnt_sys_tim_10ms++;
if(cnt_sys_tim_10ms >= 10)
{
cnt_sys_tim_10ms = 0;
F_sys_tim_10ms = 1;
}
//---------------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;
P10 = !P10; //<2F><><EFBFBD><EFBFBD>Timer0
//-----------------250ms-------------------------
cnt_sys_tim_1s++;
if(cnt_sys_tim_1s >= 4)
{
cnt_sys_tim_1s = 0;
F_sys_tim_1s = 1;
}
}
}
/*
*******************************************************************************
* void Delay10ms(void) //@11.0592MHz
*
* Description : 10ms<6D><73><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
#if 0
void Delay10ms(void) //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
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;
//LED_Drv();
F_sys_tim0_tick = 1;
}
/*
*******************************************************************************
* void Sys_Tim0_Init(void)
*
* Description : TImer0 Mode1 16bit timer Initialization
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
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
}
#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
#ifdef DISPLAY_LED_188
LED_188_Drive(g_188_Num); //188<38><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
#endif
// P10 = !P10; //<2F><><EFBFBD><EFBFBD>Timer0
F_sys_tim1_tick = 1;
}
/*
*******************************************************************************
* void Sys_Tim1_Init(void)
*
* Description : TImer1 Mode1 16bit timer Initialization
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
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