puts the controller into a "do-nothing" delay loop for 1 to 65535 units of 1000 instruction cycles (milliseconds at 4 MHz).
Precise time delays are an important part of most control program, since they allow the controller to synchronize with slower, real-world events.
Pause accepts a 16-bit number in hiB and lowB, and puts the controller into a do-nothing loop for that number of 1000-instruction-cycle units. With a 4-MHz clock (as in the BASIC Stamp) this amounts to time delays ranging from 1 to 65,535 milliseconds.
The routine requires a little processing time in addition to the internal delay loop, so the actual delay produced will always be 16 instruction cycles longer than specified. This amounts to an error of less than 2 percent for a 1-unit delay, and 0.24 parts per million for a 65,535-unit delay.
To see Pause in operation, either run the program with the PSIM simulator, or connect the circuit below to an erasable PIC or PIC emulator, such as the Parallax downloader. Assemble and run PAUSE.SRC. When you apply power to the PIC, the LED will toggle once per second (assuming a 4 MHz clock). Try changing the value passed to Pause to adjust the flashing rate.
; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.bubblesoftonline.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; PAUSE time ; A general-purpose delay routine that puts the PIC into a do-nothing ; loop for a 16-bit number of milliseconds (1 to 65535) at 4 MHz. Requires ; 16 cycles of overhead for call, return and other processing. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 hiB Res d'1' ; MSB of time. lowB Res d'1' ; LSB of time. temp Res d'1' ; temporary counter for Pause ; Device data and reset vector org 0 start MOVLW d'0' ; Output through RB. TRIS 6h MOVLW d'3' ; Length of delay = MOVWF hiB MOVLW 0x00E8 ; 3E8h (1000 ms @ 4MHz). MOVWF lowB MOVLW d'255' ; Toggle LED(s). XORWF 6h CALL Pause ; Wait 1 second. GOTO start ; Do it again. ; Upon entry, variables hiB and lowB hold the MSB and LSB of the ; number of milliseconds (1 to 65535) to delay. Pause COMF hiB ; Take twos complement COMF lowB ; of the 16-bit counter INCF lowB BTFSC status,z ; If zero, lowB overflowed, INCF hiB ; so carry into hiB. Pause_load MOVLW d'248' ; Set up for 1-ms loop. MOVWF temp Pause_loop NOP ; Do nothing. DECFSZ temp ; Do more nothing. GOTO Pause_loop GOTO $+1 ; 2-cycle "nop" INCF lowB ; lowB = lowB+1. BTFSC status,z ; Overflow in lowB? INCFSZ hiB ; Yes: hiB=hiB+1, overflow?. GOTO Pause_load ; No overflow: do it all again. RETLW 0h ; Overflow. Return to caller. end
; PAUSE time ; A general-purpose delay routine that puts the PIC into a do-nothing ; loop for a 16-bit number of milliseconds (1 to 65535) at 4 MHz. Requires ; 16 cycles of overhead for call, return and other processing. device pic16c55,xt_osc,wdt_off,protect_off reset start org 8 hiB ds 1 ; MSB of time. lowB ds 1 ; LSB of time. temp ds 1 ; temporary counter for Pause ; Device data and reset vector org 0 start mov !rb, #0 ; Output through RB. mov hiB,#3 ; Length of delay = mov lowB,#0E8h ; 3E8h (1000 ms @ 4MHz). XOR rb,#255 ; Toggle LED(s). call Pause ; Wait 1 second. jmp start ; Do it again. ; Upon entry, variables hiB and lowB hold the MSB and LSB of the ; number of milliseconds (1 to 65535) to delay. Pause NOT hiB ; Take twos complement NOT lowB ; of the 16-bit counter INC lowB snz ; If zero, lowB overflowed, inc hiB ; so carry into hiB. :load mov temp,#248 ; Set up for 1-ms loop. :loop nop ; Do nothing. djnz temp,:loop ; Do more nothing. jmp $ + 1 ; 2-cycle "nop" inc lowB ; lowB = lowB+1. snz ; Overflow in lowB? incsz hiB ; Yes: hiB=hiB+1, overflow?. jmp :load ; No overflow: do it all again. ret ; Overflow. Return to caller.
See also:
Questions:
file: /Techref/microchip/seepicsrc/psbpix/pause.htm, 6KB, , updated: 2004/2/25 17:40, local time: 2024/11/23 00:58,
3.149.254.25: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? <A HREF="http://techref.massmind.org/Techref/microchip/seepicsrc/psbpix/pause.htm"> microchip seepicsrc psbpix pause</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.