Searching \ for 'Delay Macro' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Delay Macro'.

Truncated match.
PICList Thread
'Delay Macro'
1997\10\21@145523 by Bob Fehrenbach

picon face
Sorry if this is off-topic in the PCB layout tools,
Canadian-as-a-second-language forum.

Some time back Andy Warren posted a cute macro that would insert
a delay of a specified number of cycles.  Recently in a little
12C508 project I needed a delay and rather than rool my own, I
thought of Andy's macro.  The problem is that the 12C508 does not
have a 'addlw' instruction.  Here is a version that avoids that
problem at the cost of using a register.

Maybe someone will find this useful.

;    From Andy Warren:
        ;His original comments:
;    Here's a macro that'll delay from 0 to 1027 cycles.  It uses no
;    registers (except W) and occupies from 0-7 words (5, on average)
;    of program space every time it's invoked.  If program space is
;    at a premium, it could be rewritten to call a subroutine.
;    To use this macro, just invoke it with a "WAIT N", where "N" is
;    the number of cycles you want to delay.

wait    macro   usecs
  local   x

  if ((usecs) > 1027)
  error "delay must be less than 1028 cycles!"

  if ((usecs) < 0)
  error "delay must be at least 0 cycles!"

x = (usecs)%4

  if (x == 1)

  if (x == 2)
  goto    $+1

  if (x == 3)
  goto    $+1

x = (usecs)/4

  if (x)

  if (x == 256)
x = 0

    ;original code                   modification   (uses count)

  movlw   x                            movlw   x
  addlw   -1  <- trouble               movwf   count
  skpz                                 decfsz  count, w
  goto    $-2                          goto    $-2



Bob Fehrenbach    Wauwatosa, WI

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...