bananasiong
New Member
Hi,mrfunkyjay said:Now the LED is turning on as always, wherever Power Supply is connected. Hmm... let me post my code here.
Code:#include <p18f4520.h> #include <delays.h> #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF char Previous; void main(void) { /*Settings*/ TRISD=0b00000000; TRISA=0b00010000; ADCON1=7; TRISB=0b00000001; Previous=PORTAbits.RA4; if(PORTAbits.RA4==0 && Previous==1) { PORTDbits.RD1 = ~PORTDbits.RD1; } }
These codes are just executed once, you should have a while (1) in the main for looping, all the initialize setting (eg TRIS or disable ADC) shoule be before the while loop. Like this:
Code:
void main(void)
{
/*Settings*/
TRISD=0b00000000;
TRISA=0b00010000;
ADCON1=7;
TRISB=0b00000001;
while (1)
{
//..... button is checked here, this is called polling
}
}