Demo the function of RTC module AM1805

Dependencies:   mbed-dev

Fork of I2C_HelloWorld_Mbed by mbed official

Committer:
marcusC
Date:
Thu Dec 24 05:15:42 2015 +0000
Revision:
2:16b8f527b5c7
Parent:
1:c45df8c46fa8
Remove the redundant log

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:f76c26307f9a 1 #include "mbed.h"
marcusC 1:c45df8c46fa8 2 #include "AM1805.h"
marcusC 1:c45df8c46fa8 3
marcusC 1:c45df8c46fa8 4 #define DEMO_INPUT_INTERRUPT 0
marcusC 1:c45df8c46fa8 5 #define DEMO_COUNTDOWN_TIMER 0
marcusC 1:c45df8c46fa8 6 #define DEMO_ALARM_FUNCTION 1
mbed_official 0:f76c26307f9a 7
marcusC 1:c45df8c46fa8 8 DigitalOut oneLed(LED1);
marcusC 1:c45df8c46fa8 9 DigitalOut twoLed(LED2);
marcusC 1:c45df8c46fa8 10 DigitalOut indLed(LED3);
marcusC 1:c45df8c46fa8 11 DigitalOut errorLed(LED4);
mbed_official 0:f76c26307f9a 12
marcusC 1:c45df8c46fa8 13 typedef enum
marcusC 1:c45df8c46fa8 14 {
marcusC 1:c45df8c46fa8 15 DEFAULT_FLAG = 0xFF, /**< Default State */
marcusC 1:c45df8c46fa8 16 INIT_FLAG = 0x01, /**< Initialize Done */
marcusC 1:c45df8c46fa8 17 HOST_RUN_ONE = 0x02, /**< Run to mode 1 */
marcusC 1:c45df8c46fa8 18 HOST_RUN_TWO = 0x04 /**< Run to mode 2 */
marcusC 1:c45df8c46fa8 19 } demo_mode_t;
mbed_official 0:f76c26307f9a 20
mbed_official 0:f76c26307f9a 21 int main() {
marcusC 1:c45df8c46fa8 22
marcusC 1:c45df8c46fa8 23 demo_mode_t demo_status = DEFAULT_FLAG;
marcusC 1:c45df8c46fa8 24
marcusC 1:c45df8c46fa8 25 /* attempt to read the current status */
marcusC 1:c45df8c46fa8 26 wait(5);
marcusC 1:c45df8c46fa8 27 demo_status = (demo_mode_t)am1805_read_ram(0);
marcusC 1:c45df8c46fa8 28
marcusC 1:c45df8c46fa8 29 if ( demo_status == DEFAULT_FLAG )
marcusC 1:c45df8c46fa8 30 {
marcusC 1:c45df8c46fa8 31 /* Not config AM1805 yet */
marcusC 1:c45df8c46fa8 32 indLed = 1;
marcusC 1:c45df8c46fa8 33 wait(1);
marcusC 1:c45df8c46fa8 34
marcusC 1:c45df8c46fa8 35 if ( am1805_init() == false )
marcusC 1:c45df8c46fa8 36 {
marcusC 1:c45df8c46fa8 37 while(1) {
marcusC 1:c45df8c46fa8 38 wait(0.1);
marcusC 1:c45df8c46fa8 39 errorLed = !errorLed;
marcusC 1:c45df8c46fa8 40 }
marcusC 1:c45df8c46fa8 41 }
marcusC 1:c45df8c46fa8 42
marcusC 1:c45df8c46fa8 43 #if DEMO_INPUT_INTERRUPT
marcusC 1:c45df8c46fa8 44 am1805_config_input_interrupt(XT1_INTERRUPT);
marcusC 1:c45df8c46fa8 45 #elif DEMO_COUNTDOWN_TIMER
marcusC 1:c45df8c46fa8 46 am1805_config_countdown_timer( PERIOD_SEC, 10, REPEAT_PLUSE_1_64_SEC, PIN_nTIRQ);
marcusC 1:c45df8c46fa8 47 #elif DEMO_ALARM_FUNCTION
marcusC 1:c45df8c46fa8 48
marcusC 1:c45df8c46fa8 49 time_reg_struct_t time_regs;
marcusC 1:c45df8c46fa8 50
marcusC 1:c45df8c46fa8 51 time_regs.hundredth = 0x00;
marcusC 1:c45df8c46fa8 52 time_regs.second = 0x08;
marcusC 1:c45df8c46fa8 53 time_regs.minute = 0x00;
marcusC 1:c45df8c46fa8 54 time_regs.hour = 0x00;
marcusC 1:c45df8c46fa8 55 time_regs.date = 0x00;
marcusC 1:c45df8c46fa8 56 time_regs.month = 0x00;
marcusC 1:c45df8c46fa8 57 time_regs.year = 0x00;
marcusC 1:c45df8c46fa8 58 time_regs.weekday = 0x00;
marcusC 1:c45df8c46fa8 59 time_regs.century = 0x00;
marcusC 1:c45df8c46fa8 60 time_regs.mode = 0x02;
marcusC 1:c45df8c46fa8 61 /* Set specific alarm time */
marcusC 1:c45df8c46fa8 62 am1805_config_alarm(time_regs, ONCE_PER_MINUTE, PULSE_1_4_SEC, PIN_FOUT_nIRQ);
marcusC 1:c45df8c46fa8 63 #endif
marcusC 1:c45df8c46fa8 64 wait(0.2);
marcusC 1:c45df8c46fa8 65 am1805_write_ram(0,HOST_RUN_ONE);
marcusC 1:c45df8c46fa8 66 wait(0.2);
marcusC 1:c45df8c46fa8 67 am1805_set_sleep(7,1);
marcusC 1:c45df8c46fa8 68 } else {
marcusC 1:c45df8c46fa8 69 switch(demo_status){
marcusC 1:c45df8c46fa8 70 case HOST_RUN_ONE:
marcusC 1:c45df8c46fa8 71 for(uint8_t i = 0;i < 5;i++)
marcusC 1:c45df8c46fa8 72 {
marcusC 1:c45df8c46fa8 73 wait(1);
marcusC 1:c45df8c46fa8 74 oneLed = !oneLed;
marcusC 1:c45df8c46fa8 75 }
marcusC 1:c45df8c46fa8 76 am1805_write_ram(0,HOST_RUN_TWO);
marcusC 1:c45df8c46fa8 77 wait(0.2);
marcusC 1:c45df8c46fa8 78 am1805_set_sleep(7,1);
marcusC 1:c45df8c46fa8 79 break;
marcusC 1:c45df8c46fa8 80 case HOST_RUN_TWO:
marcusC 1:c45df8c46fa8 81 for(uint8_t i = 0;i < 5;i++)
marcusC 1:c45df8c46fa8 82 {
marcusC 1:c45df8c46fa8 83 wait(1);
marcusC 1:c45df8c46fa8 84 twoLed = !twoLed;
marcusC 1:c45df8c46fa8 85 }
marcusC 1:c45df8c46fa8 86 am1805_write_ram(0,HOST_RUN_ONE);
marcusC 1:c45df8c46fa8 87 wait(0.2);
marcusC 1:c45df8c46fa8 88 am1805_set_sleep(7,1);
marcusC 1:c45df8c46fa8 89 break;
marcusC 1:c45df8c46fa8 90 default:
marcusC 1:c45df8c46fa8 91 errorLed = 1;
marcusC 1:c45df8c46fa8 92 break;
marcusC 1:c45df8c46fa8 93 }
marcusC 1:c45df8c46fa8 94 }
marcusC 1:c45df8c46fa8 95
mbed_official 0:f76c26307f9a 96 while (1) {
mbed_official 0:f76c26307f9a 97 }
mbed_official 0:f76c26307f9a 98 }