Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=16F84A
- #include <p16F84a.inc>
- __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
- tmp EQU 0x0F
- ORG 0x000 ; processor reset vector
- bcf STATUS,RP1
- bsf STATUS,RP0 ; switch to register bank 1
- movlw 0x1C ; control word for port A
- movwf TRISA ; RA4, RA3, RA2 - input, RA1, RA0 - output
- movlw 0xFF ; control word for port B
- movwf TRISB ; all are inputs for now
- bcf STATUS,RP0 ; switch back to register bank 0
- start
- movf PORTA, w ; load data from port A into w
- andlw 0x1C ; apply mask 00011100 - isolate A B C
- movwf tmp ; save 000ABC00 in tmp
- andlw 0x04 ; apply mask 00000100 - isolate C
- xorlw 0x04 ; negate C in accumulator
- btfsc STATUS,Z ; if !C=1 then
- bsf tmp, 0x02 ; set 000ABC10 in tmp
- movf tmp, w ; load 000ABC10 into accumulator
- andlw 0x10 ; apply mask 00010000 - isolate A
- rrf w ; rotate w to the right, so it lines up with B in tmp
- xorwf tmp, w ; A xor B
- andlw 0x08 ; isolate (A xor B) value
- rrf w ; (A xor B) is now at 0x04
- rrf w ; (A xor B) is now at 0x02, lines up with !C in tmp
- iorwf tmp, w ; (A xor B) || !C
- andlw 0x02 ; isolate result
- movwf PORTA ; output result on port A
- goto start
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement