Program J : ;************************************ ; written by : John Morton * ; date : 21/07/97 * ; version : 1.0 * ; file saved as : LogicGates * ; for PIC54 * ; clock frequency : 3.82 MHz * ;************************************ ; PROGRAM FUNCTION : To act as the eight different gates. list P=16C54 include "c:\pic\p16c5x.inc" ;============ ; Declarations : porta equ 05 portb equ 06 STORE equ 08 org 1FF goto Start org 0 ;=========== ; Subroutines : Init movlw b'1111' ; RA0 : secondary input, RA1-3 : gate select bits tris porta ; movlw b'00000001' ; RB0 : primary input, RB4 : output, tris portb ; RB1-3 and RB5-7 : not connected retlw 0 ;============= ; Program Start : Start call Init ; sets up inputs and outputs Main bcf STATUS, C ; makes sure Carry Flag is clear rrf porta, w ; bumps off bit 0, leaving the result in the ; working register addwf PCL, f ; adds this number to the program counter goto NOT ; the code for a NOT gate is received goto BUFFER ; the code for a BUFFER is received goto AND ; etc. goto IOR ; goto XOR ; goto NAND ; goto NOR ; goto XNOR ; NOT swapf portb, f ; swaps bit 0 for bit 4 (input for output) comf portb, f ; inverts the whole of port b (and thus also bit 4) goto Main ; loops back to Main BUFFER swapf portb, f ; swaps the input bit for the output bit. goto Main ; loops back AND movfw porta ; takes the number out of Port A andwf portb, w ; ANDs the number with Port B common1 movwf STORE ; stores result in a G.P. file register swapf STORE, w ; swaps nibbles and put result in working reg. movwf portb ; returns result to Port B goto Main ; IOR movfw porta ; takes the number out of Port A iorwf portb, w ; ANDs the number with Port B goto common1 ; goes to the section in AND which is repeated XOR movfw porta ; takes the number out of Port A xorwf portb, w ; ANDs the number with Port B goto common1 ; goes to the section in AND which is repeated NAND movfw porta ; takes the number out of Port A andwf portb, w ; ANDs the number with Port B common2 movwf STORE ; stores result in a G.P. file register swapf STORE, f ; swaps nibbles comf STORE, w ; inverts result and puts result in working reg. movwf portb ; returns result to Port B goto Main ; NOR movfw porta ; takes the number out of Port A iorwf portb, w ; ANDs the number with Port B goto common2 ; goes to NOTing section XNOR movfw porta ; takes the number out of Port A xorwf portb, w ; XORx the number with Port B goto common2 ; goes to NOTing section END