change the timer of LED to TIMER5(basic timer)

This commit is contained in:
yelvlab 2024-09-25 11:00:47 +08:00
parent 4252d59581
commit 212ffff06b
3 changed files with 15 additions and 16 deletions

View File

@ -10,8 +10,9 @@
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_9
#define LED_RCU RCU_GPIOA
#define LED_TIMER TIMER16
#define LED_IRQ TIMER16_IRQn
#define LED_TIMER_RCU RCU_TIMER5
#define LED_TIMER TIMER5
#define LED_IRQ TIMER5_IRQn
#define USART_RCU RCU_USART0
#define USART_GPIO_RCU RCU_GPIOA

View File

@ -98,20 +98,18 @@ void SysTick_Handler(void)
{
}
void TIMER16_IRQHandler(void) {
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP) == SET)
void TIMER5_IRQHandler(void) {
if (timer_interrupt_flag_get(LED_TIMER, TIMER_INT_FLAG_UP) == SET)
{
timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_UP);
timer_interrupt_flag_clear(LED_TIMER, TIMER_INT_FLAG_UP);
static uint8_t led_status = 0;
if (led_status)
{
//! turn on led & reconfig timer13 period to 19000(1900ms)
gpio_bit_write(GPIOA, GPIO_PIN_9, RESET);
timer_autoreload_value_config(TIMER16, 19200);
gpio_bit_write(LED_PORT, LED_PIN, RESET);
timer_autoreload_value_config(LED_TIMER, 19200);
} else {
//! turn off led & reconfig timer13 period to 1000(100ms)
gpio_bit_write(GPIOA, GPIO_PIN_9, SET);
timer_autoreload_value_config(TIMER16, 800);
gpio_bit_write(LED_PORT, LED_PIN, SET);
timer_autoreload_value_config(LED_TIMER, 800);
}
led_status = !led_status;
}

View File

@ -6,8 +6,6 @@
#include "gd32e23x.h"
#include "systick.h"
uint8_t speed_pwm = 30; //bldc default pwm is 30
void led_config(void)
{
rcu_periph_clock_enable(LED_RCU);
@ -16,8 +14,8 @@ void led_config(void)
gpio_output_options_set(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_PIN);
gpio_bit_write(LED_PORT, LED_PIN, SET);
rcu_periph_clock_enable(RCU_TIMER13);
timer_deinit(RCU_TIMER13);
rcu_periph_clock_enable(LED_TIMER_RCU);
timer_deinit(LED_TIMER);
timer_parameter_struct timer_initpara;
timer_struct_para_init(&timer_initpara);
@ -30,8 +28,10 @@ void led_config(void)
timer_auto_reload_shadow_enable(LED_TIMER);
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
nvic_irq_enable(LED_IRQ, 3);
timer_enable(LED_TIMER);
nvic_irq_enable(LED_IRQ, 0);
}
void usart_config(void)