原帖由
ukonline2000
发自:dev.eefocus.com
------------------------------------------------------------------------------------------------------------------------------------------
ChipKIT Uno32上实现RTCC实时时钟功能,Uno32的PIC32是自带RTC功能的,这个要比arduino实在一点,Uno32板上也预留了RTC的功能,就是没焊实时时钟的 32.768Khz 晶体 ,正好手头的项目中很多这个晶体,于是拿到Uno32就直接焊上了(有点冲动,呵呵)! 言归正传,测试程序源码如下:
#include <RTCC.h>
void setup() { Serial.begin(9600);
// Initialize the RTCC module RTCC.begin();
// Set the time to something sensible RTCC.hours(9); RTCC.minutes(59); RTCC.seconds(0); RTCC.year(11); RTCC.month(05); RTCC.day(9);
// Set the alarm to trigger every second RTCC.alarmMask(AL_SECOND); RTCC.chimeEnable(); RTCC.alarmEnable();
// Attach our routine to send the time through the serial port RTCC.attachInterrupt(&outputTime); }
void loop() { }
void outputTime() { char time[50];
// Format the time and print it. sprintf(time,"%02d/%02d/%02d %02d:%02d:%02d\n", RTCC.day(), RTCC.month(), RTCC.year(), RTCC.hours(), RTCC.minutes(), RTCC.seconds() ); Serial.print(time); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |