[PIC®/AVR®/dsPIC®产品] 【CuriosityNano测评报告】+定时器中断LED闪烁

[复制链接]
1306|10
 楼主| dql2015 发表于 2021-3-27 20:09 | 显示全部楼层 |阅读模式

定时器是MCU常用功能之一,本次配置一个1ms定时中断。
系统时钟设置16MHz,便于后面分频:

开启全局中断:

16分频,定时器时钟为1MHz,向下计数模式,开启中断:

主函数设置:


主函数首先设置定时器初值,然后注册溢出中断函数,由于定时器时钟配置为1MHz,向下计数模式,因此从初值999减到0即为1ms。
在定时器中断函数中清除中断标志,重新设置初值。

  1. #include "mcc_generated_files/mcc.h"
  2. /*
  3.     Main application
  4. */
  5. int i=0;
  6. void tca0_cb(void)
  7. {  
  8.     TCA0_ClearOverflowInterruptFlag();
  9.     TCA0_WriteTimer(999);
  10.     i++;
  11.     if(i==1000)
  12.     {
  13.         i=0;
  14.         LED_Toggle();
  15.     }
  16. }
  17. int main(void)
  18. {
  19.     /* Initializes MCU, drivers and middleware */
  20.     SYSTEM_Initialize();
  21.     /* Replace with your application code */;                                       
  22.     LED_SetDigitalOutput();
  23.     LED_SetHigh();
  24.         TCA0_WriteTimer(999);
  25.     TCA0_SetOVFIsrCallback(tca0_cb);
  26.     while (1)
  27.     {        
  28.         DELAY_milliseconds(1000);     
  29.     }
  30. }
  31. /**
  32.     End of File
  33. */


实验现象:

测试工程源码:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
typeof 发表于 2021-4-6 20:29 | 显示全部楼层
入门的好资料呢。   
kkzz 发表于 2021-4-6 20:29 | 显示全部楼层
CuriosityNano的最大频率是多少呢   
htmlme 发表于 2021-4-6 20:29 | 显示全部楼层
学习一下定时器的功能。   
pklong 发表于 2021-4-6 20:29 | 显示全部楼层
支持几个定时器呢   
touser 发表于 2021-4-6 20:29 | 显示全部楼层
谢谢楼主分享的CuriosityNano资料。  
uytyu 发表于 2021-4-6 20:29 | 显示全部楼层
以后有机会申请CuriosityNano试试看。  
iyoum 发表于 2021-4-6 20:30 | 显示全部楼层
1ms的闪烁是不是太快了。  
jkl21 发表于 2021-4-6 20:30 | 显示全部楼层
谢谢楼主分享的资料。  
wwppd 发表于 2021-4-6 20:30 | 显示全部楼层
定时器中断支持几个?
usysm 发表于 2021-4-6 20:30 | 显示全部楼层
         
您需要登录后才可以回帖 登录 | 注册

本版积分规则

104

主题

384

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部