; Program: LED Control with PB0 and PB1
; Microcontroller: PIC16F877A
; Function: PB0 -> LED OFF, PB1 -> LED ON
LIST P=16F877A ; Specify the PIC16F877A microcontroller
INCLUDE <P16F877A.INC> ; Include file for register definitions
__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _LVP_OFF
; Start of code
ORG 0x0000 ; Reset vector
GOTO MAIN ; Jump to main program
ORG 0x0004 ; Interrupt vector
GOTO ISR ; Jump to interrupt service routine
; Main Program
MAIN:
BCF STATUS, RP0 ; Select Bank 0
CLRF PORTB ; Clear PORTB output
CLRF TRISB ; Configure PORTB as output
BSF STATUS, RP0 ; Switch to Bank 1
BSF TRISB, 0 ; Set RB0 (PB0) as input
BSF TRISB, 1 ; Set RB1 (PB1) as input
BCF STATUS, RP0 ; Return to Bank 0
BSF INTCON, INTE ; Enable external interrupt on RB0
BSF INTCON, GIE ; Enable global interrupts
MAIN_LOOP:
GOTO MAIN_LOOP ; Infinite loop
; Interrupt Service Routine (ISR)
ISR:
BTFSC PORTB, 0 ; Check if PB0 (RB0) is pressed
GOTO LED_OFF ; Turn LED off if PB0 is pressed
BTFSC PORTB, 1 ; Check if PB1 (RB1) is pressed
GOTO LED_ON ; Turn LED on if PB1 is pressed
BCF INTCON, INTF ; Clear the external interrupt flag
RETFIE ; Return from ISR
LED_OFF:
BCF PORTB, 7 ; Turn off LED (clear RB7)
BCF INTCON, INTF ; Clear interrupt flag
RETFIE ; Return from ISR
LED_ON:
BSF PORTB, 7 ; Turn on LED (set RB7)
BCF INTCON, INTF ; Clear interrupt flag
RETFIE ; Return from ISR
END ; End of program