; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; GOSUB sub, return address (in w) ; Jumps to the address in the variable sub after storing the return address on a ; stack in general-purpose RAM. When the destination routine is finished, it ; jumps to a routine called Return, which fetches the return address off the stack, ; and jumps to the instruction following the one that invoked Gosub. ; The Gosub/Return mechanism requires exclusive use of the file-select ; register (fsr). If other parts of the program need to use the fsr, ; copy it to a variable before altering it and restore it when done. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 sub Res d'1' ; Destination of Gosub. temp Res d'1' ; Variables for delays temp2 Res d'1' ; used in demo subroutines. ; Device data and reset vector org 0 start MOVLW d'0' ; All outputs for LEDs TRIS 6h CLRF 6h ; Turn LEDs off. MOVLW d'31' ; Point to end of memory MOVWF fsr MOVLW One ; Destination: One. MOVWF sub MOVF pc,w ; Save program counter. GOTO Gosub ; Gosub One. MOVLW d'15' ; LEDs on. MOVWF 6h start_loop DECFSZ temp ; Short delay. GOTO start_loop DECFSZ temp2 GOTO start_loop CLRF 6h ; LEDs off. GOTO $ ; Endless loop. Gosub MOVWF indirect ; Return addr on stack. DECF fsr ; Decrement stack pointer. MOVF sub,w ; Destination address to w. MOVWF pcl ; Go there. Return inc fsr ; Increment stack pointer INCF indirect,w ; w = return addr + 1. MOVWF pcl ; Jump to return addr. ; GOSUB (cont) ; Demonstration routines to show successful nesting of ; three Gosubs. One MOVLW d'1' ; LED on. MOVWF 6h One_loop DECFSZ temp ; Short delay. GOTO One_loop DECFSZ temp2 GOTO One_loop CLRF 6h ; LEDs off MOVLW Two ; Destination: Two. MOVWF sub MOVF pc,w ; Save program counter. GOTO Gosub ; Gosub Two. GOTO Return ; Return. Two MOVLW d'3' ; LEDs on. MOVWF 6h Two_loop DECFSZ temp ; Short delay. GOTO Two_loop DECFSZ temp2 GOTO Two_loop CLRF 6h ; LEDs off MOVLW Three ; Destination: Three. MOVWF sub MOVF pc,w ; Save program counter. GOTO Gosub ; Gosub Three GOTO Return ; Return. Three MOVLW d'7' ; LEDs on. MOVWF 6h Three_loop DECFSZ temp ; Short delay. GOTO Three_loop DECFSZ temp2 GOTO Three_loop CLRF 6h ; LEDs off GOTO Return ; Return. vö|Hƒþ}CkÞ#ƒ¿ÿt9Vjjj end