PDA

View Full Version : novice need help for a security keypad



davleo
- 22nd October 2003, 05:52
hi everybody,
I just start in programing and i would like to make an security keypad. the keypad is a 4*4 connect to the 8 pin of portb like this
B0..1...2...3...A
B1..4...5...6...B
B2..7...8...9...C
B3..*...0...#...D
....B4..B5..B6..7
I using a 16f84 and picbasic pro 2.44

I would like to know how to compare a code enter by the keypad with the one store in the program.
I started like this:
trisa=%00000000
trisb=%11111111
code=123A
key1 var byte
key2 var byte
key3 var byte
keyA var byte
,etc for each key
key1 = portb.0 AND portb.4 at 0,
key2 = portb.0 AND portb.5 at 0,I DON'T KNOW HOW TO DO THIS PART
key3 = portb.0 AND portb.6 at 0,
keyA = portb.0 AND portb.7 at 0,
,etc for each key
key1:
check keypad IF key1 is press THEN key2 else key1,
key2:
check keypad IF key2 is press THEN key3 else key1,I DON'T KNOW HOW TO DO THIS PART TOO

key3:
check keypad IF key3 is press THEN key3 else key1,
key4:
check keypad IF key4 is press THEN YES else NO
yes:
high portA.0, green led
pause 5000
low portA.0
goto key1
no:
high portA.1, red led
pause 5000
low portA.1
goto key1
end

For sure is not the good way, if somebody can give me help on this
thanks

davleo
- 22nd October 2003, 23:26
up

davleo
- 24th October 2003, 01:24
nobody can't help me !
please

davleo
- 24th October 2003, 05:50
this is ma first code whta wrong with it:(the explanation is in french but i'm sure you don't need it )
eeprom 0,[11101110] ;pour chiffre 1
eeprom 1,[10111011] ;pour chiffre 9
eeprom 2,[11101011] ;pour chiffre 7
eeprom 3,[11101110] ;pour chiffre 1
trisa=%00000000 ; port A en sortie
b0 var byte
b1 var byte
b2 var byte
b3 var byte
b10 var byte
b11 var byte
b12 var byte
b13 var byte
debut:
low porta.1
low porta.2
trisb=%11111111 ;port B en entrée
b0=portb ;lit le port B et met les info dans b0
if b0=%11111111 then debut ; si aucune touche appuyé recommence a lire le port B jusqu'a l'appuis d'une touche
pause 100
b1=portb
pause 100
b2=portb
pause 100
b3=portb

code1:
read 0,b10
if b10=b0 then code2
goto bad
code2:
read 1,b11
if b11=b1 then code3
goto bad
code3:
read 2,b12
if b12=b2 then code4
goto bad
code4:
read 3,b13
if b13=b3 then good
goto bad

bad:
pause 1500
high porta.2
pause 3000
low porta.2
goto debut

good:
high porta.1
pause 5000
low porta.1
goto debut
end

languer
- 24th October 2003, 22:12
You may want to look at the LOOKUP function. I belive it is probably what you want to use. Just create a table of all possible combinations you get on the keypad.

Let me explain,

B0+B4 = 1 (PORTB = 00010001)
B0+B5 = 2 (PORTB = 00100001)

etc...

Now you have a 16 unique numbers that represent each keypad character. You can have the 16 numbers in a LOOKDOWN table, so you compare the PORTB number to the table. This gives you the location that matches the number. Now you create a LOOKUP table that contains the keypad characters in the EXACT order as the numbers they represent (as you created them in the LOOKDOWN table). You use the position value from the LOOKDOWN function to select you the desired character in the LOOKUP table.

The following article is probably very useful:
http://www.parallax.com/dl/docs/cols/nv/vol4/col/97.pdf

davleo
- 24th October 2003, 22:22
thanks a lot a read that and let you know

davleo
- 25th October 2003, 04:48
I tried lookup-look down method but I don't realy understand
but i found an over way:
EEPROM 0,[1,9,7,1]; my code
; variable declaration here
; port A declaration here
debut:
code=0
decodage:
PORTB.0 = high
If PORTB.4 = then touche= 1
If PORTB.5 = then touche= 2
If PORTB.6 = then touche= 3
If PORTB.7 = then touche= A
PORTB.0 = low
PORTB.1 = HIGH
If PORTB.4 = then touche= 4
If PORTB.5 = then touche= 5
If PORTB.6 = then touche= 6
If PORTB.7 = then touche= B
ETC....


branch code,[c1,c2,c3,c4]
c1:
read 0,b10
if b10=touche then code=1 goto decodage
else goto bad
c2:
read 1,b11
if b11=touche then code=2 goto decodage
else goto bad
c3:
read 2,b12
if b12=touche then code=3 goto decodage
else goto bad
c4:
read 3,b13
if b13=touche then goto good
else bad
after that is very simple
do you think is good? I didn't test this code yet, but I will this weekend.

Melanie
- 25th October 2003, 14:02
I think you should break-down this project into little stages. One of the most important is your Keypad entry routine - since the whole project rotates around that. To give you a helping start, tell me what kind of keypad is it... one of those where you scan Rows/Columns or one of those with a common pin and you then have one invidual pin for each button.

languer
- 25th October 2003, 17:05
Let's start with the table (from there you can implement it different ways):

1 = B0+B4 = 00010001b = 11h
2 = B0+B5 = 00100001b = 21h
3 = B0+B6 = 01000001b = 41h
A = B0+B7 = 10000001b = 81h
4 = B1+B4 = 12h
5 = B1+B5 = 22h
6 = B1+B6 = 42h
B = B1+B7 = 82h
7 = B2+B4 = 14h
8 = B2+B5 = 24h
9 = B2+B6 = 44h
C = B2+B7 = 84h
* = B3+B4 = 18h
0 = B3+B5 = 28h
# = B3+B6 = 48h
D = B3+B7 = 88h

Ok, table is done.

Now to use the lookdown / lookup method you build it like this:
{
*POLL / READ PORT B into keypad
*byte variable position
*byte variable position
LOOKDOWN keypad, [$11,$21,$41,$81,$12,$22,$42,$82,$14,$24,$44,$84,$1 8,$28,$48,$88], position
*this gives you the location in the table for the numeric representation of the character selected and puts it in 'position'*
LOOKUP position,["123A456B789C*0#D"],codeX
*this gives you the actual character selected and puts it in 'codeX'*
}

You then poll the keypad for the next characters in sequence.

The same applies to your, IF-THEN-ELSE routine. You can use it, but you should've built the table. Then you do something like:
IF PORTB = $11 then codeX = "1" etc...

Hope this helps, I am no expert and surely my hex is pretty rusty. But you should also get good guidance from some pretty smart people around here.

A good read before you even begin to tinker with PBP (in my opinion) is the BasicStamp manual. You will not get any better documentation since that is where it all started, and it is so widely used that each command is explained with great detail. The commands unique to PBP are obviously not in it, but most are (this is one of them).

Good luck.

davleo
- 25th October 2003, 18:04
Originally posted by Melanie
I think you should break-down this project into little stages. One of the most important is your Keypad entry routine - since the whole project rotates around that. To give you a helping start, tell me what kind of keypad is it... one of those where you scan Rows/Columns or one of those with a common pin and you then have one invidual pin for each button.


my keypad is a 4*4 rows/columns ,
row=rb0 ->rb3
columns= rb4->rb7
but my code is correct or scrap ?

davleo
- 25th October 2003, 18:10
thanks LANGER, but the keypad need to works with rb0->rb3 in output, and rb4->rb7 in input, but I starting to understand the method.

Tim B
- 17th November 2003, 13:26
davleo

In case you have not resolved your problem, have a look at a project on just such a device I wrote for a new Pic Basic User site.

http://users.picbasic.org/

Look under Projects, Control

There is nothing unique in there to unique that will not prevent an easy conversion to Pbp

Tim

davleo
- 17th November 2003, 22:54
thx for the link very interesting