示例#1
0
文件: main.c 项目: Athuli7/Microchip
/******************************************************************************
 * 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)
{
    //Make sure that the SD-card is not selected
    TRISCbits.TRISC6 = 0;
    LATCbits.LATC6 = 1;
    PORTCbits.RC6 = 1;

	/* Initialize the mTouch library */
	mTouchInit();

	/* Call the mTouch callibration function */
	mTouchCalibrate();

	/* Initialize the accelerometer */
	InitBma150(); 

    //make sure that the accelerometer is not selected
    LATCbits.LATC7 = 1;
    PORTCbits.RC7 = 1;

	Fill(0x00);
	g_level = 0;
	loadLevel(g_level);
	InitPhysics();
}//end UserInit
示例#2
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
示例#3
0
文件: main.c 项目: huleg/Microchip
/******************************************************************************
 * 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)
{
    /* Initialize the mTouch library */
    mTouchInit();

    /* Call the mTouch callibration function */
    mTouchCalibrate();

    /* Initialize the accelerometer */
    InitBma150();

    //initialize the variable holding the handle for the last
    // transmission
    USBOutHandle = 0;
    USBInHandle = 0;
}//end UserInit
示例#4
0
文件: main.c 项目: huleg/Microchip
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{
    if(DemoIntroState == 0xFF)
    {
        BL_CheckLoaderEnabled();
    }

    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    // Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

    DemoIntroduction();

    if(!HIDRxHandleBusy(USBOutHandle))        //Check if data was received from the host.
    {

        switch(ReceivedDataBuffer[0])       //Look at the data the host sent, to see what kind of application specific command it sent.
        {
        case 0x80:  //mTouch callibration command
            mTouchCalibrate();
            break;

        case 0x20:
        {
            WORD potVoltage;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                /* Select ADC channel */
                ADCON0bits.CHS = 4;

                /* Make sure A/D interrupt is not set */
                PIR1bits.ADIF = 0;

                /* Begin A/D conversion */
                ADCON0bits.GO=1;
                //Wait for A/D convert complete
                while(!PIR1bits.ADIF);

                /* Get the value from the A/D */
                potVoltage = ADRES;

                ToSendDataBuffer[0] = 0x20;
                ToSendDataBuffer[1] = (BYTE)(potVoltage);
                ToSendDataBuffer[2] = (BYTE)(potVoltage>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x30:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(0);

                ToSendDataBuffer[0] = 0x30;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x31:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(1);

                ToSendDataBuffer[0] = 0x31;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }