Exemple #1
0
/******************************************************************************
* LED_TurnOnLed
*
* Turn on one or more LEDs. Doesn't check/affect flashing states.
*******************************************************************************/
void LED_TurnOnLed(LED_t LEDNr)
{
  if (LEDNr & LED1)
    Led1On();
  if (LEDNr & LED2)
    Led2On();
  if (LEDNr & LED3)
    Led3On();
  if (LEDNr & LED4)
    Led4On();
}
Exemple #2
0
void MotorClass::Upward(void) // A1, B2 - вверх
{
	// отключаем A2 и B1
	GPIO_ResetBits(MOTOR_A2_GPIO,MOTOR_A2_PIN);
	GPIO_SetBits(MOTOR_B1_GPIO,MOTOR_B1_PIN);
	Led2Off();
	// ждем закрытия транзисторов
	Delay.ms(SWITCH_DELAY);
	// включаем A1 и B2
	GPIO_SetBits(MOTOR_A1_GPIO,MOTOR_A1_PIN);
	GPIO_ResetBits(MOTOR_B2_GPIO,MOTOR_B2_PIN);
	iOverloadDelay=0;
	chState=MOTOR_UPWARD;
	Led3On();
}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
    DEBUGDELAY* pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
    // PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)


    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

    // MTouchDebugDelay(sensorNumber) function calculates CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set adjusted CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);
    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
#endif

    // STEP 3
    // Slider initialization. All sliders must be initialized (see MTOUCH_2CHSLIDERS_NUMBER in mTouchConfig.h).
    // For example if slider is connected to sensor 5 and sensor 11
    // MTouchSet2ChSlider(0,           // slider number
    //                    5,           // first sensor number
    //                    11);         // second sensor number

    // slider #0
    MTouchSet2ChSlider(0, 0, 1);

    // STEP 4
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 5
        // Decode all controls.
        MTouchDecode();


        // STEP 6
        // Get current value of the slider.

        if(MTouchGet2ChSliderState(0) == CONTROL_PRESSED)
        {
            Led_ALLOff();

            if(MTouchGet2ChSliderValue(0) > 15*1000/16) {
                Led15On();
            }

            else if(MTouchGet2ChSliderValue(0) > 14*1000/16) {
                Led14On();
            }

            else if(MTouchGet2ChSliderValue(0) > 13*1000/16) {
                Led13On();
            }

            else if(MTouchGet2ChSliderValue(0) > 12*1000/16) {
                Led12On();
            }

            else if(MTouchGet2ChSliderValue(0) > 11*1000/16) {
                Led11On();
            }

            else if(MTouchGet2ChSliderValue(0) > 10*1000/16) {
                Led10On();
            }

            else if(MTouchGet2ChSliderValue(0) > 9*1000/16)  {
                Led9On();
            }

            else if(MTouchGet2ChSliderValue(0) > 8*1000/16)  {
                Led8On();
            }

            else if(MTouchGet2ChSliderValue(0) > 7*1000/16)  {
                Led7On();
            }

            else if(MTouchGet2ChSliderValue(0) > 6*1000/16)  {
                Led6On();
            }

            else if(MTouchGet2ChSliderValue(0) > 5*1000/16)  {
                Led5On();
            }

            else if(MTouchGet2ChSliderValue(0) > 4*1000/16)  {
                Led4On();
            }

            else if(MTouchGet2ChSliderValue(0) > 3*1000/16)  {
                Led3On();
            }

            else if(MTouchGet2ChSliderValue(0) > 2*1000/16)  {
                Led2On();
            }

            else if(MTouchGet2ChSliderValue(0) > 1*1000/16)  {
                Led1On();
            }

            else if(MTouchGet2ChSliderValue(0) > 0)          {
                Led0On();
            }
        }

#ifdef MTOUCH_DEBUG
        // Log data from sensors to PC GUI.
        MTouchDebugLogDeltas();

#endif


    }

}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
DEBUGDELAY* pDelay;
#endif
UINT8  i;

    // Board hardware initialization.
    SysBoardInit();

    // Clear sleep timeout counter.
    SleepResetTimeoutCounter();

    // Clear sleep mode flag.
    SleepSetRunMode();


    // mTouch library initialization.
    MTouchInit();

    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
	// PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)

                  
    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1); 
    // sensor #2
    MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1);  
    // sensor #3
    MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1);  
    // sensor #4
    MTouchSetSensor(4, CH4_TRIS, CH4_LAT, CH4_IO_BIT, CH4_AN_NUM, -1, -1, -1);  
    // sensor #5
    MTouchSetSensor(5, CH5_TRIS, CH5_LAT, CH5_IO_BIT, CH5_AN_NUM, -1, -1, -1);  
    // sensor #6
    MTouchSetSensor(6, CH6_TRIS, CH6_LAT, CH6_IO_BIT, CH6_AN_NUM, -1, -1, -1);  
    // sensor #7
    MTouchSetSensor(7, CH7_TRIS, CH7_LAT, CH7_IO_BIT, CH7_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // MTouchDebugDelay(sensorNumber) function calculates CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set adjusted CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);
    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
    pDelay = MTouchDebugDelay(2);
    MTouchSetChargeDelay(2, pDelay->delay);
    pDelay = MTouchDebugDelay(3);
    MTouchSetChargeDelay(3, pDelay->delay);
    pDelay = MTouchDebugDelay(4);
    MTouchSetChargeDelay(4, pDelay->delay);
    pDelay = MTouchDebugDelay(5);
    MTouchSetChargeDelay(5, pDelay->delay);
    pDelay = MTouchDebugDelay(6);
    MTouchSetChargeDelay(6, pDelay->delay);
    pDelay = MTouchDebugDelay(7);
    MTouchSetChargeDelay(7, pDelay->delay);

#endif

    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();

    while(1)
    {
        // Get current states of the buttons.
        // If any sensor is pressed then reset sleep mode timeout counter.
        Led_ALLOff();
        // sensor #0
        if(MTouchGetSensorState(0) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led0On();} 
        // sensor #1
        if(MTouchGetSensorState(1) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led1On();}
        // sensor #2
        if(MTouchGetSensorState(2) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led2On();}
        // sensor #3
        if(MTouchGetSensorState(3) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led3On();}
        // sensor #4
        if(MTouchGetSensorState(4) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led4On();}
        // sensor #5
        if(MTouchGetSensorState(5) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led5On();}
        // sensor #6
        if(MTouchGetSensorState(6) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led6On();}
        // sensor #7
        if(MTouchGetSensorState(7) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led7On();}


        // If the timeout counter transition is from sleep to run value then
        // change mode for normal operation.
        if(SleepIsWakeUpEvent())
        {
             
            // Disable watchdog timer.
            SysDisableWDT();

            // Initialize sensors
            MTouchInitializeSensor(0);
            MTouchInitializeSensor(1);
            MTouchInitializeSensor(2);
            MTouchInitializeSensor(3);
            MTouchInitializeSensor(4);
            MTouchInitializeSensor(5);
            MTouchInitializeSensor(6);
            MTouchInitializeSensor(7);

            // Enable timer interrupt
            SysEnableTimerInterrupt();

            // Clear sleep mode flag.
            SleepSetRunMode();

        }

        // If the timeout counter transition is from run to sleep value then
        // change mode for power save operation.
        if(SleepIsTimeoutEvent())
        {

            // Disable timer interrupt
            SysDisableTimerInterrupt();

            // Enable watchdog timer to wakeup.
            SysEnableWDT();

            // Set sleep mode flag.
            SleepSetSleepMode();
           
        }


        // Check sleep mode flag.
        if(SleepIsSleepMode())
        {

            // Indicate power saving mode.
            Led15On();
            
            // Enter device sleep mode (sleep time is 1024 mS).
            // Device will wake up from watchdog timer.
            Sleep();

            // Reset watchdog timer.
            ClrWdt();

            for(i=0; i<4*MTOUCH_DEFAULT_OVERSAMPLING; i++)
            {
                // Run acquisition.
                MTouchAcquisition();

                // Reset watchdog timer.
                ClrWdt();
            }


        }else{

            SleepIncrementTimeoutCounter();

        }
            
    }

}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
DEBUGDELAY*   pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
	// PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)

                  
    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);  
    // sensor #2
    MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1);  
    // sensor #3
    MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1);  
    // sensor #4
    MTouchSetSensor(4, CH4_TRIS, CH4_LAT, CH4_IO_BIT, CH4_AN_NUM, -1, -1, -1);  
    // sensor #5
    MTouchSetSensor(5, CH5_TRIS, CH5_LAT, CH5_IO_BIT, CH5_AN_NUM, -1, -1, -1);  
    // sensor #6
    MTouchSetSensor(6, CH6_TRIS, CH6_LAT, CH6_IO_BIT, CH6_AN_NUM, -1, -1, -1);  
    // sensor #7
    MTouchSetSensor(7, CH7_TRIS, CH7_LAT, CH7_IO_BIT, CH7_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

	// MTouchDebugDelay(sensorNumber) function calculates an optimal CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set the adjusted optimal CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);

    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
    pDelay = MTouchDebugDelay(2);
    MTouchSetChargeDelay(2, pDelay->delay);
    pDelay = MTouchDebugDelay(3);
    MTouchSetChargeDelay(3, pDelay->delay);
    pDelay = MTouchDebugDelay(4);
    MTouchSetChargeDelay(4, pDelay->delay);
    pDelay = MTouchDebugDelay(5);
    MTouchSetChargeDelay(5, pDelay->delay);
    pDelay = MTouchDebugDelay(6);
    MTouchSetChargeDelay(6, pDelay->delay);
    pDelay = MTouchDebugDelay(7);
    MTouchSetChargeDelay(7, pDelay->delay);

#endif

    // STEP 3
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 4
        // Get current states of the basic buttons.

        Led_ALLOff();
        // button #0
        if(MTouchGetSensorState(0) == SENSOR_PRESSED) { Led0On(); }
        // button #1
        if(MTouchGetSensorState(1) == SENSOR_PRESSED) { Led1On(); }
        // button #2
        if(MTouchGetSensorState(2) == SENSOR_PRESSED) { Led2On(); }
        // button #3
        if(MTouchGetSensorState(3) == SENSOR_PRESSED) { Led3On(); }
        // button #4
        if(MTouchGetSensorState(4) == SENSOR_PRESSED) { Led4On(); }
        // button #5
        if(MTouchGetSensorState(5) == SENSOR_PRESSED) { Led5On(); }
        // button #6
        if(MTouchGetSensorState(6) == SENSOR_PRESSED) { Led6On(); }
        // button #7
        if(MTouchGetSensorState(7) == SENSOR_PRESSED) { Led7On(); }


        #ifdef MTOUCH_DEBUG
           // Log data from sensors to PC GUI.
           MTouchDebugLogDeltas();

        #endif

     
    }

}