Code:
Here's a delay routine optimized for the 18f family that delays exactly
7+N cycles, were N is a value passed in W. It uses no look up tables (like
similar routines for other devices), requires no extra RAM, and is only 7
instructions.
;------------------------------------------------------------
; DelayCycles:
;
; Input: W -- the desired delay
; Output: Returns after W+7 cycles
DelayCycles:
dc1: ADDLW -3 ;3-cycle delay loop
BC dc1
; W now contains either -3 (0xFD), -2 (0xFE) or -1 (0xFF).
; The -2 case needs to be delayed an extra cycle more than
; the -3 case, and the -1 case needs yet another cycle of delay.
;
; Examine the bottom two bits of W to determine the exact delay
;
BTFSS WREG,1
BRA dc2 ;W=0xFD - no extra delay needed
RRCF WREG,F ;If the LSB is set (W=0xFF) then set C
BC dc2 ;add a cycle delay for W=0xFF but not 0xFE
dc2: RETURN
Pic code... Just like the good ol' days!
Scott+
Archive:
| file: /techref/microchip/18Fdelay-sd.htm, 1KB, , updated: 2005/10/7 23:59, local time: 2008/7/5 06:05,
owner: JMN-EFP-786,
38.103.63.16:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/microchip/18Fdelay-sd.htm"> Delay X cycles (7-263) for 18F chips by Scott Dattalo</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20080705 Apptech, Jinx, Xiaofan Chen, Alan B. Pearce, David VanHorn, Bob Axtell, William \Chops\ Westfield, Cedric Chang, olin piclist, Gerhard Fiedler, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Larry Williams, David VanHorn, Bryan Whitehouse, Timothy Weber, David Challis. Peter Todd. on-going support is MOST appreciated! * Contributors: Neil Narwani, David Cary, Elemer AM Nyiry, Philip J Taylor, Gus Calabrese of Omegadogs.com, Gautama Venegas, Patrick B. Murphy, William Chops Westfield, Peter Todd, Leslie Ellis |
|
.