; delay - Macro for Delaying PICMicro Operations ; ; ; The subroutine produced by this include file is ; inserted after a label and either uses a TMR0 ; interrupt or constant delay. ; ; Dependancies: ; vars.inc ; ; Myke Predko ; 99.07.25 ; Dlay macro Speed, Delay ; "Delay" in usecs local RTCAdd ; Put after Subroutine Label ifndef RTCActual ; Is there a Timer Subroutine Present? ifndef _dlayHere VarAdd _dlay, 1 ; Delay Variable for Subroutine #define _dlayHere endif variable DlayCycles, HiDlay, LoDlay DlayCycles = (Delay * (Speed / 1000)) / (1000 * 28) HiDlay = (DlayCycles / 256) + 1 LoDlay = DlayCycles - ((HiDlay - 1) * 256) + 1 movlw HiDlay movwf _dlay movlw LoDlay xorlw 0x0FF ; Increment "w" by 1 addwf INTCON, w subwf INTCON, w btfsc STATUS, Z decfsz _dlay goto $ - 5 else ; Can Use RTC for the Delay ; RTCActual has the # of usecs per loop variable RTCAdd ; Value to Add to RTC to get the Update RTCAdd = (Delay / RTCActual) + 2 ; Number of Loops to Go ifndef RTCDlay #define RTCDlay VarAdd _dlay, 2 endif if RTCAdd > 0x0FF ; What Type of Loop Is there movlw (RTCAdd & 0x0FF) ; Set the Low B addwf RTC, w ; Update the Timer movwf _dlay movlw (RTCAdd & 0x0FF00) > 8 ; Set the Low B addwf RTC + 1, w ; Update the Timer movwf _dlay + 1 movf _dlay, w xorwf RTC, w btfss STATUS, Z goto $ - 3 movwf _dlay + 1, w xorwf RTC + 1, w btfss STATUS, Z goto $ - 7 else movlw (RTCAdd & 0x0FF) ; Set the Timer addwf RTC, w movwf _dlay movf _dlay, w ; Wait for the Update xorwf RTC, w btfss STATUS, Z goto $ - 3 endif endif return ; Return to Caller endm