芯片破解定时器中断计数
芯片破解定时器初始化和中断服务程序
- uint32_t volatile time_base_ms; //volatile关键字防?编译器优化
- void timer_init(void)
- {
- //初始化定时器
- time_base_ms = 0;
- }
- // 定时器中断服务程序
- void Timer_hander(void) interrupt 19
- {
- ++time_base_ms;
- }
复制代码
- uint32_t ret;
- ret = time_base_ms; // 读取计数,该过程可能中断
- if(ret != time_base_ms){ // 读取计数,该过程可能中断;如果不相等,说明两
- 个过程有?个发?过中断
- ret = time_base_ms; // 读取计数,该过程没有中断
- }
- return ret;
- }