please dont rip this site

PIC Microcontoller Time Method

Delays

Code generator  for Delays by Nikolai Golovchenko Wow!

Timer@

General Delay Methods

Counting Hours Minutes and Seconds

Stack Recursive Delay

PIC 16 Delay Tutorial by Vasily Koudymov

Delay Subroutines

Are there simulation problems with delays?

Macro Examples

James Newton says:

I also wrote this god-awful macro for the Parallax SX key asembler that may be of use to someone: It produces the smallest and/or tightest loop delays inline when you call it with the value and units of time you wish to delay for; calculating the number of cycles based on the processor speed. The CpuMhz equate must be adjusted to what ever is right for your chip. It should probably be called CpuMips vice CpuMhz. The only redeming virtue is that it does not use anything other than w (on the SX you can decrement W); no stack use, no register use. :
	device	pins28, pages1, banks8, turbo, stackx, optionx, carryx
	reset reset_entry
CpuMhz = 50
temp	ds	1
usec	EQU	-6
msec	EQU	-3
sec	EQU	1
cycles	EQU	0

mynop	MACRO
	noexpand
	page $>>8
	ENDM

cyclefor MACRO 1
_cycles = \1
IF _cycles > 0
_temp	=	$//4
IF _temp = 2
 IF _cycles <5 
	REPT _cycles 
	expand 
	mynop 
	noexpand 
	ENDR _cycles = 0 
  ELSE 
	expand 
	mynop 
	noexpand 
	_cycles = _cycles -1 
	ENDIF 
    ENDIF 
IF _temp = 1 
    IF _cycles < 6 
	REPT _cycles 
	expand 
	mynop 
	noexpand 
	ENDR 
	_cycles = 0 
    ELSE 
	expand 
	mynop 
	mynop 
	noexpand 
	_cycles = _cycles -2 
	ENDIF 
    ENDIF 
IF _cycles > 3
	expand
	 mov w, #_cycles / 3
	 decsz 1	;dec w
	 clrb 2.1       ;modify PC to jump back
	noexpand
 _cycles = _cycles // 3 ;cycles left over
 ENDIF
IF _cycles > 0
  REPT	_cycles
	expand
	 mynop
	noexpand
   ENDR
 ENDIF
ENDIF
	ENDM

reset_entry
	mov w,#$7F
	mov !OPTION,w

delayhelp MACRO
	ERROR 'USAGE: delay value, [usec,msec,sec,cycles]'
	ENDM

delay	MACRO	2
noexpand
IF (\2=usec OR \2=msec OR \2=sec) AND (\1<1000 AND \1>0)
 IF \2=sec
  _cycles = (\1 * 1000000 / (1000/CpuMhz))
  ENDIF
 IF \2=msec
  _cycles = (\1 * 1000 / (1000/CpuMhz))
  ENDIF
 IF \2=usec
  _cycles = (\1 / (1000/CpuMhz))
  ENDIF
 IF \2=cycles
  _cycles = \2
  ENDIF
 IF _cycles = 0
  expand
	 ;delay less than one cycle at this processor speed'
  noexpand
 ELSE
  IF _cycles > 255
   REPT (_cycles / 256)
    cyclefor 256
    _cycles = _cycles - 256
    ENDR
   ENDIF
  cyclefor _cycles
  ENDIF

ELSE
	delayhelp
ENDIF
	ENDM

	delay 999, usec
	delay 200, usec
	delay 250, usec
	delay 10, usec
	delay 20, usec
	delay 100, msec

See Also:

See:

Archive:

Questions:

Code:

Comments:


file: /Techref/microchip/delays.htm, 7KB, , updated: 2021/5/6 13:34, local time: 2024/11/17 05:22,
TOP NEW HELP FIND: 
18.118.162.128:LOG IN

 ©2024 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! / MAKE!

<A HREF="http://linistepper.com/techref/microchip/delays.htm"> PIC Microcontoller Time Method </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 a nice message (short messages are blocked as spam) 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: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?