PDA

View Full Version : Trouble in reading eeprom data..



tacbanon
- 6th November 2011, 14:03
Hi, I'm trying to modify the following codes(from DT and using Mr_e's Keypad routine), which reads data from eeprom (Data @0, 5,"12345")


Init:
enable

ReStart = 0
pause 500
Failed = 0
Read 0, ComboLength
serout PortD.5,T9600,[$1B,$63,$30]
Serout PortD.5, T9600, [$1B,$45,"Enter PIN Code"]
on interrupt goto KeypadINT

Start:
pause 1
Timeout = Timeout - 1
if (ComboPtr > 0) and (Timeout = 0) then Gosub Reset
if ReStart then Init
goto Start


;_________________________________________________ ____________________________
disable
@ ifndef HIGH_SECURITY
@ #define HIGH_SECURITY 0 ; default to Low security
@ endif


KeypadINT:
'Serout PortD.5, 6, [$FE,1,"Enter PIN Code"]
'Serout PortD.5, T9600, [$1b, $2a,$80] 'Turn backlight half broghtness
@ READKEYPAD _ByteA ; Get the keypress
TRISB=110000 ; Reset I/O's
PORTB=0 ; Set all columns LOW
INTCON.0 = 0 ; Clear RBIF
Timeout = MaxTime ; Reset the Timeout
lookup ByteA,[0,"123A456B789C*0#D"],Key ; convert keypress

if Key = "C" then 'Select C
Serout PortD.5, T9600, [$1B,$45,"Password"]
Serout PortD.5,T9600, [$D,"Cancel entry"]
pause 1000
scroll = 1
goto main
Endif

'Serout PortD.5,T9600, [$D,"Key=",key]
serout PortD.5,T9600,[$1B,$63,$31]
Serout PortD.5,T9600, [$D]
if key = "#" OR key = "*" then
DTMFOUT PortA.0,[key]
else
DTMFOUT PortA.3,[key] ; convert keypress to sound
Endif
ComboPtr = ComboPtr + 1
; point to next digit
@ if HIGH_SECURITY == 1
'Serout PortD.5,T9600, [$1B,$45,"Key=",key]
Serout PortD.5, T9600, ["*"]
; print a Mask character
if Key = "*" then
cn = cn+1
goto Reset
Endif
if Key = "#" then Finish


@ endif
if ComboPtr <= ComboLength then
Read ComboPtr, ByteA ; Get the digit from EEPROM
if Key = ByteA then ; is it the same ?
Read 0, ByteA ; Get the length of the combo
@ if HIGH_SECURITY == 0
'Serout PortD.5,T9600, [$1B,$45,"Key=",key]
Serout PortD.5, T9600, ["*"] ; print a Mask character
if ComboPtr = ByteA then AccessGranted ; Done?, Grant Access

@ endif
else
@ if HIGH_SECURITY == 0
ComboPtr = 0
Serout PortD.5,T9600 ,[$1B,$45] ; Wrong digit
goto AccessDenied ; terminate entry
@ else ; -HIGH_SECURITY-
Failed = 1 ; let them keep entering
@ endif ; makes it harder to figure
Endif ; the combination
endif
resume ; must end with # sign




The above codes works perfectly fine. i added a modification but having trouble make it work.
I added two more passwords for access in the eeprom.


DATA @0, 5,"12345" ' Admin
DATA @14,5,"43521" ' Client 1
DATA @21,5,"25632" ' Client 2

And upon entry...in order to select the location/identification client users must enter 11 or 12.


if myvarkey = "#" then ' Test it here


If cnt1 = 0 then
useradd = 0
Serout PortD.5,T9600, [$D,"ADMIN"]
useradd = 0 ' at address 0
pause 1000
cnt1 = 0
else
IF ByteD[0]="1" and ByteD[1]="1" then ' Client 1
Serout PortD.5,T9600, [$D,"Client 1"]
pause 1000
useradd = 14 ' at address 14
Endif
IF ByteD[0]="1" and ByteD[1]="2" then ' Client 2
Serout PortD.5,T9600, [$D,"Client 2"]
pause 1000
useradd = 21 ' at address 21
Endif

Endif


goto init
else
ByteD[cnt1]=myvarkey
Serout2 PortD.5,84, [$D, ">" , ByteD[cnt1]]
cnt1=cnt1+1
Endif

useradd variable is used to hold the location where to start reading the data from eeprom.
When pressing '#' and entering the pin code will be reading DATA @ 0,5,"12345", '11' and entering the pin code will be reading DATA @14,5, "45321" and so on.
The following modifications on the code can not get me to read the correct pin code/location.


if ComboPtr <= ComboLength then
Read useradd, ByteA ; Get the digit from EEPROM
if Key = ByteA then ; is it the same ?
Read useradd, ByteA ; Get the length of the combo
@ if HIGH_SECURITY == 0
'Serout PortD.5,T9600, [$1B,$45,"Key=",key]
Serout PortD.5, T9600, ["*"] ; print a Mask character
if ComboPtr = ByteA then AccessGranted ; Done?, Grant Access

@ endif
else
@ if HIGH_SECURITY == 0
ComboPtr = 0
Serout PortD.5,T9600 ,[$1B,$45] ; Wrong digit
goto AccessDenied ; terminate entry
@ else ; -HIGH_SECURITY-
Failed = 1 ; let them keep entering
@ endif ; makes it harder to figure
Endif ; the combination
endif
resume

Can you help me point out what I'm doing wrong in the code.

Thanks in advance,
tacbanon

tacbanon
- 7th November 2011, 04:24
Hi, I finally figured it out...the above modification works.


if ComboPtr <= ComboLength then
Read ComboPtr+useradd, ByteA[cnt1] ; Get the digit from EEPROM

if Key = ByteA then ; is it the same ?
Read 0, ByteA ; Get the length of the combo
@ if HIGH_SECURITY == 0
'Serout PortD.5,T9600, [$1B,$45,"Key=",key]
Serout PortD.5, T9600, ["*"] ; print a Mask character
if ComboPtr = ByteA then AccessGranted ; Done?, Grant Access

@ endif

else
@ if HIGH_SECURITY == 0
ComboPtr = 0
Serout PortD.5,T9600 ,[$1B,$45] ; Wrong digit
goto AccessDenied ; terminate entry
@ else ; -HIGH_SECURITY-
Failed = 1 ; let them keep entering
@ endif ; makes it harder to figure
Endif ; the combination
cnt1=cnt1+1
endif
resume


Regards,
tacbanon