Hi,
I'm new to PICs and have just begun programming a little alarm. I am using the PIC16F88.
I have got everything except for one part running nice and smoothly. The alarm features a code set feature (write to eeprom) and on every boot it fetches the 4-digit code from the eeprom and stores in registers code1,code2,code3,code4.
So if the code was say, buttons 0,3,1,2 you'd have:
code1 = 00000001
code2 = 00001000
code3 = 00000010
code4 = 00000100
So the bit that is on represents the button that needs to be pressed.
The problem is that I cant decode the registers into my code checking section. Here is the code check section for the first bit.
Code1 MOVF PORTA,W
BTFSC STATUS,2
GOTO Code1
BTFSS PORTA,code1
BSF flag,0
CALL Release
RETURN
So basically what I want to happen is that when a button on porta is pressed it checks that it is the same as the one represented in the code1 register.
The problem lies with :
BTFSS PORTA,code1
If I do a linear comparison like,
BTFSS PORTA,0
Everything works fine. But using code1 as the second parameter causes the code to fail (recognized as incorrect). I don't know how to do this part properly. I have tried calling up something to convert the "relative" bit positions from the "code" registers and convert them to pure binary then use that as a second parameter but that doesnt work either. E.g. changing 00001000 to 00000011
hence third button --> binary to number 3.
Just for notes, the BSF flag,0 is an error flag called upon later to see if the code was wrong. Release checks to see all buttons are released.
I don't know how to go about this.
Adam