Curiosity Development Board Example


This article guides you from start to finish on how to use the MCC mTouch® sensing solutions module to create a single touch button on the 8-bit Curiosity Board. It also guides you through the use of the mTouch library API to obtain button information.



Create an MPLAB® X project for the Curiosity Board.

The Curiosity Board supports a wide range of 8 bit PIC® microcontrollers; in this example the default PIC16F1619 is used.


If you are not familiar with MPLAB® X IDE, please visit the MPLAB X Page.




If you don't see the MCC logo as shown above, please check if you have installed the MCC plugin. More information on MCC installation can be found here.


Configure system clock.

Select 8MHz_HF for Internal Clock, and enable PLL. This will result in a 32MHz system clock.


To ensure the performance of mTouch button/proximity, an 8 MHz system clock is required. If you select a system clock slower than 8MHz, the mTouch module will generate a warning in the notification window.


Load mTouch Module.

Double click the mTouch icon in the Libraries list inside the Device Resources window.


After loading the module, the mTouch icon will appear in the Project Resources.



Select mTouch sensor.

After loading the mTouch module, the available mTouch sensor pin will be shown in the Pin Manager.
Select pin RC1 as the mTouch sensor, which is connected to the mTouch Button on the Curiosity board.



Add mTouch button and link to the sensor.

Go to the Buttons configuration view, and click Create New Button.


Then, click the Button0 icon to go to the Button Settings view, and select Sensor_AN5 sensor for Button0.



Enable Timer Interrupt.

Because the PIC16F1619 uses a software CVD implementation, the Automatic Frequency Adaptation (AFA) requires using a timer interrupt to schedule a CVD scan.
Open the Interrupt Module and enable the corresponding timer interrupt; in this example TMR2 is selected as the AFA timer.


If the corresponding timer interrupt is not enabled, there will be a warning issued in the Notification window.



Setup I/O pin to control LED.

LED D7 is used to provide visual feedback for the button state.
Select the RC5 pin, which is connected to LED D7, as an output in the Pin Manager.


Go to Pin Module, and rename the pin as LED.



Generate Code.

Click the Generate button.



Call mTouch service in main.c

Open up the generated main.c file, and enable the global and peripheral interrupts by uncommenting the two macros: INTERRUPT_GlobalInterruptEnable() and INTERRUPT_PeripheralInterruptEnable().

Place MTOUCH_Service_Mainloop() in the while loop, as shown below (highlighted):


Use mTouch button to control LED D7.

To use the API for mTouch button, mtouch_button.h must be included in main.c. The mTouch button provides an API: bool MTOUCH_Button_isPressed(enum mtouch_button_names button) to obtain the button state.

In this example, there is only one button, so "Button0" or "0" is provided as the argument for this API. The goal is to turn on the LED D7 (which is active high) when the button is pressed, and turn the LED off when the button is released. The application code that you need to write is shown in the highlighted lines below:


Program the board and test the code.

Click the Program icon to program the board.


Once finished, press the mTouch Button and the LED D7 should turn on.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.