; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; BRANCH offset (in w), jump table ; Jumps to the routine corresponding to offset in the jump table. ; Makes evaluating compound logic expressions easy. ; Since this example uses data straight from port RA, it could move RA ; into w, then go to the jump table. However, we're using a separate variable ; to demonstrate the technique. ; Device data and reset vector P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 flags Res d'1' ; Variable to hold bits. temp Res d'1' ; Variables for delay temp2 Res d'1' ; in Action. A equ ; Tflags.0he elements of our B = flags.1 ; compound logic expression. C_ equ ; "flags.2C" is carry bit D equ flags.3 org 0 start MOVLW d'255' ; All inputs for switches. TRIS 5h MOVLW d'0' ; All outputs for LEDs TRIS 6h CLRF 6h ; Ensure that LEDs are off. CLRF flags ; Initialize flags. ; For the sake of the example, we'll move each bit into place separately. ; However, always look for opportunities to move several bits at a time. ; For example, the four movb operations below could be replaced with ; mov flags,ra. Make sure that you strip off any extraneous bits if you use ; a port that is wider than the desired number of bits. Get_bits BTFSS 5h,d'0' ; Move bits of ra into flags. BCF flags,d'0' BTFSC 5h,d'0' BSF flags,d'0' BTFSS 5h,d'1' BCF flags,d'1' BTFSC 5h,d'1' BSF flags,d'1' BTFSS 5h,d'2' BCF flags,d'2' BTFSC 5h,d'2' BSF flags,d'2' BTFSS 5h,d'3' BCF flags,d'3' BTFSC 5h,d'3' BSF flags,d'3' ; We want to jump to Action IF A AND (B OR C) BUT NOT D. ; That corresponds to the bit patterns 0111, 0101 and 0011, ; (see diagram below) table entries 7, 5 and 3. ; Bits: | D | C_ | B | A | ; Flags: | flags.3 | flags.2 | flags.1 | flags.0 | ; BRANCH (cont) Branch MOVF flags,w ; Move flags into w. ADDWF pcl ; Table of 16 possible actions. GOTO Get_bits ; DCBA=0000: try again. GOTO Get_bits ; DCBA=0001: try again. GOTO Get_bits ; DCBA=0010: try again. GOTO Action ; DCBA=0011: Action! GOTO Get_bits ; DCBA=0100: try again. GOTO Action ; DCBA=0101: Action! GOTO Get_bits ; DCBA=0110: try again. GOTO Action ; DCBA=0111: Action! GOTO Get_bits ; DCBA=1000: try again. GOTO Get_bits ; DCBA=1001: try again. GOTO Get_bits ; DCBA=1010: try again. GOTO Get_bits ; DCBA=1011: try again. GOTO Get_bits ; DCBA=1100: try again. GOTO Get_bits ; DCBA=1101: try again. GOTO Get_bits ; DCBA=1110: try again. GOTO Get_bits ; DCBA=1111: try again. ; When the switches on port RA are in the correct combination, ; the LEDs on port RB blink. Action MOVLW d'255' ; Toggle LEDs. XORWF 6h Action_loop DECFSZ temp ; Short delay. GOTO Action_loop DECFSZ temp2 GOTO Action_loop GOTO Get_bits ; Resume checking RA. end