[demo程序] LED 闪灯

[复制链接]
1237|1
 楼主| holts 发表于 2016-12-3 11:24 | 显示全部楼层 |阅读模式
LED, pi, tc, IO, RTC
直接在官方例程上改的闪灯程序,感觉实再的方法好笨,RTC还没看懂,没办法慢慢来吧。



  1. /***************************************************************************
  2. *
  3. * [url=home.php?mod=space&uid=247401]@brief[/url] providing GPIO demo
  4. *
  5. *******************************************************************************/

  6. #include "common.h"
  7. #include "ics.h"
  8. #include "rtc.h"
  9. #include "uart.h"
  10. #include "gpio.h"
  11. #include "sysinit.h"
  12. #include "start.h"


  13. /******************************************************************************
  14. * Global variables
  15. ******************************************************************************/
  16. volatile uint32_t Switch = 1;
  17.                
  18. /******************************************************************************
  19. * Constants and macros
  20. ******************************************************************************/

  21. /******************************************************************************
  22. * Local types
  23. ******************************************************************************/

  24. /******************************************************************************
  25. * Local function prototypes
  26. ******************************************************************************/

  27. /******************************************************************************
  28. * Local variables
  29. ******************************************************************************/

  30. /******************************************************************************
  31. * Local functions
  32. ******************************************************************************/
  33. int main (void);
  34. void RTC_Task(void);
  35. /******************************************************************************
  36. * Global functions
  37. ******************************************************************************/

  38. /********************************************************************/
  39. int main (void)
  40. {
  41.     /* Perform processor initialization */
  42.     sysinit();
  43.     cpu_identify();
  44.         

  45.         
  46.     RTC_ConfigType  sRTCConfig;
  47.     RTC_ConfigType  *pRTCConfig = &sRTCConfig;  

  48.     printf("\nRunning the GPIO_demo project.\n");

  49.     /* configure RTC to 1Hz interrupt frequency */
  50.     pRTCConfig->u16ModuloValue = 9;                                      
  51.     pRTCConfig->bInterruptEn   = RTC_INTERRUPT_ENABLE;     /* enable interrupt */
  52.     pRTCConfig->bClockSource   = RTC_CLKSRC_1KHZ;          /*clock source is 1khz*/
  53.     pRTCConfig->bClockPresaler = RTC_CLK_PRESCALER_100;    /*prescaler is 100*/
  54.    
  55.     RTC_SetCallback(RTC_Task);
  56.     RTC_Init(pRTCConfig);

  57.     /* way 1. GPIO initialize by multiple pin mask */
  58.     GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
  59.     /* way 2. GPIO initialize single pin name */
  60.     /* GPIO_PinInit(GPIO_PTE7, GPIO_PinOutput); */

  61.     while (1)
  62.                 {
  63.                
  64.                 };
  65. }

  66. /*****************************************************************************//*!
  67. *
  68. * [url=home.php?mod=space&uid=247401]@brief[/url] callback routine of RTC driver which does what you want to do at
  69. *        every RTC period.
  70. *        
  71. * @param  none
  72. *
  73. * [url=home.php?mod=space&uid=266161]@return[/url] none
  74. *
  75. * [url=home.php?mod=space&uid=72445]@[/url] Pass/ Fail criteria: none
  76. *****************************************************************************/

  77. void RTC_Task(void)
  78. {
  79.          
  80.     /* toggle LED1 */
  81.     /* way 1. toggle LED1 by multiple pin mask */
  82.     /* GPIO_Toggle(GPIOB, GPIO_PTE7_MASK); */
  83.    
  84.     /* way2. toggle LED by single pin name */
  85.     /* GPIO_PinToggle(GPIO_PTE7); */
  86.         
  87.           if (Switch == 0) GPIO_PinClear(GPIO_PTE7);
  88.           if (Switch == 1) GPIO_PinSet(GPIO_PTE7);

  89.           Switch ++;
  90.           if (Switch == 2) {Switch = 0;}
  91. }
  92. /********************************************************************/


ppjxdz 发表于 2016-12-14 21:30 | 显示全部楼层
xdcvjklzx.zxcv,zxc,zx
您需要登录后才可以回帖 登录 | 注册

本版积分规则

45

主题

769

帖子

4

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