Test Decfsz a,f
goto Test
Decfsz b,f
goto Test
Decfsz c,f
goto Test
I plug in this formula 3 X 3 X a X b X c cycles
but the actual timing is much longer than this. Have anyone cascaded 3 loops for delay before? How do I get the exact delay time from this loops? Thanks a lot for reading
Setup a simple project with just your delay code. Turn on the Simulator and the Stopwatch. If you're not familiar with these facilities it's time to start reading the MPLAB Help files.
Every time b is decremented a will be zero which will be decremented 256 times before it is zero again. Hence,
770 = 256*3+2
197122 = 256*770+2
the -197833 is to compensate for the fact that writing all 1's to the registers will cause it to drop straight through without any looping. 197833 = 3+770+197122-12 the 12 is the number of cycles to drop straight through.
I don't think loops can provide the EXACT part of your question. When an interrupt is serviced during your loops, they will be longer...
You don't have interrupts? Ok but it's still not good practice.
What if the user press a button while your in the delay loop? You will never see it.
You don't have buttons? Ok but still not good practice.