Delay movlw d'39' ; load this to the timer
Loop btfss _intcon,2 ; if tmr0 overflow is not set
goto Loop ; loop, else skip
bcf _intcon,2 ; clear the timer interrupt flag
decfsz w,w ; loop until the wreg is zero
goto Loop ; it isn't zero so loop
return ; zero, so we return
Not sure why this doesn't seem to work. My thinking is as follows:
Clock speed of 4000000Hz/4 = 1000000hz
This 1/4th value is further divided by my pre-scaler of choice /256: 1000000hz/256 = 3906.25hz
3906.25 pulses take 1 second - so to count 10ms delay we need to count when this has tripped over 39 times. To prove this 1/3906.25 = 2.56x10-4 * 39 = 9.98ms.
Right or wrong? Is there anything else needed to get the TMR0 overflow to work?
Why not simply use the delay code generator on the PICList to generate delay code for you? - it's far more versatile!.
Are you sure you are setting everything up correctly?, you've only posted a small piece of the code, so there's no indication of how it's set up at all.
I took a quick glance at your code. You can't use the ff. sequence because the W register is not a regular file register.
Code:
decfsz w,w ; loop until the wreg is zero
goto Loop ; it isn't zero so loop
It will compile without error but because the value of W is defined as "0", the register that will be accessed will be the INDF register. You have to use a real file register instead of W.