PROGRAM J ;************************************ ; written by : John Morton * ; date : 21/07/97 * ; version : 1.0 * ; file saved as : LogicGates * ; for PIC16F54 * ; clock frequency : 3.82 MHz * ;************************************ ; PROGRAM FUNCTION : To act as the eight different gates. list P=16F54 include "c:\pic\p16f5x.inc" __config _RC_OSC & _WDT_OFF & _CP_OFF ;============ ; 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 tris porta ; select bits 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 result in w andlw b'0011' ; masks all but bits 0 and 1 addwf PCL, f ; branches accordingly goto BufferNOT ; handles Buffers and NOTs goto ANDNAND ; handles ANDs and NANDs goto IORNOR ; handles IORs and NORs XORXNOR movfw porta ; takes Input B xorwf portb,w ; and XORs with Input A Common movwf STORE ; stores result btfsc porta, 3 ; tests inversion bit comf STORE, f ; inverts output if necessary swapf STORE, w ; moves result into bit 4 movwf portb ; outputs result goto Main ; BUFFERNOT movfw portb ; takes Input A unchaged goto Common ; rest is as in XOR/XNOR section ANDNAND movfw porta ; takes Input B andwf portb,w ; and ANDs with Input A goto Common ; rest is as in XOR/XNOR section IORNOR movfw porta ; takes Input B iorwf portb,w ; and IORs with Input A goto Common ; rest is as in XOR/XNOR section END