chimera786
Member level 2
Well, here is deal. I ended up creating my own debounce mechanism. The only issue is that I am defining 'button' (please see code). Now, in my interrupt I call my debounce function but I need to pass it 'button'. How can I do it without changing the 'type' of 'button'
Please see attached code. Thanks
Please see attached code. Thanks
Code:
#define buttonz PORTA.B0 //define 'button' at pin0 of port A
void button_debounce(const which_button){ // function for button
if (which_button==0){ //if button is pressed, wait for 7ms to settle
Delay_ms(7); //deboucne
if (which_button==0){ // now check again. Indeed the button
while(!which_button); //is pressed and wait for release
PORTA.B2=~PORTA.B2;} //toggle LED
}
}
void timer (void){
OPTION_REG=0x08; //assign TMR0 clock source (OSC/4) and prescaler to WDG
INTCON=0xA0; //Enable global interrupt and TMR0 interrupt
TMR0=0; //initialize the TMRO tick value
}
unsigned int x=0;
void main() {
OSCCON=0x74; //set up oscillator at 8Mhz
ADCON1=0x06; //configure all A ports as digital
timer(); //configure timer0
TRISA.B0=1; //set RA0 as input
TRISA.B2=0; //set RA2 as output--LED to show shit is working
PORTA.B2=0; //keep LED off
}
void interrupt(void){
x++;
if (x==100){ // wait for 10 ms and check the status of the button
button_debounce(buttonz); // my switch_check + plus debounce
x=0;} // reset and repeat
TMR0IF_BIT=0;
}