Something like this. If there is a switch on RB0 then there are two ways depending upon how switch is connected.
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
if(PORTBbits.RB0){
_delay_ms(50);while(PORTBbits.RB0);//do what you want here}if(!PORTBbits.RB0){
_delay_ms(50);while(!PORTBbits.RB0);//do what you want here}
Let's say I would like to connect it to an LED and that whenever the output is high (which is 1), the led will light up.
How do I do that in the script?
*P.S. Is it possible if you could come up with the full working script. I'd appreciate it a lot.
Try this code. Connect an LED to PORTD.7, connect one end of switch to PORTD.0 and other end to +5V. Also connect one end of a resistor to PORTD.0 and other end to GND.