That code is difficult to read, here is how to make it understandable:
1. use code tags around the code, the '#' in the bar above the message window. It tells Edaboard not to reformat it so we see it as you wrote it.
2. instead of using addresses, please use names. For example, at the top of the program use:
Code:
cblock 0x20
delay_1
delay_2
delay_3
endc
then use the name delay_1 instead of 0x20, delay_2 instead of 0x21 and delay_3 instead of 0x22. Names make it clearer what the variable is supposed to do.
3. instead of ending variables with ",0" or ",1" use ",W" if the result goes back in the W register and ",F" if it goes back to the file register.
So the code nw looks like:
Code:
cblock 0x20
delay_1
delay_2
delay_3
endc
DELAY:
MOVLW 0xFF
MOVWF delay_1
LOOP:
DECFSZ delay_1,F
CALL DELAY1
RETURN
DELAY1:
MOVLW 0xFF
MOVWF delay_2
LOOP1:
DECFSZ delay_2,F
CALL DELAY2
GOTO LOOP1
RETURN
DELAY2:
MOVLW 0x3F
MOVWF delay_3
LOOP2:
DECFSZ delay_3,f
GOTO LOOP2
RETURN
4. software delays work by accumulating the time taken to execute each instruction but without knowing how long an instruction takes it is impossible to know the length of delay. You must tell us the clock speed you are using. Also note that other things, particularly interrupts can make the delay longer than expected.
Your code is not functionally incorrect but it isn't very efficicient. A better method is to group the three delays into one, basically remove the call and return instructions, except for the last return.
Brian.