
A simple serial test program for the ISL1208 library.
main.cpp@4:c003cef32315, 2013-11-12 (annotated)
- Committer:
- neilt6
- Date:
- Tue Nov 12 17:17:07 2013 +0000
- Revision:
- 4:c003cef32315
- Parent:
- 1:e983c454f8be
Updated to demonstrate setting the oscillator mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:48943967d624 | 1 | #include "mbed.h" |
neilt6 | 0:48943967d624 | 2 | #include "ISL1208.h" |
neilt6 | 0:48943967d624 | 3 | |
neilt6 | 0:48943967d624 | 4 | ISL1208 rtc(p28, p27); |
neilt6 | 0:48943967d624 | 5 | |
neilt6 | 0:48943967d624 | 6 | int main() |
neilt6 | 0:48943967d624 | 7 | { |
neilt6 | 0:48943967d624 | 8 | //Try to open the ISL1208 |
neilt6 | 4:c003cef32315 | 9 | if (rtc.open()) { |
neilt6 | 0:48943967d624 | 10 | printf("Device detected!\n"); |
neilt6 | 0:48943967d624 | 11 | |
neilt6 | 4:c003cef32315 | 12 | //Configure the oscillator for a 32.768kHz crystal |
neilt6 | 4:c003cef32315 | 13 | rtc.oscillatorMode(ISL1208::OSCILLATOR_CRYSTAL); |
neilt6 | 4:c003cef32315 | 14 | |
neilt6 | 0:48943967d624 | 15 | //Check if we need to reset the time |
neilt6 | 0:48943967d624 | 16 | if (rtc.powerFailed()) { |
neilt6 | 0:48943967d624 | 17 | //The time has been lost due to a power complete power failure |
neilt6 | 0:48943967d624 | 18 | printf("Device has lost power! Resetting time...\n"); |
neilt6 | 0:48943967d624 | 19 | |
neilt6 | 0:48943967d624 | 20 | //Set RTC time to Wed, 28 Oct 2009 11:35:37 |
neilt6 | 0:48943967d624 | 21 | rtc.time(1256729737); |
neilt6 | 0:48943967d624 | 22 | } |
neilt6 | 0:48943967d624 | 23 | |
neilt6 | 0:48943967d624 | 24 | while(1) { |
neilt6 | 0:48943967d624 | 25 | //Get the current time |
neilt6 | 0:48943967d624 | 26 | time_t seconds = rtc.time(); |
neilt6 | 0:48943967d624 | 27 | |
neilt6 | 0:48943967d624 | 28 | //Print the time in various formats |
neilt6 | 0:48943967d624 | 29 | printf("\nTime as seconds since January 1, 1970 = %d\n", seconds); |
neilt6 | 0:48943967d624 | 30 | printf("Time as a basic string = %s", ctime(&seconds)); |
neilt6 | 0:48943967d624 | 31 | char buffer[32]; |
neilt6 | 0:48943967d624 | 32 | strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
neilt6 | 0:48943967d624 | 33 | printf("Time as a custom formatted string = %s", buffer); |
neilt6 | 0:48943967d624 | 34 | |
neilt6 | 0:48943967d624 | 35 | //Delay for 1.0 seconds |
neilt6 | 0:48943967d624 | 36 | wait(1.0); |
neilt6 | 0:48943967d624 | 37 | } |
neilt6 | 0:48943967d624 | 38 | } else { |
neilt6 | 1:e983c454f8be | 39 | error("Device not detected!\n"); |
neilt6 | 0:48943967d624 | 40 | } |
neilt6 | 0:48943967d624 | 41 | } |