void configureRTC() { RtccInit(); while (RtccGetClkStat() != RTCC_CLK_ON); //printf("RTCC OK\r\n"); // set time and date // time is MSb: hour, min, sec, rsvd. date is MSb: year, mon, mday, wday. // please note that the rsvd field has to be 0 in the time field! // Time is in Hex! RtccOpen(0x17040000, 0x08100604, 0); // set the RTCC priority in the INT controller INTSetVectorPriority(INT_RTCC_VECTOR, INT_PRIORITY_LEVEL_5); // set the RTCC sub-priority in the INT controller INTSetVectorSubPriority(INT_RTCC_VECTOR, INT_SUB_PRIORITY_LEVEL_1); // enable the RTCC event interrupts in the INT controller. INTEnable(INT_RTCC, INT_ENABLED); // enable alaram or endless alaram - // it allows the alarm rpt to move back to the beginning //RtccChimeDisable(); - this is now changeable // how much repats - 0 means run the alarm only once //RtccSetAlarmRptCount(0); //the above means once we have alarm interrupt the alarm will be disabled // used for marching (i.e. window) when cpmparing RtccSetAlarmRpt(RTCC_RPT_MON); }
/****************************************************************************** * 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