![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 Last edited by adamscybot; 26th January 2009 at 06:14 PM. | |
| |
| | #2 |
|
Why are you testing it against PORTA? Check it like : Code: BTFSS PORTA,0 RETRUN ;BAD NUMBER CALL DELAY10ms BTFSS PORTA,3 RETURN ;BAD NUMBER CALL DELAY10ms BTFSS PORTA,1 RETRUN ;BAD NUMBER CALL DELAY10ms BTFSS PORTA,2 RETURN ;BAD NUMBER GOTO SomeWhere ;GOTO anywhere since the code is correct
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 26th January 2009 at 07:57 PM. | |
| |
| | #3 |
|
I think you misunderstood me. Im "trying" to check the inputs on PORTA against the code in the code1 register. Hence BTFSS PORTA,code1. Which of course doesnt work, which is my problem. My code is dyamic, it can be changed... Just doing BTFSS PORTA,0 or whatever, will work but im trying to compare against another register. The code isnt the same all the time. | |
| |
| | #4 |
|
oh ok 1 minute i got the fix: Is PORTA only for buttons? How are the buttons coming in? like if you press number 2 is porta = 0000 0010 ? Oh i think i see you are starting from : 0= 0x01 - 00000001 1 = 0x02 - 00000010 and so on am i right?
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 26th January 2009 at 08:11 PM. | |
| |
| | #5 | |
| Quote:
PORTA is also, yes, only 4 buttons. 0,1,2,3. Addresses in eeprom start at 0x00 to 0x03. Ive then read them into the code registers. Your are right | ||
| |
| | #6 | |
| Quote:
I don't think this is what your want, is it? You want to compare EACH bit read from Port A with EACH bit in code1, don't you? You could start by comparing the first bit, and if that is correct, then the second and so on. If the first bit fails, then you don't have to compare any more. | ||
| |
| | #7 |
|
I already compare 1 bit then the next etc. I have 4 registers. code1,code2,code3,code4. The snippet of code I posted is supposed to compare the first digit of the code only. I do want to compare the input on portA to the code1. Then in the next code block I compare to code2 register. Etc. I simply posted the code1 section only as the rest are just slightly changed dupes. E.g. code1 = 00000001 code2 = 00001000 code3 = 00000010 code4 = 00000100 They are the registers. So that would be buttons 0,3,1,2 on porta. The contents change though, as I have a code setting routine to write to eeprom ealier on. | |
| |
| | #8 | |||
| Quote:
Quote:
You are NOT comparing a bit, if you are using a register! Look at your code1 - is it a bit? or is it 8 bits? You can compare a register by anding it with another register, and checking the status bit, but BIT test is only one bit, so when you pass a file to the test when it expects a bit, of course you will get an error. Quote:
PS, a digit is not one bit... Last edited by BeeBop; 26th January 2009 at 10:20 PM. | ||||
| |
| | #9 |
|
something like this: Code: MOVLW PORTA ANDLW 0x0F INCF W ANDLW CODE1 ![]() The above should get you started
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #10 |
|
Hi. Sorry for slow reply. BeeBop, I totally understand what you are saying and I know that is exactly why my code doesn't work. What Im asking is what can I do to make working code which has the same affect (well, has the same affect if it did work). Maybe you could detail more for me on comparing using "AND" and the status bit? AtomSoft: I see what your trying to do but I can't see how I can use the result to compare...(unless your pointing towards using the status register like BeeBop said). Surely if the person got the correect answer you would end up with an 8-bit register again. EDIT: I have an idea. Just and the code1 with porta like you did then use decsz or something to that affect to see if it is >0. If it ism clearly the code is correct. Last edited by adamscybot; 28th January 2009 at 03:49 PM. | |
| |
| | #11 |
|
you might have to shift each bit and check if zero if you do it that way.. i think.. not sure ... if it was a 18F pic it would be way simpler.
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #12 |
| Why would it be any simpler on an 18F? - it's absolutely trival on any PIC - they include specific bit tests (BTFSS and BTFSC), a huge advantage of a PIC.
| |
| |
| | #13 |
|
Lol Nigel your in Derby like me . What a coincidence .Anyway, Ive just tried this: MOVF PORTA,W BTFSC STATUS,2 GOTO Code1 MOVF PORTA,W ANDLW code1 BTFSC STATUS,2 BSF flag,0 CALL Release RETURN So using the zero flag. Supposedly this should make it so that if the and result is 0, the z flag is set. So in this code if it isn't set (indiciating correct answer). However, it doesnt seem to work properly. Ive got the code2,3 and 4 routines hard coded at the minute to button 0,2,2 while I mess with the code 1 procedure (dont want to break it all at once). With this for some reason If I set the code to say, button 3 then do 0,0,2,2 or 1,0,2,2 it is saying the code is correct... | |
| |
| | #14 |
|
Edit: Hang on just testing
Last edited by adamscybot; 28th January 2009 at 04:33 PM. | |
| |
| | #15 |
| And I've also got two Cybots, and a website about them!. That try was wrong -easy way to do it: Read the entire port to W. Transfer W to a GPR. Check each of the bits in the GPR using either BTFSS or BTFSC, depending which way you're testing. Also, use the include file names, I've no idea what 'Status, 2' means?, the correct way would be 'Status, Z' (assuming 2 is Z?). | |
| |
|
| Tags |
| alarm, burglar, checking, inputs |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Burglar alarm help. | compute_a_nerd | Electronic Projects Design/Ideas/Reviews | 10 | 13th January 2009 03:14 PM |
| burglar alarm | yoursoninoz | Electronic Projects Design/Ideas/Reviews | 3 | 23rd March 2007 04:53 PM |
| Burglar Alarm | tauraim | Electronic Projects Design/Ideas/Reviews | 6 | 1st March 2007 11:05 AM |
| Burglar alarm | madmikejt12 | Chit-Chat | 6 | 21st October 2006 12:40 PM |
| burglar alarm | chriz | Electronic Projects Design/Ideas/Reviews | 1 | 21st June 2005 10:17 PM |