Ok, honestly I am getting more confused here. I know that PORTDbits:RD1 = 1; will turn on the led. But how do my microcontroller knows that the push button has already pressed once before?
Yes, you can read the output as I said before. If you're only waiting for the button to be pressed, then you don't need to loop as the LED will stay on. Just poll the input RA4.
ARGHHH, I am getting more and more confused!!! Can you just please give me examples how can I program my LED so that when I pressed it once it stays ON forever??? BIG thanks!
First part is a way to read a key and only execute the code if the key has just been pressed. So it will execute the code in the braces once per key press.
Second part is a way to change the LEDs. If there off they go on. If there on they go off.
Put the two together and you have the functionality that you asked about.
BTW, you have changed your requirements from your earlier question.
Your original question was,
When I pressed it once, LEDS switched on forever until I pressed the push button again, then LEDS switched off.
Pushbuttons are mechanical devices and when you press them the contacts can bounce for a few milliseconds.
I used the PICkit2 LA tool on my Junebug kit to capture a switch bounce. **broken link removed**