Hi,
I've got a problem I can't seem to wrap my head around...
The PIC I'm using is a 18F4520 and when I discovered the problem I was compiling with 2.6A but have now switched to 3.0.1.4

Running the following code:
Code:
DEFINE OSC 8
 
#CONFIG
    CONFIG OSC = HS
    CONFIG FCMEN = OFF
    CONFIG IESO = OFF
    CONFIG PWRT = ON
    CONFIG BOREN = OFF
    CONFIG WDT = ON
    CONFIG WDTPS = 512
    CONFIG CCP2MX = PORTC
    CONFIG PBADEN = OFF
    CONFIG LPT1OSC = OFF
    CONFIG STVREN = OFF   
    CONFIG MCLRE = ON
    CONFIG LVP = OFF
    CONFIG XINST = OFF
    CONFIG DEBUG = OFF
#ENDCONFIG
 
i VAR BYTE
 
High PortD.0 : Pause 500 : Low PortD.0
i = 0
 
Main:
  i = i + 1
  PauseUs 20
Goto Main
Everything works as expected, and with everything I mean nothing happens really. PortD.0 pulses on startup and then it sits there doing "nothing" (I've waited for ~5 minutes, you'll understand why soon.)

However, if I reduce the PauseUS to 10 or remove it completely the program restarts (PortD.0 pulses) roughly 22 times per second. (I know PauseUs 10 is border line on the specified miniumu of 9 for a 18F chip at 8Mhz) but why does it restart? And why does it restart if I remove it all together?

This works:
Code:
Main:
i = i + 1
If I = 255 Then i = 0
Goto Main
While this restarts the PIC once every 3rd second:
Code:
Main:
i = i + 1
Goto Main
The variable i is declared as a BYTE as can be seen above. It "feels" like it has something to do with i overflowing but why and why does it matter if I pause 20us?

What am I doing wrong here? 18F4520, PBP 3.0.1.4, MPLAB 8.73a/MPASM 5.42, compiling for the correct chip from MCSP 5.0.0.0.

Thanks!
/Henrik.