Cant get touch-button to work on PIC16F1619 (Curiosity)

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
burton666
Posts: 3
Joined: Tue May 16, 2017 9:16 am

Cant get touch-button to work on PIC16F1619 (Curiosity)

Post by burton666 » Wed Jun 07, 2017 8:31 am

I have a Microschip Curiosity-board with a PIC16F1619 microcontroller. I use this board for school but I am struggeling to understand some of the basic functions. I am trying to light up some leds when I touch the button (RC1 - Touchbutton)

I have seen that there are alot of code which uses some easier library for controlling th button, but we are only allowed to import the htc.h as I understand.

Can anyone help me correct my code so that I can get something to react to the touchbutton.

Code: Select all

#include <htc.h>

#define _XTAL_FREQ 500000 
void main(void){
OSCCON = 0b00111000;

TRISA =0; 
TRISB=0;
TRISC=0b00000010;

OPTION_REG = 0b00000110;
LATCbits.LATC1 = 1;
INTCONbits.IOCIE = 1;
IOCCNbits.IOCCN1 = 1;
GIE=1;
while(1){
LATA =0;
LATB=0;
}
}
void interrupt ISR(void){
    if(IOCCFbits.IOCCF1){
        IOCCFbits.IOCCF1=0;
        __delay_ms(5);
        LATA=1;
        LATB=1;
        LATC=0b11111101;
    }
}

User avatar
phalanx
Non-SFE Guru
Posts: 1972
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Cant get touch-button to work on PIC16F1619 (Curiosity)

Post by phalanx » Mon Jun 19, 2017 7:50 pm

Hi burton666,

A few things. First you need to clear all your ANSELA, ANSELB, and ANSELC bits to set all the analog pins to digital I/O.

The next thing is the mTouch button doesn't work like a normal pushbutton. You need to configure an oscillator to drive the pad plus additional hardware to measure the response of someone putting their finger in proximity of the touch pad. This is not trivial and your best bet is to use the demo software that comes with MPLABX as a starting point for your implementation of the mTouch button.

If you don't have a specific requirement to use the mTouch button, a traditional TACT switch is implemented on the board and is connected to RC4. This one will work in a traditional manner where the pin is HI until you push the button which sets it LO.

In any case, review the source code of the demo application for your Curiosity board.

-Bill

Post Reply