Define SIMULATION_WAITMS_VALUE = 1
Define CONF_WORD = 0x3f72
Define CLOCK_FREQUENCY = 12
AllDigital
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTE
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTE
Define LCD_RWBIT = 1
Define LCD_EREG = PORTE
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
'For Keypad
Symbol raw1 = RD7
Symbol raw2 = RD6
Symbol raw3 = RD5
Symbol raw4 = RD4
Symbol col1 = RD0
Symbol col2 = RD1
Symbol col3 = RD2
Symbol col4 = RD3
TRISD = 0xf0
TRISB = 0
Lcdinit
Dim button As Byte
Dim digit As Byte
Dim pass As Byte
Dim error As Bit
Dim mem As Byte
Dim keyoff As Byte
start:
Lcdcmdout LcdClear
Lcdout "ALARM SYSTEM"
Lcdcmdout LcdClear
Lcdout "New Password:"
Lcdcmdout LcdLine2Home
Lcdout "****"
mem = 0
For digit = 1 To 4 '4 digit password
Gosub get_button
pass(digit) = button
Lcdcmdout LcdLine2Pos(digit) 'replace '-' with key type
Lcdout button ''''#button
Write mem, pass(digit)
mem = mem + 1
button = 0
Next digit
'''''''go to write input data
'''''''Gosub write_data
Lcdcmdout LcdClear
Lcdout "Password Saved"
WaitUs 2000
'Test Password
Gosub check_password
Goto start
End
check_password:
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "Type Password"
For digit = 1 To 4 '4 digit password
Gosub get_button
pass(digit) = button
Lcdcmdout LcdLine2Pos(digit)
Lcdout button '''#button
button = 0
Next digit
'???? Here how to check the input password is same with saved password, error = 1 if wrong password.... some code for me?
If error = 1 Then
Lcdout "Access Denied"
WaitUs 2000
Goto check_password
Else
Lcdout "Access verified"
Endif
Return
get_button:
While button = 0
button = 0
col1 = 1
If raw1 = 1 Then button = "0"
If raw2 = 1 Then button = "4"
If raw3 = 1 Then button = "8"
If raw4 = 1 Then button = "C"
col1 = 0
col2 = 1
If raw1 = 1 Then button = "1"
If raw2 = 1 Then button = "5"
If raw3 = 1 Then button = "9"
If raw4 = 1 Then button = "D"
col2 = 0
col3 = 1
If raw1 = 1 Then button = "2"
If raw2 = 1 Then button = "6"
If raw3 = 1 Then button = "A"
If raw4 = 1 Then button = "E"
col3 = 0
col4 = 1
If raw1 = 1 Then button = "3"
If raw2 = 1 Then button = "7"
If raw3 = 1 Then button = "B"
If raw4 = 1 Then button = "F"
col4 = 0
Wend
lp1:
PORTD = 0x0f
keyoff = PORTD And 0xf0
If keyoff <> 0 Then
Goto lp1
Endif
'?????here the code wait for button release before return.... some code for me??? :)
Return