Hello,
I am working on a PIC project that is counting the number of push button presses and when it hits a predetermined value it will change states. However when the number of button presses equals the value nothing happens. I have even tried setting it up so that as long as the counter is greater than the set value the state would change to see if there was a debouncing issue and that too did not make a difference. I was wondering if anyone could point me in the right direction? I am assuming there is an issue in my code. I am using the 16f88 with XC8 compiler and MPLABX
I am working on a PIC project that is counting the number of push button presses and when it hits a predetermined value it will change states. However when the number of button presses equals the value nothing happens. I have even tried setting it up so that as long as the counter is greater than the set value the state would change to see if there was a debouncing issue and that too did not make a difference. I was wondering if anyone could point me in the right direction? I am assuming there is an issue in my code. I am using the 16f88 with XC8 compiler and MPLABX
Rich (BB code):
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 800000//Declare internal OSC Freq as 8MHz
#include <xc.h>
#include<pic.h>
__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & LVP_OFF & CPD_OFF & WRT_OFF & CCPMX_RB0 & CP_OFF);
__CONFIG(FCMEN_ON & IESO_ON);
unsigned int count=0;
main()
{
TRISA=0;//Sets all ports on A to be outputs
TRISB=1;//Sets all ports on B to be inputs
for(;;){
if(PORTBbits.RB0==1){//When the button is pressed the LED is off
PORTAbits.RA1 =0;
count=count+1;
}
else {
PORTAbits.RA1=1;
count = count +1;
}
if (count > 20){//if count =20 aka 20 button presses the LED turns on
PORTAbits.RA0=1;
}
else{
PORTAbits.RA0=0;
}
}
}