The following code executes correctly on a PIC16F877A at 20 MHz but not on a PIC18F8722 at 10 or 40 MHz:
Please note:Code:clear DEFINE OSC 40 ' Run on PIC18F8722 using HSPPL ADCON1 = $0F ' Set PortA to digital TRISB=0 ' Make Port B outputs PORTB=0 ' Clear the port X var byte Loop: PORTB=$0 FOR X = 0 to 3 IF X<1 THEN PORTB=$F0 IF X>1 AND X<3 THEN PORTB=$3C IF X>2 THEN PORTB=$0F PAUSE 1000 NEXT X GOTO Loop
1. With two IF...THENs inside the loop - all is OK.
2. I know that it would be easier to use
IF X=1 THEN....
IF X=2 THEN...
Etc, but this is a simplification of my real code.
3. I've tried a lot of variations but anything with multiple (>2) IF....THENs inside the loop will not work.
4. LEDs on PORTB work OK with
FOR X=0 TO 255
PORTB=X
NEXT X
5. Going nuts on this. What am I missing?
Regards Bill Legge
Bookmarks