The mTouchCVD_Init() function will automatically configure the ADC, communications module (if enabled), and all required interrupts. There are only a few things the user is required to define on power-up:
OSCCON = 0b01110000; // 32 MHz Fosc w/ PLLEN_ON config word on PIC16F1937
OPTION_REG = 0b10000000; // TMR0 Prescaler = 1:2 (~40% processor usage)
ANSELA = 0b00000000; // Digital TRISA = 0b00000000; // Output PORTA = 0b00000000; // Low
Open mTouchCVD_Config.h and make the following edits:
#define _XTAL_FREQ 32000000
#define TMR0_PRESCALER 2
#define CVD_NUMBER_SENSORS 5
#define CVD_SENSOR0 AN0 #define CVD_SENSOR1 AN1 #define CVD_SENSOR2 AN2 #define CVD_SENSOR3 AN3 #define CVD_SENSOR4 AN4
CVD_SENSOR5
, in this case - will simply be ignored.)
In your application's main loop:
while(1) { if (mTouchCVD_isDataReady()) // Is new information ready? { mTouchCVD_Service(); // Decode the newly captured data and transmit new data updates. } }
#define LED0 LATA0 #define LED_ON 0 #define LED_OFF 1 if (CVD_GetButtonState(0) < CVD_PRESSED) { LED0 = LED_OFF; // Sensor is either initializing or released. } else { LED0 = LED_ON; // Sensor is pressed. }
Your application should now compile and function. If you have enabled communications, you can see the real-time sensor readings using the mTouch CVD Framework GUI. For more information about adjusting the thresholds on sensors and further customizations, refer to the other Getting Started guides.