4electros
New Member
This section of code is taken from tutorial 1.2 of nigel tutorails:
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
The delay subroutine is supposed to make a delay of 1ms...I've calculated the time by myself and found that the dealay time is 994us not 1000us=1ms.
I don't know whether my calculation is wrong or the result is approximated to 1ms... what's the matter?!
I depend with my calculation upon considering the goto instruction takes 2 instruciton cycles and decfsz instruction only takes 1 instruction cycle.is that true?!
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
The delay subroutine is supposed to make a delay of 1ms...I've calculated the time by myself and found that the dealay time is 994us not 1000us=1ms.
I don't know whether my calculation is wrong or the result is approximated to 1ms... what's the matter?!
I depend with my calculation upon considering the goto instruction takes 2 instruciton cycles and decfsz instruction only takes 1 instruction cycle.is that true?!