论坛» 嵌入式开发» MCU

ChipKIT Uno32上实现RTCC实时时钟功能!

菜鸟
2012-05-23 17:08 1楼
团购的ChipKIT Uno32板子到手,板子做工没得说,很精致!再次感谢这次活动主办方 http://www.eeboard.com/bbs/article_1246_325461.html,给了这么实惠的价格!
ChipKIT Uno32上实现RTCC实时时钟功能,Uno32的PIC32是自带RTC功能的,这个要比arduino实在一点,Uno32板上也预留了RTC的功能,就是没焊实时时钟的 32.768Khz 晶体 ,正好手头的项目中很多这个晶体,于是拿到Uno32就直接焊上了(有点冲动,呵呵)!




言归正传,测试程序源码如下:
  1. #include
  2. void setup()
  3. {
  4. Serial.begin(9600);
  5. // Initialize the RTCC module
  6. RTCC.begin();
  7. // Set the time to something sensible
  8. RTCC.hours(9);
  9. RTCC.minutes(59);
  10. RTCC.seconds(0);
  11. RTCC.year(11);
  12. RTCC.month(05);
  13. RTCC.day(9);
  14. // Set the alarm to trigger every second
  15. RTCC.alarmMask(AL_SECOND);
  16. RTCC.chimeEnable();
  17. RTCC.alarmEnable();
  18. // Attach our routine to send the time through the serial port
  19. RTCC.attachInterrupt(&outputTime);
  20. }
  21. void loop()
  22. {
  23. }
  24. void outputTime()
  25. {
  26. char time[50];
  27. // Format the time and print it.
  28. sprintf(time,"%02d/%02d/%02d %02d:%02d:%02d\n",
  29. RTCC.day(),
  30. RTCC.month(),
  31. RTCC.year(),
  32. RTCC.hours(),
  33. RTCC.minutes(),
  34. RTCC.seconds() );
  35. Serial.print(time);
  36. }
共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]