52 lines
824 B
C
52 lines
824 B
C
/*
|
|
* timer.c
|
|
*
|
|
* Created on: May 16, 2025
|
|
* Author: cc
|
|
*/
|
|
#include "timer.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void TIMER0_Init(void)
|
|
{
|
|
TMR0_DeInit();
|
|
TMR0_TimerInit(SystemCoreClock / 10000);
|
|
TMR0_ITCfg(RB_TMR_IF_CYC_END, ENABLE);
|
|
NVIC_EnableIRQ(TIM0_IRQn);
|
|
TMR0_Enable();
|
|
}
|
|
|
|
volatile uint32_t Time0_100us = 0;
|
|
volatile uint32_t Time0_1ms = 0;
|
|
|
|
void __attribute__((interrupt("WCH-Interrupt-fast"))) TIM0_IRQHandler()
|
|
{
|
|
static uint8_t NUM_1 = 0;
|
|
|
|
TMR0_ClearITFlag(RB_TMR_IF_CYC_END);
|
|
|
|
Time0_100us++;
|
|
NUM_1++;
|
|
|
|
if(NUM_1 >= 10){
|
|
NUM_1 = 0;
|
|
Time0_1ms++;
|
|
}
|
|
}
|
|
|
|
void Timer0_Task(void)
|
|
{
|
|
static uint32_t timer0_tick = 0;
|
|
|
|
if(Time0_1ms - timer0_tick >= 1000 ){
|
|
timer0_tick = Time0_1ms;
|
|
|
|
printf("Run:%d ..",timer0_tick);
|
|
}
|
|
}
|
|
|
|
|