smiles
Advanced Member level 4
is there anyway that I input a number, for i.e 123, than we have a 123ms delay ?
Thanks !!!
Can we utilize this code for that purpose ?
Thanks !!!
Can we utilize this code for that purpose ?
Code:
Dly0 res 1 ;Stores 4 bytes of data for the delay count
Dly1 res 1 ;Dly0 is the least significant byte
Dly2 res 1 ;while Dly3 is the most significant byte
Dly3 res 1
Dly32 MACRO DLY
goto $+1 ;delay 2 cycles
goto $+1 ;delay total of 4 cycles
;Take the delay value argument from the macro, precalculate
;the required 4 RAM values and load the The RAM values Dly3
;though Dly0.
BANKSEL Dly3
movlw (DLY-1) & H'FF'
movwf Dly0
movlw (DLY-1) >>D'08' & H'FF'
movwf Dly1
movlw (DLY-1) >>D'16' & H'FF'
;Bytes are shifted and anded by the assembler to make user
;calculations easier.
movwf Dly2
movlw (DLY-1) >>D'24' & H'FF'
;Call DoDly32 to run the delay loop.
movwf Dly3
call DoDly32
ENDM ;End of Macro definition
RST CODE 0x00 ;Reset Vector
pagesel TestCode
goto TestCode
CODE ;Code starts here
TestCode
Dly32 D'50000' ; 50000x20microseconds than we have 1s delay
nop
goto TestCode ;Go back to top of program and
;run the delay again.
;Subroutine, called by the Macro Dly32 (20 microseconds per loop)
DoDly32
movlw H'FF' ;Start with -1 in W
addwf Dly0,F ;LSB decrement
btfsc STATUS,C ;was the carry flag set?
clrw ;If so, 0 is put in W
addwf Dly1,F ;Else, we continue.
btfsc STATUS,C
clrw ;0 in W
addwf Dly2,F
btfsc STATUS,C
clrw ;0 in W
addwf Dly3,F
btfsc STATUS,C
clrw ;0 in W
iorwf Dly0,W ;Inclusive-OR all variables
iorwf Dly1,W ;together to see if we have reached
iorwf Dly2,W ;0 on all of them.
iorwf Dly3,W
btfss STATUS,Z ;Test if result of Inclusive-OR's is 0
goto DoDly32 ;It was NOT zero, so continue counting
retlw 0 ;It WAS zero, so exit this subroutine.
END