PuG
/
RTC
bubu
main.cpp
- Committer:
- Peeraya
- Date:
- 2015-11-15
- Revision:
- 0:c368b419bdf1
File content as of revision 0:c368b419bdf1:
// show how the DS1307 class works #include "ds1307.h" #include "mbed.h" //Serial pc(USBTX, USBRX); // tx, rx for debug and usb pc comunications DS1307 my1307(A4,A5); // start DS1307 class and give it pins for connections of the DS1307 device int sec = 0; int min = 0; int hours = 0; int day = 0; int date = 0; int month = 0; int year = 0; void test_rw(int test) { if (test == 0) printf("Last R/W operaion passed!\n\r"); else printf("Last R/W operation failed!\n\r"); } int main() { while(1){ int junk = 0; sec = 24; // 24 seconds min = 13; // 13 min hours = 13; // 1 pm day = 4; // wednesday date = 20; // June 20 month = 6; year = 12; // 2012 // set time to these values on the ds1307 connected device test_rw(my1307.settime( sec, min, hours, day, date, month, year)); printf("seconds set are %.2d \n\r",sec); printf("min set are %.2d \n\r",min); printf("hour set are %.2d \n\r",hours); printf("day set are %.2d \n\r",day); printf("date set are %.2d \n\r",date); printf("month set are %.2d \n\r",month); printf("year set are %.2d \n\r",year); wait(3); // now read the time of the DS1307 device and see what time it is // note that because of the 3 second wait this time should be 3 seconds past what it was set to earlier test_rw(my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year)); printf("seconds read are %.2d \n\r",sec); printf("min read are %.2d \n\r",min); printf("hour read are %.2d \n\r",hours); printf("day read are %.2d \n\r",day); printf("date read are %.2d \n\r",date); printf("month read are %.2d \n\r",month); printf("year read are %.2d \n\r",year); junk = 0x39; // just a junk value do read and write test to DS1307 ram test_rw(my1307.write( 0x20, junk)); // this should write the value of junk to register 0x20 (a ram location) in the ds1307. printf("Value written to register 0x20 %.2x \n\r",junk); junk = 0; // clear junk to show that when the register is read from the correct value is obtained test_rw(my1307.read( 0x20, &junk)); // this should read register 0x20 printf("Value read from register 0x20 %.2x \n\r",junk); } }