Ok, with the code below, i dont get how it makes a delay of 250ms
Code:
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end
from my understanding
decrement 1 form counta and keep repeating till counta is 0
when it is 0, dec 1 from countb, this wastes 200 cycles, (0xc7=199, and 0x01 = 1, so 1 + 199 =200)
when you have taken the 1 away from countb, it equals 0, so skips to decfsz count1, which decriments 1 from count1 and then jumps back up to d1, and this happens 250 times (because count1 is 250) until count1 is equal to 0, which it then reurns to program
so the delay is 200x250, so wastes 50,000 clock cycles
and the frequency of the pic is 4mhz, which gets divided by 4 by the pic,
so it is actually running at 1mhz
so is running 1,000,000 instructions a second,
so how is 50,000 missed causing a 250ms delay?
what have i done wrong?