hi.. i need help with this program. this is a program to turn 'ON' and 'OFF' 1 LED using 2 push buttons.
the underline statement suppose to wait for button press. but it is alway false even i have press the button. is there any one who can tell me what's wrong with the statement.. thank alot..
#include <p18f4620.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#define btn_on PORTBbits.RB4
#define btn_off PORTBbits.RB5
#define led PORTAbits.RA0
void on(void);
void off(void);
void Delay(void);
void main(void)
{
TRISA = 0; //set Port A(LED) as output
PORTAbits.RA0 = 0; //reset LED
Rpt:
[U] if (btn_on || btn_off)[/U] //wait for btn press
{
if (btn_on == 1) //btn on pressed
{
Delay(); //This is the real trick, Debounce the input!!
if (!btn_on) //btn on still pressed?
goto Rpt; //No
on();
}
if (btn_off == 1) //btn off pressed
{
Delay(); //This is the real trick, Debounce the input!!
if (!btn_off) //btn off still pressed?
goto Rpt; //No
off();
}
}
goto Rpt;
} //end main
void on(void)
{
Rpt_on:
while(btn_on); //wait for btn(RB4) released
Delay(); //debounce
if (btn_on) //btn on still released?
goto Rpt_on; //No
PORTAbits.RA0 = 0x0F; //on LED
} //end on
void off(void)
{
Rpt_off:
while(btn_off); //wait for btn(RB5) released
Delay(); //debounce
if (btn_off) //btn off still released?
goto Rpt_off; //No
PORTAbits.RA0 = 0x00; //off LED
} //end off
void Delay(void)
{
int i;
for(i=0; i<2048; i++);
}