Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; initialize a PIC assembly program
- LIST P=16F84A ; Tells the assembler what chip we are using
- INCLUDE "p16f84a.inc" ; Include the defaults for the chip
- __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC ; Configuration settings
- ORG 0x00 ; Start at location 0
- GOTO MAIN ; Skip over the interrupt service routine
- ORG 0x04 ; Interrupt service routine location
- RETFIE ; Return from interrupt
- MAIN
- BANKSEL TRISA ; Select TRISA to configure inputs/outputs
- MOVLW b'00001111' ; Set RA3-RA0 as inputs
- MOVWF TRISA ; Write to TRISA
- BANKSEL TRISB ; Select TRISB to configure inputs/outputs
- CLRF TRISB ; Set all port B as outputs
- BEGIN
- BANKSEL PORTA ; Select PORTA to read inputs
- MOVF PORTA,W ; Move PORTA to W register
- ANDLW b'00001111' ; Keep only the last 4 bits (A, B, C, and Y)
- ; Evaluate logical expression !C || (A xor B)
- ; First, check if C is 0 (!C)
- BTFSS PORTA,2 ; Skip the next instruction if C (bit 2) is set
- GOTO SET_OUTPUT ; If C is 0, go to set output on PORTB
- ; If not, evaluate A xor B
- MOVF PORTA,W ; Move PORTA to W register
- ANDLW b'00000011' ; Keep only bits A and B
- XORWF PORTA,F ; XOR A and B
- BTFSC STATUS,Z ; Skip the next instruction if Z flag is set (A xor B == 0)
- GOTO CLEAR_OUTPUT ; If A xor B is 0, go to clear output on PORTB
- ; If none of the conditions are met, set output on PORTB
- SET_OUTPUT
- BSF PORTB,0 ; Set bit 0 of PORTB
- GOTO END ; End of program
- CLEAR_OUTPUT
- BCF PORTB,0 ; Clear bit 0 of PORTB
- END
- GOTO BEGIN ; Loop back to the beginning
- END ; End of program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement