Advertisement
dreadmachine

Untitled

Dec 28th, 2023
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 1.84 KB | None | 0 0
  1. ; initialize a PIC assembly program
  2. LIST P=16F84A       ; Tells the assembler what chip we are using
  3.     INCLUDE "p16f84a.inc"   ; Include the defaults for the chip
  4.     __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC ; Configuration settings
  5.  
  6.     ORG 0x00            ; Start at location 0
  7.     GOTO MAIN            ; Skip over the interrupt service routine
  8.  
  9.     ORG 0x04            ; Interrupt service routine location
  10.     RETFIE               ; Return from interrupt
  11.  
  12.     MAIN
  13.     BANKSEL TRISA        ; Select TRISA to configure inputs/outputs
  14.     MOVLW b'00001111'    ; Set RA3-RA0 as inputs
  15.     MOVWF TRISA          ; Write to TRISA
  16.     BANKSEL TRISB        ; Select TRISB to configure inputs/outputs
  17.     CLRF TRISB           ; Set all port B as outputs
  18.  
  19.     BEGIN
  20.     BANKSEL PORTA        ; Select PORTA to read inputs
  21.     MOVF PORTA,W         ; Move PORTA to W register
  22.     ANDLW b'00001111'    ; Keep only the last 4 bits (A, B, C, and Y)
  23.  
  24.     ; Evaluate logical expression !C || (A xor B)
  25.  
  26.     ; First, check if C is 0 (!C)
  27.     BTFSS PORTA,2        ; Skip the next instruction if C (bit 2) is set
  28.     GOTO SET_OUTPUT      ; If C is 0, go to set output on PORTB
  29.  
  30.     ; If not, evaluate A xor B
  31.     MOVF PORTA,W         ; Move PORTA to W register
  32.     ANDLW b'00000011'    ; Keep only bits A and B
  33.     XORWF PORTA,F        ; XOR A and B
  34.     BTFSC STATUS,Z       ; Skip the next instruction if Z flag is set (A xor B == 0)
  35.     GOTO CLEAR_OUTPUT    ; If A xor B is 0, go to clear output on PORTB
  36.  
  37.     ; If none of the conditions are met, set output on PORTB
  38.     SET_OUTPUT
  39.     BSF PORTB,0          ; Set bit 0 of PORTB
  40.     GOTO END             ; End of program
  41.  
  42.     CLEAR_OUTPUT
  43.     BCF PORTB,0          ; Clear bit 0 of PORTB
  44.  
  45.     END
  46.     GOTO BEGIN           ; Loop back to the beginning
  47.  
  48.     END                  ; End of program
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement