I found that all the PORTC LEDs would alternate ON and OFF as expected with the exception of LED RC2. It remains off. I checked the LED using the push button and the LED lights when the button is depressed. I also put a scope on pin RC2 and there is NO alternating state.
I then decided to use the new ICD function of the board (GREAT!). This is what I found the code doing on the chip.
First the code:
Code: Select all
program USARTSCOPE;
begin
//uses 18F4620 at 8 Mhz
TRISC := %00000000; //All pins output
PORTC := $FF; //Turn all LEDs ON
Repeat
PORTC := NOT PORTC; //Inverse Condition of LEDs
Until 1 = 2;
end.
after TRISC := %00000000;
TIRSC = 0000 0000 //this is as expected
PORTC = 1000 0000
after PORTC := $FF line debugger shows
PORTC = 1100 0000//Apparently garbage
WREG = 1111 1111 //loading FF into working Register before sending it to portC
After PORTC := NOT PORTC;
*****************************************
PORTC = 1111 1011//Here is why my LED RC2 is not lighting!!! For some reason the WREG does not transfer 1111 1111 which would light all LEDs but instead sends 1111 1011
Wreg := 1111 1111//still shows FF in working register - so why didn't it transfer correctly to PORTC??????
******************************************
On the second time through the repeat loop PORTC := NOT PORTC correctly gives
PORTC = 0000 0000
However, each time when the PORTC := NOT PORTC should give a
PORC = 1111 1111, it instead incorrectly gives 1111 1011 and RC2 LED never lights.
So the ICD debugger clearly show that RC2 LED does not light because it never gets its bit set, but the question is why does this not happen.
I switched the chip for a different 18F4620 in case there was a problem with the first chip - but I get the same results.
Any illumination would be appreciated