[demo程序] NV32F101 RTC定时中断程序示例

[复制链接]
 楼主| Bruing 发表于 2018-8-28 18:33 | 显示全部楼层 |阅读模式
  1. /**********************************************************************
  2. *
  3. * 实验名称:RTC定时中断
  4. * 实验平台:NV32开发板
  5. * 板载芯片:NV32F101FL64E
  6. * 实验效果:RTC时钟源选择LPOCLK-1KHZ,板载LED闪烁        
  7. *
  8. ************************************************************************/

  9. #include "common.h"
  10. #include "rtc.h"
  11. #include "uart.h"
  12. #include "sysinit.h"

  13. int main (void);
  14. void RTC_Task(void);


  15. uint8_t i=0;
  16. /********************************************************************/
  17. int main (void)
  18. {
  19.     uint8_t u8Ch;
  20.     uint16_t u16ModuloValue;
  21.     RTC_ConfigType  sRTCConfig;
  22.     RTC_ConfigType  *pRTC_Config=&sRTCConfig;


  23.     /* 系统初始化 */
  24.     sysinit();

  25.     printf("\nRunning the RTC_demo project.\r\n");
  26.     LED0_Init();  
  27.     LED1_Init();
  28.     LED2_Init();
  29.    
  30.     /* 配置RTC的中断频率为1HZ */
  31.     u16ModuloValue = 0x09;//模值为10
  32.     pRTC_Config->u16ModuloValue = u16ModuloValue;//装载值到模数寄存器中
  33.     pRTC_Config->bInterruptEn   = RTC_INTERRUPT_ENABLE;    //使能中断
  34.     pRTC_Config->bClockSource   = RTC_CLKSRC_1KHZ;         //选取时钟源为1KHZ
  35.     pRTC_Config->bClockPresaler = RTC_CLK_PRESCALER_100;   //分频数为100
  36.     RTC_SetCallback(RTC_Task);
  37.     RTC_Init(pRTC_Config);
  38.        
  39.     while(1)
  40.     {
  41.        u8Ch = UART_GetChar(TERM_PORT);
  42.        UART_PutChar(TERM_PORT, u8Ch);
  43.     }
  44. }

  45. /*****************************************************************************//*!
  46. *
  47. * @RTC中断任务函数,闪烁LED,三个LED轮点
  48. *      
  49. * @无返回
  50. *
  51. *****************************************************************************/

  52. void RTC_Task(void)
  53. {       
  54.         i=i+1;

  55.         if(i%3==2)
  56.         {
  57.                 LED0_On();  
  58.                 LED1_Off();
  59.                 LED2_Off();
  60.         }
  61.         else if(i%3==1)
  62.         {
  63.                 LED0_Off();
  64.                 LED1_On();
  65.                 LED2_Off();
  66.         }
  67. else
  68.         {
  69.                 LED0_Off();
  70.                 LED1_Off();
  71.                 LED2_On();  
  72.         }

  73. }
  74. /********************************************************************/


您需要登录后才可以回帖 登录 | 注册

本版积分规则

71

主题

308

帖子

1

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

71

主题

308

帖子

1

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