; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; TOGGLE port (in w), pin ; Toggles (inverts) the state of the specified port and pin. ; Device data and reset vector P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 pin Res d'1' ; Pin number to set (0-7). ; Variables for the demo program--not required by Toggle. p_index Res d'1' ; Copy of pin number, port number. temp Res d'1' ; Temporary variables for time delay temp2 Res d'1' ; between outputs. 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' ; The following demonstration code should show the value of being able to ; toggle a particular bit of a port based on a calculation performed while the ; program is running. As the variable p_index is incremented from 0 to 15, ; it is used to specify the pin and port to invert using Toggle. start MOVLW d'0' ; All outputs on rb. TRIS 6h MOVLW d'0' ; All outputs on rc. TRIS 7h MOVLW b'10101010' ; Put a pattern of alternating lights MOVWF 6h MOVLW b'10101010' ; onto rb and rc. MOVWF 7h CLRF p_index ; Clear p_index. start_loop MOVLW d'7' ; Copy three lsbs of p_index into MOVWF pin MOVF p_index ; variable pin. ANDWF pin MOVLW d'1' ; IF p_index.3 = 0 BTFSC p_index,d'3' ; THEN w = 1 MOVLW d'2' ; ELSE w = 2 CALL Toggle CALL delay ; Wait a while between toggles. INCF p_index ; Next pin/port. BTFSS p_index,d'4' ; IF p_index < 15 (rc.7) GOTO start_loop ; THEN :loop ELSE done done GOTO $ ; Endless loop. ; To use the routine Toggle, put the pin number into the variable pin ; and the port number into w. Then call Toggle. Toggle 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. XORWF indirect ; Invert the selected bit RETLW 0h ; Delay routine for demonstration. Not required by Toggle. delay DECFSZ temp ; Time delay to provide spacing GOTO delay DECFSZ temp2 ; between highs. GOTO delay RETLW 0h end end