; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; PULSOUT port, pin, time ; Generates an output pulse in 10-cycle (10 us at 4 MHz) units, ; based on a 16-bit (1 to 65,535) value. The pulse is the reverse ; of the pin's state when pulsout is called. For instance, if the ; specified pin is initially 1, Pulsout will invert it to make a ; negative-going pulse. 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. pin Res d'1' ; Pin number to pulse (0-7). temp Res d'1' ; Temporary variables for time delay temp2 Res d'1' ; between pulses ; Device data and reset vector org 0 ; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b). Pinz ADDWF pcl RETLW d'1' RETLW d'2' RETLW d'4' RETLW d'8' RETLW d'16' RETLW d'32' RETLW d'64' RETLW d'128' start MOVLW d'0' ; All outputs. TRIS 5h CLRF 5h ; Start with 0s. MOVLW d'10' ; 10 x 10-cycle pulse MOVWF lowB CLRF hiB MOVLW d'2' ; Pin 2. MOVWF pin MOVLW d'0' ; of port ra. CALL Pulsout ; Pulse pin high for 100 cycles. CALL delay ; Wait a while between pulses. GOTO start ; Do it again. ; Upon entry, the desired pin must already be set up as an output. ; The w register contains a number representing the output port (0-2) for ; RA through RC. Variable "pin" contains the pin number (0-7). The variables ; hiB and lowB are the MSB and LSB of the time argument. Pulsout MOVWF fsr ; Point to the port number. MOVLW 5h ; Add offset for port RA. ADDWF fsr MOVF pin,w CALL Pinz ; Get bit mask from the table. MOVWF pin ; Put the mask into pin 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. MOVF pin,w ; Invert the selected pin. XORWF indirect ; The main timing loop. Remove the nops for 5-cycle resolution. Pulsout_loop GOTO $+1 ; Two-cycle "nop." GOTO $+1 ; Two-cycle "nop." NOP INCF lowB ; lowB = lowB+1. BTFSC status,z ; Overflow in lowB? INCFSZ hiB ; Yes: hiB=hiB+1, watch for overflow. GOTO Pulsout_loop ; If not overflow, do it again. MOVF pin,w ; Invert pin (back to initial state). XORWF indirect RETLW 0h ; Delay routine for demonstration. Not required by Pulsout. delay DECFSZ temp ; Time delay to provide spacing GOTO delay DECFSZ temp2 ; between pulses. GOTO delay RETLW 0h end