please dont rip this site

PIC Microcontoller Delay Method


Delay X cycles (16-65551) inclusive by Mike McLaren, K8LH

Here's a 16-bit DelayTcy routine for 16F' and 12F' devices with a 14-bit instruction core. The basic routine has 4 cycle loop timing and uses 12 words of program memory and 1 byte of data (RAM) memory. The DelayTcy macro does much of the work by preprocessing the passed "delay" constant parameter value during assembly.

;******************************************************************
;                                                                 *
;  DelayTcy(), 16..65551 Tcy         Mike McLaren, K8LH, June'07  *
;                                                                 *
;  requires the use of constant operands known at assembly time!  *
;                                                                 *
;  12 words, 1 RAM variable, 14-bit core                          *
;                            ^^^^^^^^^^^                          *
;  calling macro produces 4 instructions;                         *
;                                                                 *
DelayTcy macro  delay           ; parameter range 16..65535
        movlw   ~(high(delay-16))
        movwf   TMRH
        movlw   low(delay-16)
        call    DelayLo-(delay%4)
        endm
;                                                                 *
;  example code for simulation testing;                           *
;                                                                 *
SimTest DelayTcy(65551)         ; delay 'n' Tcy
        nop                     ; put simulator break point here
;                                                                 *
;       DelayTcy(Pulse)         ; Pulse is a constant             *
;       DelayTcy(Period-Pulse)  ; Period is also a constant       *
;                                                                 *
;******************************************************************
        nop                     ; entry point for delay%4 == 3
        nop                     ; entry point for delay%4 == 2
        nop                     ; entry point for delay%4 == 1
DelayLo addlw   -4              ; subtract 4 cycle loop time
        skpnc                   ; borrow?  yes, skip, else
        goto    DelayLo         ; do another loop
        nop                     ;
DelayHi addlw   -4              ; subtract 4 cycle loop time
        incfsz  TMRH,F          ; done?  yes, skip, else
        goto    DelayLo         ; do another loop
        goto    $+1             ;
        return                  ;
;******************************************************************




file: /techref/microchip/delay/8b1cr16m-mm.htm, 2KB, , updated: 2007/6/22 15:10, local time: 2008/8/28 22:27,
TOP NEW HELP FIND: 
38.103.63.61:LOG IN
©2008 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©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/delay/8b1cr16m-mm.htm"> PIC Microcontoller, Delay Method, Mike McLaren, K8LH</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be reviewed) Just type in the box and press the Post button. (HTML welcomed!): A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Did you find what you needed?

  PICList 2008 contributors:
o List host: MIT, Site host massmind.org, Top posters @20080828 Apptech, Jinx, Xiaofan Chen, olin piclist, Alan B. Pearce, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, Cedric Chang, David VanHorn,
* 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, Timothy Weber, on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .