| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
list p=18f452 ; list directive to define processor |
| 7 |
include <p18f452.inc> ; processor specific variable definitions |
| 8 |
include <coff.inc> ; Grab some useful macros |
| 9 |
radix dec ; Numbers are assumed to be decimal |
| 10 |
|
| 11 |
GLOBAL DelayCycles |
| 12 |
GLOBAL Delay256N |
| 13 |
GLOBAL Delay4 |
| 14 |
GLOBAL Delay5 |
| 15 |
GLOBAL Delay6 |
| 16 |
GLOBAL Delay7 |
| 17 |
GLOBAL Delay8 |
| 18 |
GLOBAL Delay9 |
| 19 |
|
| 20 |
DELAY_CODE CODE |
| 21 |
|
| 22 |
;------------------------------------------------------------ |
| 23 |
; DelayCycles: |
| 24 |
; |
| 25 |
; Input: W -- the desired delay |
| 26 |
; Output: Returns after W+7 cycles |
| 27 |
|
| 28 |
DelayCycles: |
| 29 |
|
| 30 |
dc1: ADDLW -3 ;3-cycle delay loop |
| 31 |
BC dc1 |
| 32 |
|
| 33 |
; W now contains either -3 (0xFD), -2 (0xFE) or -1 (0xFF). |
| 34 |
; The -2 case needs to be delayed an extra cycle more than |
| 35 |
; the -3 case, and the -1 case needs yet another cycle of delay. |
| 36 |
; |
| 37 |
; Examine the bottom two bits and W to determine the exact delay |
| 38 |
; |
| 39 |
|
| 40 |
BTFSS WREG,1 |
| 41 |
BRA dc2 ;W=0xFD - no extra delay needed |
| 42 |
RRCF WREG,F |
| 43 |
BC dc2 |
| 44 |
dc2: RETURN |
| 45 |
|
| 46 |
Delay256Loop |
| 47 |
RCALL Delay4 |
| 48 |
Delay256N: |
| 49 |
RCALL dc3 |
| 50 |
|
| 51 |
DECFSZ WREG,F |
| 52 |
bra Delay256Loop |
| 53 |
Delay5 NOP |
| 54 |
Delay4 RETURN |
| 55 |
|
| 56 |
dc3: RCALL Delay64 |
| 57 |
RCALL Delay32 |
| 58 |
RCALL Delay16 |
| 59 |
RCALL Delay8 |
| 60 |
NOP |
| 61 |
Delay128 RCALL Delay64 |
| 62 |
Delay64 RCALL Delay32 |
| 63 |
Delay32 RCALL Delay16 |
| 64 |
Delay16 RCALL Delay8 |
| 65 |
Delay8 nop |
| 66 |
Delay7 nop |
| 67 |
Delay6 bra Delay4 |
| 68 |
Delay9 bra Delay7 |
| 69 |
|
| 70 |
END |
| 71 |
|