基于GD32 Hello-M3 MDK-ARM 4.73
代码如下:
/**********************************************************
* @brief 设置nus中断
*
* @param nus 多少us后发生中断
*
* @return NONE
*********************************************************/
void Set_SysTick_Nus_it(u32 nus)
{
SysTick->CTRL &= ~B_U32_BIT0 ; //禁止
SysTick->CTRL &= ~B_U32_BIT2 ; // 选择外部时钟
SysTick->LOAD = nus*9-12 ; //-12是因为有12个时钟周期的延时
SysTick->VAL = 0 ;
SysTick->CTRL |= (B_U32_BIT0 + B_U32_BIT1) ; //使能定时+中断
}
LED_FIFO.rar
(138.38 KB)
https://bbs.21ic.com/forum.php?mod=attachment&aid=MjM3MjQ0fDI4NzA1NjllNDI0NWQxNTU0YzA2N2RmOTBjYjIyYzIwfDE3MzE0NjMxNzY%3D&request=yes&_f=.rar
https://bbs.21ic.com/forum.php?mod=attachment&aid=MjM3MjQ0fDI4NzA1NjllNDI0NWQxNTU0YzA2N2RmOTBjYjIyYzIwfDE3MzE0NjMxNzY%3D&request=yes&_f=.rarattach://237244.rarhttps://bbs.21ic.com/forum.php?mod=attachment&aid=MjM3MjQ0fDI4NzA1NjllNDI0NWQxNTU0YzA2N2RmOTBjYjIyYzIwfDE3MzE0NjMxNzY%3D&request=yes&_f=.rar
void led_fifo_app(void)
{
if(++systick_int_times >= 200)
{
systick_int_times = 0 ;
if(led_fifo_dir == 0)
{
if(++led_fifo_dutycycle >= 200)
{
led_fifo_dir = 255 ;
}
}
else
{
if(--led_fifo_dutycycle == 0)
{
led_fifo_dir = 0 ;
}
}
led_fifo_duty_value = led_fifo_dutycycle ; // 改变占空比
}
if(led_fifo_duty_value > 0)
{
led_fifo_duty_value-- ;
PAOUT(8) = 0 ; // 打开 LED
PDOUT(2) = 0 ;
}
else
{
PAOUT(8) = 1 ; // 关闭 LED
PDOUT(2) = 1 ;
}
} 完整工程
|