Hi,
Most likely read-modify-write issue as peja089 says.
If you remove the LEDs and measure the voltage on the pins you'll see that they all goes "high" and close to 5V (if that's your powersupply voltage). If you put the LEDs back you'll get the phenomenon you see and if measure the voltage you'll see that it's no longer 5V due the LED clamping the voltage.
A LED operate on current and produce a certain voltage drop across it. You must put a resistor in series with the LED to "set" the correct current. Simply wiring the LED to the PIC output pin like that does indeed light up the LED but the output voltage of the PIC will be clamped by the forward voltage drop of the LED which, depending on the color might be somewhere between 1.8 and 2.1V.
Now, for an input to be concidered "high" the voltage at the pin must be atleast 2V when the power supply voltage is 5V. Why does it matter, you're not using any inputs?
It matters because when you do HIGH PortB.2 the PIC reads all the bits in PortB into an internal register, it then sets bit 2 of that register "high" and finally writes the register back out to PortB (Read-Modify-Write). Because the voltage of the output pin is being clamped by the forward voltage drop of the LED the PIC reads that pin as low thus setting the output low when it writes back the internal working register to the port.
So, it's a hardware problem, not a software bug.
/Henrik.
Bookmarks