示例#1
0
/******************************************************************************
 * Function:        void UserInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This routine should take care of all of the demo code
 *                  initialization that is required.
 *
 * Note:            
 *
 *****************************************************************************/
void UserInit(void)
{
	// Real time clock start
	RtccInitClock();
	RtccWrOn();                             
	
	{
		rtccTimeDate initd;
		initd.f.year=0x10;
		initd.f.mon=0x01;
		initd.f.mday=0x01;
		initd.f.wday=5;   // 2010.01.01 is friday
		initd.f.hour=0;
		initd.f.min=0;
		initd.f.sec=0;
		RtccWriteTimeDate(&initd,FALSE);
		RtccWriteAlrmTimeDate(&initd);
	}
	mRtccOn();
        mRtccAlrmEnable();
	RtccSetAlarmRpt(RTCC_RPT_MIN,TRUE);
	// Mtouch init
	mTouchInit();
	mTouchCalibrate();
	
	cmdstr[0]=0;
	screen=0;
	screenvalid=0;
	position=0;
	buttonstate.Val=0;
	buttonpressed.Val=0;
    devicereset=0;  
    clockss=0;
	resetcounter=0;
	alarmcnt=0;

        TRISBbits.TRISB1=0;

        PPSUnLock();
        iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_CCP1P1A);            //Configre RP24 as C1OUT pin
        PPSLock();

//----Configure pwm ----
    period = 0xFF;
    OpenPWM1( period);            //Configure PWM module and initialize PWM period

//-----set duty cycle----
        duty_cycle = 256;
        SetDCPWM1(duty_cycle);        //set the duty cycle

//----set pwm output----
    outputconfig = HALF_OUT ;
    outputmode = PWM_MODE_1;
    SetOutputPWM1( outputconfig, outputmode);    //output PWM in respective modes
	ADCON0bits.CHS=4;
	/* Make sure A/D interrupt is not set */
	PIR1bits.ADIF = 0;
	/* Begin A/D conversion */
}//end UserInit
示例#2
0
/*********************************************************************
 * Function:        BOOL RtccWriteTime(const rtccTime* pTm, BOOL di)
 *
 * PreCondition:    pTm pointing to a valid rtccTime structure having proper values:
 *                      - sec:  BCD codification, 00-59
 *                      - min:  BCD codification, 00-59
 *                      - hour: BCD codification, 00-24
 * Input:           pTm - pointer to a constant rtccTime union
 *                  di  - if interrupts need to be disabled
 * Output:          TRUE '1' : If all the values are within range
 *                  FALSE '0' : If any value is out of above mentioned range.
 * Side Effects:    None
 * Overview:        The function sets the current time of the RTCC device.
 * Note:            - The write is successful only if Wr Enable is set.
 *                  The function will enable the write itself, if needed.
 *                  Also, the Alarm will be temporarily disabled and the
 *                  device will be stopped (On set to 0) in order
 *                  to safely perform the update of the RTC time register.
 *                  However, the device status will be restored.
 *                  - Usually the disabling of the interrupts is desired, if the user has to have more
 *                  precise control over the actual moment of the time setting.
 ********************************************************************/
BOOL RtccWriteTime(const rtccTime* pTm , BOOL di)
{
    WORD_VAL tempHourWDay ;
    WORD_VAL tempMinSec ;
    UINT8  CPU_IPL;

    BOOL        wasWrEn;
    BOOL        wasOn;
    BOOL        wasAlrm=FALSE;

    if((MAX_MIN < pTm->f.min )|| (MAX_SEC < pTm->f.sec) || (MAX_HOUR < pTm->f.hour))
    {
        return(FALSE);
    }

    tempMinSec.byte.HB = pTm->f.min;
    tempMinSec.byte.LB =pTm->f.sec;        // update the desired fields

    if(di)
    {
        /* Disable Global Interrupt */
        mSET_AND_SAVE_CPU_IP(CPU_IPL,7);
    }

    if(!(wasWrEn= mRtccIsWrEn()))
    {
        RtccWrOn();            // have to allow the WRTEN in order to write the new value
    }
    if((wasOn=mRtccIsOn()))
    {
        wasAlrm= mRtccIsAlrmEnabled();
        mRtccOff();         // turn module off before updating the time
    }

    mRtccClearRtcPtr();
    mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);

    tempHourWDay.Val = RTCVAL;
    tempHourWDay.byte.LB = pTm->f.hour;


    mRtccClearRtcPtr();
    mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);

    RTCVAL = tempHourWDay.Val; // update device value
    RTCVAL = tempMinSec.Val;

    if(wasOn)
    {
        mRtccOn();
        if(wasAlrm)
        {
            mRtccAlrmEnable();
        }

        if(wasWrEn)
        {
            RtccWrOn();
        }
    }
    else
    {
        if(!wasWrEn)
        {
            mRtccWrOff();
        }
    }

    if(di)
    {
        /* Enable Global Interrupt */
        mRESTORE_CPU_IP(CPU_IPL);
    }


    return(TRUE);
}