Problem understading how to use touch-button on PIC16F1619 microcontroller

Thread Starter

Cliff Karlsson

Joined May 16, 2017
4
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:
#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;
 }
}
 

AlbertHall

Joined Jun 4, 2014
12,346
Are you using a push button switch on RC1 (not a touch sensitive thing)?
You need to set the pins for digital I/O. The default is analog.
ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
Also, do you have a pull up a resistor on RC1? (Assuming the switch is from the PIC pin to ground.)
If not you could enable the weak pull up like this:
WPUC = 0x02;
 

Thread Starter

Cliff Karlsson

Joined May 16, 2017
4
Are you using a push button switch on RC1 (not a touch sensitive thing)?
You need to set the pins for digital I/O. The default is analog.
ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
Also, do you have a pull up a resistor on RC1? (Assuming the switch is from the PIC pin to ground.)
If not you could enable the weak pull up like this:
WPUC = 0x02;
 

Thread Starter

Cliff Karlsson

Joined May 16, 2017
4
There is a built in Touch sensor on the board which uses the port RC1 internally. I dont understand if that makes it analog or how it works.
 

AlbertHall

Joined Jun 4, 2014
12,346
OK. The only hardware there is on the board is the touch button so what the PIC has to measure is the capacitance on RC1. This is not trivial. Did the board come with example code (or is there some to download)?
 

ErnieM

Joined Apr 24, 2011
8,377
The demonstration program for this board used the on board touch button to Turn on the D6 LED.

Have you inspected that code to see how they do it?
 
Top