下面是一段使用滴答定时器交替闪烁LED灯的代码:
- #include "CH58x_common.h"
- /*********************************************************************
- * @fn main
- * [url=home.php?mod=space&uid=247401]@brief[/url] 主函数
- * [url=home.php?mod=space&uid=266161]@return[/url] none
- */
- uint32_t cnt=0;
- int main() {
- SetSysClock(CLK_SOURCE_PLL_60MHz);
- SysTick_Config(60000000);//设定嘀嗒时间
- GPIOB_SetBits(GPIO_Pin_15);
- GPIOB_ModeCfg(GPIO_Pin_15, GPIO_ModeOut_PP_20mA); // 配置推挽输出
- while(1){
- if (cnt%2==0)
- GPIOB_SetBits(GPIO_Pin_15);
- else
- GPIOB_ResetBits(GPIO_Pin_15);
- }
- }
- /*********************************************************************
- * @fn SysTick_Handler
- * @brief SysTick中断函数
- * @return none
- */
- __attribute__((interrupt("WCH-Interrupt-fast")))
- __attribute__((section(".highcode")))
- void SysTick_Handler()
- {
- cnt++;
- SysTick->SR=0;//清除中断标志
- }
|