tons of different way to do it. You could even set your secret code in an array, read the keypad x times, compare the result with the array.
i'll try something.. maybe this will put some lights...
Code:
'
' Hardware assignment
' ====================
'
' System LCD
' -----------
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTD ' LCD register select port
DEFINE LCD_RSBIT 2 ' LCD register select bit
DEFINE LCD_EREG PORTD ' LCD enable port
DEFINE LCD_EBIT 3 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD bus size 4 or 8
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
'
' 4X4 matrix Keypad
' -----------------
include "c:\PBP_PROG\Include_Routines\keypad.bas"
DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTB.4
DEFINE KEYPAD_COL 4 ' 4 COL keypad
DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
DEFINE KEYPAD_COL_BIT 0 ' COL0 = PORTB.0
DEFINE KEYPAD_DEBOUNCEMS 100 ' debounce delay = 100 mSec
'
' Variables definition
' ===================
SecretCode var byte[5]
CounterA var byte
Match var byte
'
' Software/Hardware initialisation
' ================================
secretcode[0]=1
secretcode[1]=2
secretcode[2]=3
secretcode[3]=4
secretcode[4]=5
'
' Program start
' =============
Start:
match=0
lcdout $FE,1,"Enter the code"
for countera = 0 to 4
@ READKEYPAD _Key
if Key=secretcode[countera] then Match=Match+1
lcdout $FE,($C0+COUNTERA),"*"
next
if match=5 then
lcdout $FE,1,"Access Granted!"
else
lcdout $FE,1,"Access denied..."
endif
PAUSE 2000
goto start
to answer your original question... your code don't work because you don't keep track of your user entry. So it always stick to the first character => 7
and this...
Code:
If ByteA = 4 then ByteA = "A"
if ByteA = 5 then ByteA = 4
if ByteA = 6 then ByteA = 5
if ByteA = 7 then ByteA = 6
if ByteA = 8 then ByteA = "B"
if ByteA = 9 then ByteA = 7
if ByteA = 10 then ByteA = 8
if ByteA = 11 then ByteA = 9
if ByteA = 12 then ByteA = "C"
if ByteA = 13 then ByteA = "*"
if ByteA = 14 then ByteA = 0
if ByteA = 15 then ByteA = "#"
if ByteA = 16 then ByteA = "D"
could be replace by the single line bellow.
Code:
LOOKUP ByteA,[0,1,2,3,"A",4,5,6,"B",7,8,9,"C","*",0,"#","D"],ByteA
Or store the table in the EEPROM, then read from it..
Code:
DATA @1,1,2,3,"A",4,5,6,"B",7,8,9,"C","*",0,"#","D"
'
'
'
'
'
Read ByteA, ByteA
Bookmarks