cllunlu
Member level 4

Hi Everyone,
I use pic18f24k50 microcontroller and wanna use RC1 and RC2 pin as input with button. When button1 that is connected RC1 is pressed, led1 that is connected RA1 will be on. And when button2 that is connected RC2 is pressed, led1 that is connected RA2 will be on.
I write code is below. when button1 is pressed, led is on. but when I press button2, dont change any situation led2. it always on.
I check many times hardware and connections and dont any mistake. The first RC2 pin is 5V when I pressed button RC2 is 0V. but pic18f24k50 doesnt detect it.
I think, fuse and settings may be wrong.
void main()
{
TRISA=0x00;
TRISB=0x00;
TRISC=0XFF;
ADCON1 =0x07;
for(;
{
if(PORTC.B1==0)
{
PORTA.B0=1;
PORTB.B3=1;
}
else
{
PORTA.B0=0;
PORTB.B3=0;
}
if(PORTC.B2==0)
{
PORTA.B1=1;
PORTB.B3=1;
}
else
{
PORTA.B1=0;
PORTB.B3=0;
}
}
}
my circuit
https://obrazki.elektroda.pl/5347806500_1431118149.png
Anyone can help me about Project settings in mikroC.
Thanks
I use pic18f24k50 microcontroller and wanna use RC1 and RC2 pin as input with button. When button1 that is connected RC1 is pressed, led1 that is connected RA1 will be on. And when button2 that is connected RC2 is pressed, led1 that is connected RA2 will be on.
I write code is below. when button1 is pressed, led is on. but when I press button2, dont change any situation led2. it always on.
I check many times hardware and connections and dont any mistake. The first RC2 pin is 5V when I pressed button RC2 is 0V. but pic18f24k50 doesnt detect it.
I think, fuse and settings may be wrong.
void main()
{
TRISA=0x00;
TRISB=0x00;
TRISC=0XFF;
ADCON1 =0x07;
for(;
{
if(PORTC.B1==0)
{
PORTA.B0=1;
PORTB.B3=1;
}
else
{
PORTA.B0=0;
PORTB.B3=0;
}
if(PORTC.B2==0)
{
PORTA.B1=1;
PORTB.B3=1;
}
else
{
PORTA.B1=0;
PORTB.B3=0;
}
}
}
my circuit
https://obrazki.elektroda.pl/5347806500_1431118149.png
Anyone can help me about Project settings in mikroC.
Thanks