'****************************************************************
'* Name : LCDprog1.BAS *
'* Author : Paul-Marc Bougharios, ID: 20020519 *
'* Notice : Copyright (c) 2005 B.I.O. *
'* : All Rights Reserved *
'* Date : 6/12/2005 *
'* Version : 1.0 *
'* Notes : THANK YOU MY GOD!!! *
'* : The program starts now the real stuff... *
'* : God, please enlighten me. Thank You For You Love. *
'* : The program loads in 2 modes: *
'* : Save Code Mode: to save the 4-digit code in mem. *
'* : Check Code Mode: to enter the code and compare it *
'* : with the saved one... *
'****************************************************************
' Symbols
symbol second = 1000
symbol del1 = 200
symbol del2 = 70
' Variables
cnt var byte
cn2 var byte
p10 var byte
key var byte
code var byte
sCode var byte
' Columns
col1 var PORTB.0
col2 var PORTB.1
col3 var PORTB.2
' Rows
row1 var PORTB.4
row2 var PORTB.5
row3 var PORTB.6
row4 var PORTB.7
' Temporary variables for buttons
tmp1 var byte
tmp2 var byte
tmp3 var byte
tmp4 var byte
'*****************
' Start of Program
pause second
lcdout $FE,1,"Load Program...",$FE,$C0
pause second
' Teach PortB
TRISB=%11110000 ' Have RB4-7 as inputs
lcdout "Press Any Key..."
gosub getkey
if key = -2 then
goto saveCode
else
goto enterCode
endif
saveCode:
lcdout $FE,1,"Save Code Mode"
' Ask for Code
lcdout $FE,$C0,"Enter Code: "
code = 0
for cnt = 0 to 3
gosub getKey
gosub power
code = code + key * p10
next
write $3F8, code
goto endProg
enterCode:
lcdout $FE,1,"Check Code Mode"
' Ask for Code
lcdout $FE,$C0,"Enter Code: "
code = 0
for cnt = 0 to 3
gosub getKey
gosub power
code = code + key * p10
next
read $3F8, sCode
if code = sCode then
goto success
else
goto fail
endif
endProg:
lcdout $FE,$C0,"Program Ended..."
loop: goto loop
power:
p10 = 1
for cn2 = 0 to cnt
p10 = p10 * 10
next cn2
return
success:
lcdout $FE,1,"Authenticated..."
goto endProg
fail:
lcdout $FE,1,"Unauthorized..."
goto endProg
'*************
' Program Loop
'loop:
' gosub getKey
' goto loop
'************
' Key Grabber
getKey:
' Send 1's to columns
col1=1
col2=1
col3=1
' Initialize Debouncing variables
tmp1=0
tmp2=0
tmp3=0
tmp4=0
' Pause a little, for speed
pause del1
button row1,1,255,0,tmp1,1,lbl_R1
button row2,1,255,0,tmp2,1,lbl_R2
button row3,1,255,0,tmp3,1,lbl_R3
button row4,1,255,0,tmp4,1,lbl_R4
' Wait for user input
goto getKey
gotKey:
' Have the key, and saved it in 'key'
return
lbl_R1:
' Turn off all columns, then 1 by 1, to get correct pin
col1=1
col2=0
col3=0
' Check row, again, for column 1
tmp1=0
button row1,1,255,0,tmp1,1,lbl_R1C1
' Low column 1, high column 2
col1=0
col2=1
col3=0
' Check row, again, for column 2
tmp1=0
button row1,1,255,0,tmp1,1,lbl_R1C2
' Low column 1,2 high column 3
col1=0
col2=0
col3=1
' Check row, again, for column 3
tmp1=0
button row1,1,255,0,tmp1,1,lbl_R1C3
' Get Back, akhiran
goto getKey
lbl_R2:
' Turn off all columns, then 1 by 1, to get correct pin
col1=1
col2=0
col3=0
' Check row, again, for column 1
tmp2=0
button row2,1,255,0,tmp2,1,lbl_R2C1
' Low column 1, high column 2
col1=0
col2=1
col3=0
' Check row, again, for column 2
tmp2=0
button row2,1,255,0,tmp2,1,lbl_R2C2
' Low column 1,2 high column 3
col1=0
col2=0
col3=1
' Check row, again, for column 3
tmp2=0
button row2,1,255,0,tmp2,1,lbl_R2C3
' Get Back, akhiran
goto getKey
lbl_R3:
' Turn off all columns, then 1 by 1, to get correct pin
col1=1
col2=0
col3=0
' Check row, again, for column 1
tmp3=0
button row3,1,255,0,tmp3,1,lbl_R3C1
' Low column 1, high column 2
col1=0
col2=1
col3=0
' Check row, again, for column 2
tmp3=0
button row3,1,255,0,tmp3,1,lbl_R3C2
' Low column 1,2 high column 3
col1=0
col2=0
col3=1
' Check row, again, for column 3
tmp3=0
button row3,1,255,0,tmp3,1,lbl_R3C3
' Get Back, akhiran
goto getKey
lbl_R4:
' Turn off all columns, then 1 by 1, to get correct pin
col1=1
col2=0
col3=0
' Check row, again, for column 1
tmp4=0
button row4,1,255,0,tmp4,1,lbl_R4C1
' Low column 1, high column 2
col1=0
col2=1
col3=0
' Check row, again, for column 2
tmp4=0
button row4,1,255,0,tmp4,1,lbl_R4C2
' Low column 1,2 high column 3
col1=0
col2=0
col3=1
' Check row, again, for column 3
tmp4=0
button row4,1,255,0,tmp4,1,lbl_R4C3
' Get Back, akhiran
goto getKey
lbl_R1C1:
lcdout "2"
key = 2
goto gotKey
lbl_R1C2:
lcdout "1"
key = 1
goto gotKey
lbl_R1C3:
lcdout "3"
key = 3
goto gotKey
lbl_R2C1:
lcdout "0"
key = 0
goto gotKey
lbl_R2C2:
lcdout $FE,1
key = -2
goto gotKey
lbl_R2C3: ' Like Backspace, delete one character backwards
lcdout $FE,$10," ",$FE,$10
key = -1
goto gotKey
lbl_R3C1:
lcdout "8"
key = 8
goto gotKey
lbl_R3C2:
lcdout "7"
key = 7
goto gotKey
lbl_R3C3:
lcdout "9"
key = 9
goto gotKey
lbl_R4C1:
lcdout "5"
key = 5
goto gotKey
lbl_R4C2:
lcdout "4"
key = 4
goto gotKey
lbl_R4C3:
lcdout "6"
key = 6
goto gotKey
end ' Mich daroureh, bass yalla...