stephansavic
Newbie level 2
So I wanna control 2 LED's with Microcontroller.
I am using PIC16F819.
Here's the code :
I am using pull-up resistor 4,7kOhm.
RA1 is LED1.
RA2 is LED2.
RA0 is input pin.
It seems that I can't change state.
Pushbutton works only when it's pressed once ( if I press it for the 1st time,then he switches the LED's ).
Can you tell me where I'm wrong?
Thanks in advance!
I am using PIC16F819.
Here's the code :
Code:
void main()
{
int counter,state,last;
TRISA=0;
TRISB=0;
PORTB=1;
PORTA=0b00000001;
ADCON1=7;
OSCCON=0b01100000;
counter=0;
state=1;
last=1;
while ( 1 == 1 )
{
state=RA0_bit;
if ( state != last && state == 0 ) counter++;
if ( counter % 2 == 0 ) { RA2_bit=0; RA1_bit=1; }
else
if ( counter % 2 == 1 ) { RA1_bit=0; RA2_bit=1; }
last=state;
}
}
RA1 is LED1.
RA2 is LED2.
RA0 is input pin.
It seems that I can't change state.
Pushbutton works only when it's pressed once ( if I press it for the 1st time,then he switches the LED's ).
Can you tell me where I'm wrong?
Thanks in advance!