/******************************************************************************
 * 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
Exemple #2
0
  void HW_init(void) {
    remapAllPins();

    ANCON0 = 0xFF;
    ANCON1 = 0x1F;

    IRQ0_INT_TRIS = 1;
    IRQ1_INT_TRIS = 1;

    // Config IRQ Edge = Rising
    INTCON2bits.INTEDG1 = 1;
    INTCON2bits.INTEDG2 = 1;


    PHY_IRQ0 = 0; // MRF89XA
    PHY_IRQ0_En = 1; // MRF89XA
    PHY_IRQ1 = 0; // MRF89XA
    PHY_IRQ1_En = 1; // MRF89XA    

    Data_nCS = 1;
    Config_nCS = 1;

    Data_nCS_TRIS = 0;
    Config_nCS_TRIS = 0;

    SDI_TRIS = 1;
    SDO_TRIS = 0;
    SCK_TRIS = 0;

    SSP1STAT = 0xC0;
    SSP1CON1 = 0x21;

    // reset radio
    PHY_RESETn = 1;
    PHY_RESETn_TRIS = 0;
    delay_ms(1);
    PHY_RESETn = 0;
    delay_ms(10);

    LED0_TRIS = 0;
    LED0 = 0;
    LED1_TRIS = 0;
    LED1 = 0;

    //documentation page 187
    // enabled timer,as 16 bit,internal instruction cycle, edge(x), not bypass prescaler, prescale 256
    T0CON = 0b10010111;
    TMR0H = 200; //wait more while configuration done
    INTCONbits.TMR0IE = 1;
    INTCONbits.TMR0IF = 0;
    INTCON2bits.TMR0IP = 0; //use low priority on timer0 interupts 
    
    RtccInitClock();
    RtccWrOn();
    RTCCFGbits.RTCSYNC = 1;
    RTCCALbits.CAL = 10000000;
    mRtccOn();
    mRtccWrOff();
    PIE3bits.RTCCIE = 0;

    RCONbits.IPEN = 1; //enable interupt priority levels

    INTCONbits.GIEH = 1;
    INTCONbits.GIEL = 1;
    
    spieepromInit();
    Vibra_Init();
    I2c_Init();
    
/*         
    unjoinNetwork();
    while(1);
*/    
    
    
};