Cantafford
Member
Ok last thread I will do today I swear.
I'm trying to implement an XOR function in assembly. I have two push buttons. If they are in different positions(one pressed one not pressed) the led will light up. Otherwise the LED will stay off.
This is how I connected them:
And this is the code I wrote:
My program won't run as expected. If I press button on RA0 the LED lights up no matter what position button on RA1 is on. Please help me correct this if possible. Thank you.
I'm trying to implement an XOR function in assembly. I have two push buttons. If they are in different positions(one pressed one not pressed) the led will light up. Otherwise the LED will stay off.
This is how I connected them:

And this is the code I wrote:
Code:
#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
My program won't run as expected. If I press button on RA0 the LED lights up no matter what position button on RA1 is on. Please help me correct this if possible. Thank you.