Exemple #1
0
/*****************************************************************************
 * Function: TBannerChangeField
 *
 * Precondition: None.
 *
 * Overview: The function increases/decreases the selected clock field.
 *
 * Input: Direction of changing: 0 to decrement otherwise increment.
 *
 * Output: None.
 *
 *****************************************************************************/
void TBannerChangeField(char increment){
unsigned char data;
if(_uTBannerSetup){
	mRTCCUnlock();
    switch(_uTBannerCurPos){
        case TBNR_POS_WKDAY:
            break;
        case TBNR_POS_HOUR:
            data = mRTCCGetBinHour();
            if(increment) data++; else data--;
            RTCCSetBinHour(data);
            break;
        case TBNR_POS_MIN:
            data = mRTCCGetBinMin();
            if(increment) data++; else data--;
            RTCCSetBinMin(data);
            break;
        case TBNR_POS_SEC:
            data = mRTCCGetBinSec();
            if(increment) data++; else data--;
            RTCCSetBinSec(data);
            break;
        case TBNR_POS_MONTH:
            data = mRTCCGetBinMonth();
            if(increment) data++; else data--;
            RTCCSetBinMonth(data);
            RTCCCalculateWeekDay();
            break;
        case TBNR_POS_DAY:
            data = mRTCCGetBinDay();
            if(increment) data++; else data--;
            RTCCSetBinDay(data);
            RTCCCalculateWeekDay();
            break;
        case TBNR_POS_YEAR:
            data = mRTCCGetBinYear();
            if(increment) data++; else data--;
            RTCCSetBinYear(data);
            RTCCCalculateWeekDay();
            break;
        default:
            ;
    }// End of switch(_uTBannerCurPos ...
    mRTCCSet();
}
}
/*********************************************************************
 * Function: RTCCInit
 *
 * Preconditions: RTCCInit must be called before.
 *
 * Overview: Enable the oscillator for the RTCC
 *
 * Input: None.
 *
 * Output: None.
 ********************************************************************/
void RTCCInit(void)
{
    // Enables the LP OSC for RTCC operation
	asm("mov #OSCCON,W1");	// move address of OSCCON to W1
	asm("mov.b #0x02, W0");	// move 8-bit literal to W0, 16-bit.
	asm("mov.b #0x46, W2");	// unlock byte 1 for OSCCONL(low byte)
	asm("mov.b #0x57, W3");	// unlock byte 2 for OSCCONL(low byte)
							// move 8-bit of Wn to OSCCON register
	asm("mov.b W2, [W1]");	// write unlock byte 1
	asm("mov.b W3, [W1]");	// write unlock byte 2
	asm("mov.b W0, [W1]");	// enable SOSCEN

    // Unlock sequence must take place for RTCEN to be written
	RCFGCAL	= 0x0000;
    RTCCUnlock();
    RCFGCALbits.RTCEN = 1;	// bit15

    //RTCC pin pad conected to RTCC second clock
	PADCFG1bits.RTSECSEL = 1;
	RCFGCALbits.RTCOE = 1;		//RTCC Output Enable bit

	/* Enable the RTCC interrupt*/
	IFS3bits.RTCIF = 0;		//clear the RTCC interrupt flag
	IEC3bits.RTCIE = 1;		//enable the RTCC interrupt

    // TO DO: Write the time and date to RTCC as follow.
	_time_chk.sec = mRTCCBin2Dec(0);
	_time_chk.min = mRTCCBin2Dec(1);  // 40 minutes
	_time_chk.hr =  mRTCCBin2Dec(2);   //7PM
	_time_chk.wkd = 3;
	_time_chk.day = mRTCCBin2Dec(4);
	_time_chk.mth = mRTCCBin2Dec(5);
	_time_chk.yr = mRTCCBin2Dec(13);
	RTCCCalculateWeekDay();	// To calculate and confirm the weekday

	// Set it after you change the time and date.
	RTCCSet();

	// Set alarm
	_alarm.sec	= 0x01;
	_alarm.min	= 0x01;
	_alarm.hr	= 0x01;
	_alarm.wkd	= 0x01;
	_alarm.day	= 0x01;
	_alarm.mth	= 0x01;
	RTCCALMSet();
}
Exemple #3
0
WORD ProcessMessageTime( WORD translatedMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg )
{
    signed char change;
    WORD        controlID;
    signed char day;
    signed char dayMax;
    signed char hour;
    signed char minute;
    signed char month;
    signed char year;


    controlID = GetObjID(pObj);
    switch (controlID)
    {
       case ID_RTCC_BUTTON_NEXT:
            // Show the old control set as unselected.
            IndicateFocus( BLACK );

            // Set the next control as active.
            currentControlSet ++;
            if (currentControlSet > CONTROL_SET_MAX)
            {
                currentControlSet = 0;
            }

            // Show the new control set as selected.
            IndicateFocus( WHITE );

            return 0;   // Hidden button
            break;

       case ID_RTCC_BUTTON_PREVIOUS:
            // Show the old control set as unselected.
            IndicateFocus( BLACK );

            // Set the next control as active.
            currentControlSet --;
            if (currentControlSet < 0 )
            {
                currentControlSet = CONTROL_SET_MAX;
            }

            // Show the new control set as selected.
            IndicateFocus( WHITE );

            return 0;   // Hidden button
            break;

        case ID_RTCC_BUTTON_HOME:
            screenState = SCREEN_DISPLAY_MAIN;
            return 0;   // Hidden button
            break;

        case ID_DAY_PLUS:
        case ID_MONTH_PLUS:
        case ID_YEAR_PLUS:
        case ID_HOUR_PLUS:
        case ID_MINUTE_PLUS:
            if (translatedMsg == BTN_MSG_PRESSED)
            {
                change = +1;
            }
            else
            {
                return 1;
            }
            break;

        case ID_DAY_MINUS:
        case ID_MONTH_MINUS:
        case ID_YEAR_MINUS:
        case ID_HOUR_MINUS:
        case ID_MINUTE_MINUS:
            if (translatedMsg == BTN_MSG_PRESSED)
            {
                change = -1;
            }
            else
            {
                return 1;
            }
            break;

        default:
            return 0;
    }

    // Update the selected field.

    RTCCProcessEvents();
    hour    = RTCCGetBinHour();
    minute  = RTCCGetBinMin();
    day     = RTCCGetBinDay();
    month   = RTCCGetBinMonth();
    year    = RTCCGetBinYear();

    dayMax  = daysPerMonth[month-1];

    // February has one day more for a leap year, unless it is on the thousands
    if ((month == 2) && ((year % 4) == 0) && (year != 0))
    {
        dayMax ++;
    }

    // Change the appropriate setting.  Allow the controls to roll over.
    switch (currentControlSet)
    {
        case CONTROL_SET_DAY:
            day += change;
            if (day < 1)
            {
                day = dayMax;
            }
            if (day > dayMax)
            {
                day = 1;
            }
            break;

        case CONTROL_SET_MONTH:
            month += change;
            if (month < 1)
            {
                month = 12;
            }
            if (month > 12)
            {
                month = 1;
            }
            break;

        case CONTROL_SET_YEAR:
            year += change;
            if (year < 0)
            {
                year = 99;
            }
            if (year > 99)
            {
                year = 0;
            }
            break;

        case CONTROL_SET_HOUR:
            hour += change;
            if (hour < 0)
            {
                hour = 23;
            }
            if (hour > 23)
            {
                hour = 0;
            }
            break;

        case CONTROL_SET_MINUTE:
            minute += change;
            if (minute < 0)
            {
                minute = 59;
            }
            if (minute > 59)
            {
                minute = 0;
            }
            break;

        default:
            return 0;
    }

    RTCCOff();
    RTCCSetBinHour( hour );
    RTCCSetBinMin( minute );
    RTCCSetBinSec( 0 );
    RTCCSetBinMonth( month );
    RTCCSetBinYear( year );
    RTCCSetBinDay( day );
    RTCCCalculateWeekDay();
    RTCCSet();                      // Copy the new values to the RTCC registers
    UpdateDateTime();               // Update the display.

    return 1;   // Call the default handler to show the button state.
}