; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; LOW port (in w), pin ; Outputs a low to 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 Low. 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 ; clear 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 clear using Low. start MOVLW d'0' ; All outputs on rb. TRIS 6h MOVLW d'0' ; All outputs on rc. TRIS 7h MOVLW d'255' ; Start with 1s on rb, rc (all LEDs on). MOVWF 6h MOVLW d'255' 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 Low CALL delay ; Wait a while between lows. 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 Low, put the pin number into the variable pin ; and the port number into w. Then call Low. Low 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. XORLW 0xFF ; Invert it so there's a 0 in selected bit. ANDWF indirect ; Turn off the selected bit RETLW 0h ; Delay routine for demonstration. Not required by Low. delay DECFSZ temp ; Time delay to provide spacing GOTO delay DECFSZ temp2 ; between highs. GOTO delay RETLW 0h end