如何将Arduino与DS1307同步

时间:2013-12-28 07:38:45

标签: c arduino arduino-ide

我使用的是Arduino和DS1307。我从RTC获得的时间没有问题,但是当我尝试应用setSyncProvider调用时,我得到一些错误,这些错误暗示我的库中的ds1307.h文件。附上是我的代码和错误。这些错误,我不太确定它们是什么和意思。我是否需要进入记事本++并将66-68行换成某些东西或改变.h?有没有人知道?非常感谢您的帮助。顺便说一句,代码是来自Arduino Cookbook,所以我知道它的工作原理,它只是在那个.h文件中的东西......我想

#include <Time.h>
#include <Wire.h>
#include <DS1307.h> // a basic DS1307 library that returns time as a time_t

void setup() {
    Serial.begin(9600);
    setSyncProvider(RTC.get); // the function to get the time from the RTC

    if(timeStatus() != timeSet)
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");
}

void loop() {
    if(Serial.available()) {
        time_t t = processSyncMessage();

        if(t > 0) {
            RTC.set(t); // set the RTC and the system time to the received value
            setTime(t);
        }
    }

    digitalClockDisplay();
    delay(1000);
}

void digitalClockDisplay() {
    // digital clock display of the time
    Serial.print(hour());
    printDigits(minute());
    printDigits(second());
    Serial.print(" ");
    Serial.print(day());
    Serial.print(" ");
    Serial.print(month());
    Serial.print(" ");
    Serial.print(year());
    Serial.println();
}

// utility function for digital clock display: prints preceding colon and
// leading 0.
//

void printDigits(int digits) {
    Serial.print(":");

    if(digits < 10)
        Serial.print('0');

    Serial.print(digits);
}
/* code to process time sync messages from the serial port */

#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by Unix time_t
#define TIME_HEADER 'T' // Header tag for serial time sync message

time_t processSyncMessage() {

    while(Serial.available() >= TIME_MSG_LEN ) {
        char c = Serial.read() ;
        Serial.print(c);

        if( c == TIME_HEADER ) {
            time_t pctime = 0;

            for(int i=0; i < TIME_MSG_LEN -1; i++) {
                c = Serial.read();

                if( c >= '0' && c <= '9') {
                    pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
                }
            }

            return pctime;
        }
    }

    return 0;
}

我的错误........................................

sketch_dec27d.ino: In function 'void setup()':
sketch_dec27d:14: error: no matches converting function 'get' to type 'time_t (*)()'
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:66: error: candidates are: void DS1307::get(int*, boolean)
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:67: error:                 int DS1307::get(int, boolean)
sketch_dec27d.ino: In function 'void loop()':
sketch_dec27d:27: error: no matching function for call to 'DS1307::set(time_t&)'
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:68: note: candidates are: void DS1307::set(int, int)

0 个答案:

没有答案