按照例程所给的定时器中断(1ms)进行改写,定时器2是可以正常输出的但是把参数均换成定时器0以后无法输出,请大家帮忙看看是哪里的问题。
#include "gd32e23x.h"
#include "systick.h"
#include <stdio.h>
#include "main.h"
void delay(int time)
{
while(time--);
return;
}
void gpio_config(void)
{
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_4);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
}
void nvic_config(void)
{
nvic_irq_enable(TIMER0_Channel_IRQn, 0);
timer_interrupt_enable(TIMER0, TIMER_INT_UP);
}
void timer_config(void)
{
/* -----------------------------------------------------------------------
TIMER1 configuration: generate 3 PWM signals with 3 different duty cycles:
TIMER1CLK = SystemCoreClock / 72 = 1MHz
TIMER1 channel 2 duty cycle = 50%
----------------------------------------------------------------------- */
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER0);
timer_deinit(TIMER0);
/* TIMER1 configuration */
timer_initpara.prescaler = 71;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0,&timer_initpara);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
/* auto-reload preload enable */
timer_enable(TIMER0);
}
int main(void)
{ rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
systick_config();
gpio_config();
nvic_config();
timer_config();
while(1)
{
}
}
/*******************************************中断源文件如下***********************************/
uint32_t Timcounter;
uint8_t LedFlag;
void TIMER0_Channel_IRQHandler(void)
{
if(timer_flag_get(TIMER0,TIMER_FLAG_UP)!=RESET)
{
timer_flag_clear(TIMER0,TIMER_FLAG_UP);
Timcounter++;
if(Timcounter>=1)
{
Timcounter=0;
LedFlag^=0x01;
}
if(LedFlag)
{
gpio_bit_set(GPIOB,GPIO_PIN_4);
}else
{
gpio_bit_reset(GPIOB,GPIO_PIN_4);
}
}
}
|