Uptech19
Newbie level 2
Hello every one, I have been facing a problem regarding my code for PIC for quite a few days now,
I am new to PIC programming in microC since i have only worked on 8051 microcontrollers and keil,
I would really appreciate it if some one can kindly tell me what am I doing wrong in the code given below!
// code to switch on LED when push button at pin RA0 is pressed and off when it is released
sbit LED at RB0_bit;
sbit LED_Direction at TRISB0_bit;
sbit SW at RA0_bit;
sbit SW_Direction at TRISA0_bit;
void main()
{
ADCON1= 0x0F;
CMCON = 0x07;
LED_Direction = 0; // setting pin B0 as output
SW_Direction= 1 ; // setting pin A0 as input
TRISD= 0; // setting port D as output
while(1);
{
if (SW==0)
{
LED=1;
}
PORTD = 0xff;
Delay_1sec;
PORTD = 0x0f;
if (SW==1)
{
LED=0;
}
}
}
its a simple code to switch on and Off an LED when button is pressed but its not simulating in proteus!
thank you in advance
here is the proteus design
https://obrazki.elektroda.pl/27_1324276294.jpg
I am new to PIC programming in microC since i have only worked on 8051 microcontrollers and keil,
I would really appreciate it if some one can kindly tell me what am I doing wrong in the code given below!
// code to switch on LED when push button at pin RA0 is pressed and off when it is released
sbit LED at RB0_bit;
sbit LED_Direction at TRISB0_bit;
sbit SW at RA0_bit;
sbit SW_Direction at TRISA0_bit;
void main()
{
ADCON1= 0x0F;
CMCON = 0x07;
LED_Direction = 0; // setting pin B0 as output
SW_Direction= 1 ; // setting pin A0 as input
TRISD= 0; // setting port D as output
while(1);
{
if (SW==0)
{
LED=1;
}
PORTD = 0xff;
Delay_1sec;
PORTD = 0x0f;
if (SW==1)
{
LED=0;
}
}
}
its a simple code to switch on and Off an LED when button is pressed but its not simulating in proteus!
thank you in advance
here is the proteus design
https://obrazki.elektroda.pl/27_1324276294.jpg
Last edited: