add led
This commit is contained in:
@@ -35,6 +35,7 @@ OF SUCH DAMAGE.
|
||||
#include "gd32e23x_it.h"
|
||||
#include "main.h"
|
||||
#include "systick.h"
|
||||
#include "board_config.h"
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
@@ -98,21 +99,21 @@ void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
void TIMER13_IRQHandler(void)
|
||||
void TIMER16_IRQHandler(void)
|
||||
{
|
||||
if (timer_interrupt_flag_get(TIMER13, TIMER_INT_FLAG_UP) == SET)
|
||||
if (timer_interrupt_flag_get(LED_BLINK_TIMER, TIMER_INT_FLAG_UP) == SET)
|
||||
{
|
||||
timer_interrupt_flag_clear(TIMER13, TIMER_INT_FLAG_UP);
|
||||
timer_interrupt_flag_clear(LED_BLINK_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(GPIOB, GPIO_PIN_1, RESET);
|
||||
timer_autoreload_value_config(TIMER13, 19200);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||
timer_autoreload_value_config(LED_BLINK_TIMER, 19200);
|
||||
} else {
|
||||
//! turn off led & reconfig timer13 period to 1000(100ms)
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_1, SET);
|
||||
timer_autoreload_value_config(TIMER13, 800);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
||||
timer_autoreload_value_config(LED_BLINK_TIMER, 800);
|
||||
}
|
||||
led_status = !led_status;
|
||||
}
|
||||
|
37
src/led.c
Normal file
37
src/led.c
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#include "led.h"
|
||||
|
||||
/*!
|
||||
\brief led blink configuration
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void led_blink_config(void)
|
||||
{
|
||||
rcu_periph_clock_enable(LED_RCU);
|
||||
|
||||
gpio_mode_set(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
|
||||
gpio_output_options_set(LED_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, LED_PIN);
|
||||
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||
|
||||
rcu_periph_clock_enable(LED_BLINK_TIMER_RCU);
|
||||
timer_deinit(LED_BLINK_TIMER);
|
||||
|
||||
timer_parameter_struct timer_initpara;
|
||||
timer_struct_para_init(&timer_initpara);
|
||||
timer_initpara.prescaler =7199;
|
||||
timer_initpara.alignedmode =TIMER_COUNTER_EDGE;
|
||||
timer_initpara.counterdirection =TIMER_COUNTER_UP;
|
||||
timer_initpara.period =9999;
|
||||
timer_initpara.clockdivision =TIMER_CKDIV_DIV1;
|
||||
timer_init(LED_BLINK_TIMER, &timer_initpara);
|
||||
|
||||
timer_auto_reload_shadow_enable(LED_BLINK_TIMER);
|
||||
timer_interrupt_enable(LED_BLINK_TIMER, TIMER_INT_UP);
|
||||
nvic_irq_enable(LED_BLINK_IRQ, 0);
|
||||
timer_enable(LED_BLINK_TIMER);
|
||||
}
|
13
src/led.h
Normal file
13
src/led.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by yelv1 on 24-12-30.
|
||||
//
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
void led_blink_config(void);
|
||||
|
||||
#endif //LED_H
|
@@ -30,34 +30,4 @@ void usart_config(void)
|
||||
gpio_bit_write(GPIOA, GPIO_PIN_4, SET);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief led blink configuration
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void led_blink_config(void)
|
||||
{
|
||||
rcu_periph_clock_enable(RCU_GPIOB);
|
||||
|
||||
gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_1);
|
||||
gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_1, SET);
|
||||
|
||||
rcu_periph_clock_enable(RCU_TIMER13);
|
||||
timer_deinit(RCU_TIMER13);
|
||||
|
||||
timer_parameter_struct timer_initpara;
|
||||
timer_struct_para_init(&timer_initpara);
|
||||
timer_initpara.prescaler =7199;
|
||||
timer_initpara.alignedmode =TIMER_COUNTER_EDGE;
|
||||
timer_initpara.counterdirection =TIMER_COUNTER_UP;
|
||||
timer_initpara.period =999;
|
||||
timer_initpara.clockdivision =TIMER_CKDIV_DIV1;
|
||||
timer_init(TIMER13, &timer_initpara);
|
||||
|
||||
timer_auto_reload_shadow_enable(TIMER13);
|
||||
timer_interrupt_enable(TIMER13, TIMER_INT_UP);
|
||||
nvic_irq_enable(TIMER13_IRQn, 0);
|
||||
timer_enable(TIMER13);
|
||||
}
|
||||
|
Reference in New Issue
Block a user