#include "p16F870.inc"
; CONFIG
; __config 0xFF3A
__CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _CP_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ALL
RES_VECT CODE 0x0000 ; processor reset vector
GOTO MAIN ; go to beginning of program
; TODO ADD INTERRUPTS HERE IF USED
MAIN_PROG CODE ; let linker place main program
MAIN
BANKSEL ADCON1 ;(RA0 and RA1 are digital)
movlw b'00000111'
movwf ADCON1
movlw b'00000011' ;buttons(RA0, RA1 are inputs)
movwf TRISA
movlw b'11111100' ;leds(RB0, RB1 are outputs)
movwf TRISB
BANKSEL PORTB ; leds are initially off
clrf PORTB
btfss PORTA, RA0 ;check if button on RA0 is pressed | 'f' is '0', the next instruction is executed
goto FirstButtonPressed
goto FirstButtonNotPressed
GOTO MAIN
FirstButtonNotPressed ;RA0 = 1
btfss PORTA, RA1 ;If RA1 = 0 execute next instruction else skip
bsf PORTB, RB0
bcf PORTB, RB0
return
FirstButtonPressed ;RA0 = 0
btfss PORTA, RA1 ;If RA1 = 0 execute next instruction else skip
bcf PORTB, RB0
bsf PORTB, RB0
return
END