• AVR Freaks

Hot!set compilation time as RTCC time and date

Author
sumit809
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2020/03/08 23:49:39
  • Location: 0
  • Status: offline
2020/07/02 11:45:14 (permalink)
0

set compilation time as RTCC time and date

Controller: PIC32MM0256GPM064
 
There is a provision to set initial time for RTCC in MCC, but I think it's useless since I don't know that when I'm going to burn my hex code into the controller.
 
In arduino, it used to automatically take compilation time as the clock time. How can I achieve this in MCC or in my code using RTCC_TimeSet function?
#1

10 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3851
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/02 13:33:19 (permalink)
    5 (3)
    Check the docs whether symbols like DATE and TIME (with whatever number of embracing underscores) are available and how to use these. (Not absolutely sure, but I seem to remember such symbols.)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    sumit809
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2020/03/08 23:49:39
    • Location: 0
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/06 05:25:06 (permalink)
    0
    I can set it directly in RTCTIME and RTCDATE registers... But that can be hardcoded only...
     
    I want them to be set with compilation date and time...
    #3
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: set compilation time as RTCC time and date 2020/07/06 06:01:09 (permalink)
    5 (3)
    That is what du00000001 is describing. Those macros contain the compilation time

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    crosland
    Super Member
    • Total Posts : 2017
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/06 06:03:03 (permalink)
    5 (3)
    sumit809
    I can set it directly in RTCTIME and RTCDATE registers... But that can be hardcoded only...

     
    What makes you say that? They can be written at run time.
     

    I want them to be set with compilation date and time...



    Post #2 gives you the answer, if you apply a bit of thought to the problem.
    #5
    du00000001
    Just Some Member
    • Total Posts : 3851
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/06 06:53:35 (permalink)
    4.2 (5)
    sumit809
    I can set it directly in RTCTIME and RTCDATE registers... But that can be hardcoded only...
     
    I want them to be set with compilation date and time...



    Troll !
    The symbols available are __DATE_ and __TIME_. Now you just have to find out how to access and use these.
    But there's an "XC32 Compiler User's Guide" ...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    sumit809
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2020/03/08 23:49:39
    • Location: 0
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/06 10:56:38 (permalink)
    0
    Sorry guys...
     
    I searched entire internet... but missed what you wanted to say @du000000001
    I'm thinking myself as so dumb... 
     
    I got the compilation date and time with __DATE__ and __TIME__ 
    now it's time to convert it into legit hex code for RTCDATE and RTCTIME...
     
    Thanks guys!
    #7
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: set compilation time as RTCC time and date 2020/07/06 13:49:15 (permalink)
    4.67 (3)
    sumit809
    I searched entire internet...

    I suspect this is a small exaggeration.
     
    Why not START with the compiler user guide?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    dan1138
    Super Member
    • Total Posts : 3731
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/06 16:20:03 (permalink)
    4.67 (3)
    sumit809
    ... now it's time to convert it into legit hex code for RTCDATE and RTCTIME ...

    This is lifted from Micorchip Explorer 16/32 demo code:
    /*****************************************************************************
     * Function: RTCCInit
     *
     * Preconditions: RTCCInit must be called before.
     *
     * Overview: Enable the oscillator for the RTCC
     *
     * Input: None.
     *
     * Output: None.
     *****************************************************************************/
    void RTCCInit(void)
    {
        char day;
        char month;
        char year;
        char hour;
        char min;
        char sec;
        int dayOfWeek;

    //  SOCS_Enable();
        //Enables the OSCON write and set
        asm volatile ("mov #OSCCON,W1");
        asm volatile ("mov.b    #0x46, W2");    // unlock sequence
        asm volatile ("mov.b    #0x57, W3");
        asm volatile ("mov.b    #0x02, W0");    // SOSCEN =1     
        asm volatile ("mov.b    W2, [W1]");
        asm volatile ("mov.b    W3, [W1]");
        asm volatile ("mov.b    W0, [W1]");
     
    //  SOCS_Enable();
        // Unlock sequence must take place for RTCEN to be written
        RCFGCAL = 0x0000;
        mRTCCUnlock();
        RCFGCALbits.RTCEN = 1;
        mRTCCOn();

        sec =  (((__TIME__[6])&0x0F)<<4) | ((__TIME__[7])&0x0F);
        min =  (((__TIME__[3])&0x0F)<<4) | ((__TIME__[4])&0x0F);
        hour = (((__TIME__[0])&0x0F)<<4) | ((__TIME__[1])&0x0F);
        day =  (((__DATE__[4])&0x0F)<<4) | ((__DATE__[5])&0x0F);
        year = (((__DATE__[9])&0x0F)<<4) | ((__DATE__[10])&0x0F);

        //Set the month
        switch(__DATE__[0])
        {
            case 'J':
                //January, June, or July
                switch(__DATE__[1])
                {
                    case 'a':
                        //January
                        month = 0x01;
                        break;
                    case 'u':
                        switch(__DATE__[2])
                        {
                            case 'n':
                                //June
                                month = 0x06;
                                break;
                            case 'l':
                                //July
                                month = 0x07;
                                break;
                        }
                        break;
                }
                break;
            case 'F':
                month = 0x02;
                break;
            case 'M':
                //March,May
                switch(__DATE__[2])
                {
                    case 'r':
                        //March
                        month = 0x03;
                        break;
                    case 'y':
                        //May
                        month = 0x05;
                        break;
                }
                break;
            case 'A':
                //April, August
                switch(__DATE__[1])
                {
                    case 'p':
                        //April
                        month = 0x04;
                        break;
                    case 'u':
                        //August
                        month = 0x08;
                        break;
                }
                break;
            case 'S':
                month = 0x09;
                break;
            case 'O':
                month = 0x10;
                break;
            case 'N':
                month = 0x11;
                break;
            case 'D':
                month = 0x12;
                break;
        }

        mRTCCSetSec(sec);
        mRTCCSetMin(min);
        mRTCCSetHour(hour);
        mRTCCSetDay(day);
        mRTCCSetMonth(month);
        mRTCCSetYear( year );

        dayOfWeek = 6;
        dayOfWeek += ((year>>4)*10)+(year&0x0F);
        dayOfWeek += ((year>>4)*10)+(year&0x0F)/4;
        switch(month)
        {
            case 0x01:  //January
                //fall through
            case 0x10:  //October
                //add nothing
                break;

            case 0x02:  //February
            case 0x03:  //March
            case 0x11:  //November
                dayOfWeek += 3;
                break;

            case 0x04:  //April
            case 0x07:  //July
                dayOfWeek += 6;
                break;

            case 0x05:  //May
                dayOfWeek += 1;
                break;

            case 0x06:  //June
                dayOfWeek += 4;
                break;

            case 0x08:  //August
                dayOfWeek += 2;
                break;

            case 0x09:  //September
                //fall through
            case 0x12:  //December
                dayOfWeek += 5;
                break;
        }
        dayOfWeek += ((day>>4)*10)+(day&0x0F);
        dayOfWeek = dayOfWeek%7;

        mRTCCSetWkDay(dayOfWeek);

        mRTCCSet();
    }

    #9
    sumit809
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2020/03/08 23:49:39
    • Location: 0
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/08 00:44:34 (permalink)
    0
    ric
    sumit809
    I searched entire internet...

    I suspect this is a small exaggeration.
     
    Why not START with the compiler user guide?
     




    Yeah! I'm keeping it handy now
    #10
    sumit809
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2020/03/08 23:49:39
    • Location: 0
    • Status: offline
    Re: set compilation time as RTCC time and date 2020/07/08 00:46:48 (permalink)
    0
    dan1138
    sumit809
    ... now it's time to convert it into legit hex code for RTCDATE and RTCTIME ...

    This is lifted from Micorchip Explorer 16/32 demo code:
    /*****************************************************************************
     * Function: RTCCInit
     *
     * Preconditions: RTCCInit must be called before.
     *
     * Overview: Enable the oscillator for the RTCC
     *
     * Input: None.
     *
     * Output: None.
     *****************************************************************************/
    void RTCCInit(void)
    {
        char day;
        char month;
        char year;
        char hour;
        char min;
        char sec;
        int dayOfWeek;

    //  SOCS_Enable();
        //Enables the OSCON write and set
        asm volatile ("mov #OSCCON,W1");
        asm volatile ("mov.b    #0x46, W2");    // unlock sequence
        asm volatile ("mov.b    #0x57, W3");
        asm volatile ("mov.b    #0x02, W0");    // SOSCEN =1     
        asm volatile ("mov.b    W2, [W1]");
        asm volatile ("mov.b    W3, [W1]");
        asm volatile ("mov.b    W0, [W1]");
     
    //  SOCS_Enable();
        // Unlock sequence must take place for RTCEN to be written
        RCFGCAL = 0x0000;
        mRTCCUnlock();
        RCFGCALbits.RTCEN = 1;
        mRTCCOn();

        sec =  (((__TIME__[6])&0x0F)<<4) | ((__TIME__[7])&0x0F);
        min =  (((__TIME__[3])&0x0F)<<4) | ((__TIME__[4])&0x0F);
        hour = (((__TIME__[0])&0x0F)<<4) | ((__TIME__[1])&0x0F);
        day =  (((__DATE__[4])&0x0F)<<4) | ((__DATE__[5])&0x0F);
        year = (((__DATE__[9])&0x0F)<<4) | ((__DATE__[10])&0x0F);

        //Set the month
        switch(__DATE__[0])
        {
            case 'J':
                //January, June, or July
                switch(__DATE__[1])
                {
                    case 'a':
                        //January
                        month = 0x01;
                        break;
                    case 'u':
                        switch(__DATE__[2])
                        {
                            case 'n':
                                //June
                                month = 0x06;
                                break;
                            case 'l':
                                //July
                                month = 0x07;
                                break;
                        }
                        break;
                }
                break;
            case 'F':
                month = 0x02;
                break;
            case 'M':
                //March,May
                switch(__DATE__[2])
                {
                    case 'r':
                        //March
                        month = 0x03;
                        break;
                    case 'y':
                        //May
                        month = 0x05;
                        break;
                }
                break;
            case 'A':
                //April, August
                switch(__DATE__[1])
                {
                    case 'p':
                        //April
                        month = 0x04;
                        break;
                    case 'u':
                        //August
                        month = 0x08;
                        break;
                }
                break;
            case 'S':
                month = 0x09;
                break;
            case 'O':
                month = 0x10;
                break;
            case 'N':
                month = 0x11;
                break;
            case 'D':
                month = 0x12;
                break;
        }

        mRTCCSetSec(sec);
        mRTCCSetMin(min);
        mRTCCSetHour(hour);
        mRTCCSetDay(day);
        mRTCCSetMonth(month);
        mRTCCSetYear( year );

        dayOfWeek = 6;
        dayOfWeek += ((year>>4)*10)+(year&0x0F);
        dayOfWeek += ((year>>4)*10)+(year&0x0F)/4;
        switch(month)
        {
            case 0x01:  //January
                //fall through
            case 0x10:  //October
                //add nothing
                break;

            case 0x02:  //February
            case 0x03:  //March
            case 0x11:  //November
                dayOfWeek += 3;
                break;

            case 0x04:  //April
            case 0x07:  //July
                dayOfWeek += 6;
                break;

            case 0x05:  //May
                dayOfWeek += 1;
                break;

            case 0x06:  //June
                dayOfWeek += 4;
                break;

            case 0x08:  //August
                dayOfWeek += 2;
                break;

            case 0x09:  //September
                //fall through
            case 0x12:  //December
                dayOfWeek += 5;
                break;
        }
        dayOfWeek += ((day>>4)*10)+(day&0x0F);
        dayOfWeek = dayOfWeek%7;

        mRTCCSetWkDay(dayOfWeek);

        mRTCCSet();
    }





    I have written my own logic for now... but it's good to know this apprach as well...
    Thanks
     
    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5