pic18f46j50 RTCC, can't get it to work.

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Mar 26, 2015.

  1. bug13

    Thread Starter Senior Member

    Feb 13, 2012
    1,233
    40
    Hi guys

    I have trouble setting up RTCC, the idea is to setup an alarm (say 5 seconds later), trigger an interrupt and wake up the MCU.

    Here is my code:

    Code (Text):
    1. void setup_rtcc(void)
    2. {
    3.     rtccTimeDate RtccResetTimeDate;
    4.     rtccTimeDate RtccAlarmTimeDate;
    5.  
    6.     RtccInitClock();                            //turn on clock source
    7.     RtccWrOn();                                 //enable write to RTCC registers
    8.     PIE3bits.RTCCIE = 1;                   //enable interrupt
    9.  
    10.     //set up clock time
    11.     RtccResetTimeDate.f.hour = 0x01;
    12.     RtccResetTimeDate.f.min = 0x00;
    13.     RtccResetTimeDate.f.sec = 0x00;
    14.     RtccResetTimeDate.f.mday = 0x04;
    15.     RtccResetTimeDate.f.mon = 0x04;
    16.     RtccResetTimeDate.f.year = 0x09;
    17.     RtccResetTimeDate.f.wday = 0x06;
    18.  
    19.     //set up alarm time to be 5 second later
    20.     RtccAlarmTimeDate.f.hour = RtccResetTimeDate.f.hour;
    21.     RtccAlarmTimeDate.f.min = RtccResetTimeDate.f.min;
    22.     RtccAlarmTimeDate.f.sec = RtccResetTimeDate.f.sec + 0x05;
    23.     RtccAlarmTimeDate.f.mday = RtccResetTimeDate.f.mday;
    24.     RtccAlarmTimeDate.f.mon = RtccResetTimeDate.f.mon;
    25.     RtccAlarmTimeDate.f.year = RtccResetTimeDate.f.year;
    26.     RtccAlarmTimeDate.f.wday = RtccResetTimeDate.f.wday;
    27.  
    28.     RtccWriteTimeDate(&RtccResetTimeDate, 1);             //write time for clock
    29.     RtccSetAlarmRpt(RTCC_RPT_TEN_SEC,1);
    30.     RtccSetAlarmRptCount(0,1);                                        //alarm do not repeat
    31.     RtccWriteAlrmTimeDate(&RtccAlarmTimeDate);       //write time for alarm
    32.  
    33.     mRtccOn();                                                                    //enable rtcc
    34.     mRtccAlrmEnable();                                                      //enable alarm
    35. }
    36.  
    And that's how I test it:

    Code (Text):
    1.  
    2. while(1)
    3. {
    4.         if (PIR3bits.RTCCIF == 1)
    5.         {
    6.             PIR3bits.RTCCIF = 0;
    7.             LED2 = 1;
    8.         }
    9. }
     
Loading...