I have been experimenting with a PIC 12F508 and have just begun writing my own delay loops in assembler. Nothing fancy yet just toggling an LED connected to GP1 (set as an output) on and off to verify the code.
I finally got my loop to work but I don't understand why it has to be written a certain way for it to work.
I have copied part of the code that doesn't work below I omitted the input / output TRIS setup and configuration bits for clarity.
When the code is written as it is below and dly4 loops back on itself the LED doesn't flash it just stays on solid.
I can't understand why this is because according to the datasheet after the variable count4 reaches 0 the goto dly4 should be skipped. The next instruction goto main_loop should then be executed which returns to the start of the code toggles the led again and the process repeats.
main_loop movf sGPIO,w xorlw b'000010' ; toggle LED on GP1 movwf sGPIO movwf GPIO movlw .80 movwf count movwf count2 movwf count3 movwf count4 dly1 decfsz count,f goto dly1 dly2 decfsz count2,f goto dly2 dly3 decfsz count3,f goto dly3 dly4 decfsz count4,f goto dly4 goto main_loop END
To make the code work I have to modify the goto at the end of the loop from:
goto dly4 to goto dly1
Why would I want to go back through all four loops again? Wouldn't decrementing the variables from 0 by going through again reset them to 255? Even though the code works with the modification above I can't understand how the loop is even being exited.
Thanks For Any Help In Advance.