上一贴我们讨论了时钟与硬件定时器的使用方法,本贴讨论外设里面的Timer框架的使用
上一贴内容访问 https://bbs.21ic.com/icview-3426584-1-1.html
Generate,生成了Timer软件框架,注意这里是采用的类似面向对象的方式的结构体。
- unsigned int time_num=0;
- unsigned int time_**=0;
- void time0_handle(void)
- {
- time_num++;
- if(time_num>=50)
- {
- time_num=0;
- time_**=1;
- }
- }
- int main(void)
- {
- SYSTEM_Initialize();
- Timer0.TimeoutCallbackRegister(time0_handle);
- Enable_global_interrupt();
- while(1)
- {
- if(SW_GetValue())
- {
- if(time_**==1)
- {
- YELLOW_LED_Toggle();
- time_**=0;
- }
- //DELAY_milliseconds(500);
- }
- else
- {
- YELLOW_LED_SetHigh();
- }
- }
- }
编写代码,编译并运行,达到想要效果。
根据个人体验,还是直接使用硬件定时器比较好理解。
|