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 // 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 } }
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(); } } }
__noreturn main() { RCC_Config(); //I2C_Enable(); SPI_Enable(); GPIO_Enable(); //ADC_Enable(); MTouchInit(); MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1,OUT_CH0_MODER,IN_CH0_MODER,AN_CH0_MODER);// sensor #0 MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1,OUT_CH1_MODER,IN_CH1_MODER,AN_CH1_MODER);// sensor #1 MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1,OUT_CH2_MODER,IN_CH2_MODER,AN_CH2_MODER);// sensor #2 MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1,OUT_CH3_MODER,IN_CH3_MODER,AN_CH3_MODER);// sensor #3 // thr ovs cd MTouchSetButton(0, 0, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(1, 1, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(2, 2, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); MTouchSetButton(3, 3, DECODE_PRESS_RELEASE|DECODE_ONE_EVENT); Timers_init(); #ifdef __MOD_BUS_ENABLE__ eMBMasterInit(MB_RTU, 2, 38400, MB_PAR_NONE); eMBMasterEnable(); #endif /*__MOD_BUS_ENABLE__*/ __enable_irq(); //*******************Потом заменим на чтение из EEPROM******************* up_led(1); bottom_led(0); chasy_led_string("er"); minuty_led_string("r"); Indic_struct.colon = False; //************************************************************************ while (1) { #ifdef __MOD_BUS_ENABLE__ eMBMasterPoll(); #endif /*__MOD_BUS_ENABLE__*/ #ifdef __SENSOR_KEYS__ MTouchDecode(); #endif /*__SENSOR_KEYS__*/ #ifdef __TOUCH_DEBUG__ up_led(buttons[0].pSensor->delta/10); chasy_led(buttons[1].pSensor->delta/10); minuty_led(buttons[2].pSensor->delta/10); bottom_led(buttons[3].pSensor->delta/10); if(buttons[0].curState == 0x01){Indic_struct.k4 = True;} else {Indic_struct.k4 = False;}; if(buttons[1].curState == 0x01){Indic_struct.k3 = True;} else {Indic_struct.k3 = False;}; if(buttons[2].curState == 0x01){Indic_struct.k2 = True;} else {Indic_struct.k2 = False;}; if(buttons[3].curState == 0x01){Indic_struct.k1 = True;} else {Indic_struct.k1 = False;}; #endif /*__TOUCH_DEBUG__*/ // if (o < 7 ) {o++;} else {/*o = 0;*/}; // switch(o) // { // case 0: // Indic_struct.k1 = True; // break; // case 1: // Indic_struct.k2 = True; // break; // case 2: // Indic_struct.k3 = True; // break; // case 3: // Indic_struct.k4 = True; // break; // case 4: // Indic_struct.red_bottom = True; // break; // case 5: // //Indic_struct.minus = True; // break; // case 6: // Indic_struct.red_up = True; // break; // case 100: // Indic_struct.k1 = False; // Indic_struct.k2 = False; // Indic_struct.k3 = False; // Indic_struct.k4 = False; // Indic_struct.red_bottom = False; // Indic_struct.minus = False; // Indic_struct.red_up = False; // break; // default: // break; // }; // // for(uint16_t f=0;f<60000;f++){ for(uint16_t f=0;f<50;f++){};}; // // Indic_struct.minuty++; // // // // //Indic_struct.blink_chasy = True; // Indic_struct.blink_k2 = True; // Indic_struct.blink_minus = False; // //Indic_struct.blink_minuty = True; // Indic_struct.blink_verhniy_indicator = True; // Indic_struct.blink_colon = True; }; //return 0; }