Advertisement
dreadmachine

Untitled

Dec 28th, 2023
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 1.12 KB | None | 0 0
  1. list p=16F84A
  2. #include <p16F84a.inc>
  3. __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
  4.  
  5. tmp EQU 0x0F
  6.  
  7. ORG 0x000 ; processor reset vector
  8. bcf STATUS,RP1
  9. bsf STATUS,RP0 ; switch to register bank 1
  10. movlw 0x1C ; control word for port A
  11. movwf TRISA ; RA4, RA3, RA2 - input, RA1, RA0 - output
  12. movlw 0xFF ; control word for port B
  13. movwf TRISB ; all are inputs for now
  14. bcf STATUS,RP0 ; switch back to register bank 0
  15.  
  16. start
  17. movf PORTA, w ; load data from port A into w
  18. andlw 0x1C ; apply mask 00011100 - isolate A B C
  19. movwf tmp ; save 000ABC00 in tmp
  20. andlw 0x04 ; apply mask 00000100 - isolate C
  21. xorlw 0x04 ; negate C in accumulator
  22. btfsc STATUS,Z ; if !C=1 then
  23. bsf tmp, 0x02 ; set 000ABC10 in tmp
  24. movf tmp, w ; load 000ABC10 into accumulator
  25. andlw 0x10 ; apply mask 00010000 - isolate A
  26. rrf w ; rotate w to the right, so it lines up with B in tmp
  27. xorwf tmp, w ; A xor B
  28. andlw 0x08 ; isolate (A xor B) value
  29. rrf w ; (A xor B) is now at 0x04
  30. rrf w ; (A xor B) is now at 0x02, lines up with !C in tmp
  31. iorwf tmp, w ; (A xor B) || !C
  32. andlw 0x02 ; isolate result
  33. movwf PORTA ; output result on port A
  34. goto start
  35.  
  36. end
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement