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                  ;
;******************************************************************



Comments:


file: /techref/microchip/delay/8b1cr16m-mm.htm, 3KB, , updated: 2008/10/20 07:47, local time: 2009/1/8 12:01,
TOP NEW HELP FIND: 
38.103.63.57:LOG IN
©2009 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2009 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://techref.massmind.org/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 visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page): 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?

 

Welcome to massmind.org!

  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .