need help in coding!!!

hi,
i use pic16f877,a 3x4 keypad and a 16x2 LCD display to do my project.my progress is like this:first,keyin password for privacy,then choose status i want and show it on LCD screen.it will set then.after that,i need to keyin password again to check for correctness(but i tink i didnt do that far).now i stuck in interfacing keypad with pic.i know there must be some mistakes in coding since i just modify the coding without having better understanding in it.so,i really hope somebody can help me edit the coding..a million thankful for helping me..
[' ===================hardware assignment==================
Define LCD_BITS 4 ' 4-bit interface
Define LCD_LINES 2 ' 2 line LCD
Define LCD_DREG PORTB 'bit start from bit 0
Define LCD_DBIT 0
Define LCD_RSREG PORTA 'rs at bit 2
Define LCD_RSBIT 2
Define LCD_EREG PORTA 'e at bit 1
Define LCD_EBIT 4
DEFINE LCD_RWREG PORTA
DEFINE LCD_RWBIT 3

KeyCol Var Byte
KeyRow var byte
KeyPress var byte
KeyButton var byte
Flag Var Bit ' Flag to indicate a keypress.
b0 var byte
b1 var byte
i var byte
j var byte
counter var byte
TempPass var byte[4]
RealPass var byte[4]
ROM var byte
submenu var byte
menu VAR BYTE

'===================program starts==========================
loop:
counter = 0
submenu = 0
read 5, ROM
if rom = 255 then
menu = 0
LCDOUT $FE, 1 , "Enter Password: "
lcdout $FE, $C0
gosub ValidateUser
lcdout $FE, 1 , "Password Stored"
pause 2000
endif
LCDOUT $FE, 1 , "Select Status: "
goto mainstatus
'/////////////////////////////////////////////////////////
MainStatus:
counter = 0
if menu = 1 then
lcdout $FE, $C0
lcdout "Come In!"
endif
if menu = 2 then
lcdout $FE, $C0
lcdout "Do Not Disturb!"
endif
if menu = 3 then
lcdout $FE, $C0
lcdout "Out To Meeting!"
endif
if menu = 4 then
lcdout $FE, $C0
lcdout "Away!"
endif
if menu = 5 then
lcdout $FE, $C0
lcdout "Lunch!"
endif
if menu = 6 then
lcdout $FE, $C0
lcdout "Not In!"
endif
goto mainstatus
'///////////////////////////////////////////////////////////
ValidateUser:
for i = 1 to 4
gosub keyscan
temppass[i-1] = keybutton
next i
ValidateUser1:
gosub keyscan
if keypress = 7 then validateuser
if keypress <> 15 then validateuser1

ValidatePassword:
j = 0
for i = 0 to 3
if realpass[i] = temppass[i] then
j = j + 1
else
j = j - 1
endif
next i
return

CorrectCode:
lcdout $FE, 1
lcdout "Correct Password!"
pause 1800
return

WrongCode:
lcdout $FE, 1
lcdout "Wrong Password!"
pause 2000
return
'////////////////////////////////////////////////////////////
Submenu_1:
submenu = 1
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop

Submenu_2:
submenu = 2
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop

Submenu_3:
submenu = 3
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop

Submenu_4:
submenu = 4
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop

Submenu_5:
submenu = 5
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop

Submenu_6:
submenu = 6
lcdout $FE, 1
lcdout "Enter Password:"
lcdout $FE, $C0
gosub validateuser
gosub validatepassword
if j = 4 then
gosub Correctcode
else
gosub wrongcode
endif
goto loop
'////////////////////////////////////////////////////////////
KeyScan:
for b0 = 0 to 3 ' do debouncing for key pressed
gosub ColScan
if Flag = 1 then KeyScan
next b0
gosub RowScan
Gosub Convert
CheckRelease:
for b1 = 0 to 3 ' do debouncing for key released
gosub colscan
if flag = 0 then Checkrelease
next b1
if counter < 4 then
gosub KeyNumber
endif
return

ColScan:
pause 20
TRISD = $0F
PORTD = $0F
FLAG = 0
Keycol = 0
if PORTD.4 = 0 THEN Ret1
keycol = 1
if PORTD.5 = 0 THEN Ret1
keycol = 2
if PORTD.6 = 0 then Ret1
KeyCol = 3
if PORTD.7 = 0 then Ret1
flag = 1
Ret1:
return

RowScan:
pause 20
TRISD = $F0
PORTD = $F0
KEYROW = 0
IF PORTD.0 = 0 THEN Ret2
KEYROW = 1
IF PORTD.1 = 0 THEN Ret2
KEYROW = 2
IF PORTD.2 = 0 THEN Ret2
KEYROW = 3
IF PORTD.3 = 0 THEN Ret2
GOTO ROWSCAN
Ret2:
return

Convert:
KeyPress = (keyrow * 4) + keycol
return

KeyNumber:
if keypress = 0 then
counter = counter + 1
LCDout "1"
keybutton = 1
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 1 then
counter = counter + 1
lcdout "2"
keybutton = 2
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 2 then
counter = counter + 1
lcdout "3"
keybutton = 3
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 4 then
counter = counter + 1
LCDout "4"
keybutton = 4
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 5 then
counter = counter + 1
lcdout "5"
keybutton = 5
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 6 then
counter = counter + 1
lcdout "6"
keybutton = 6
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 8 then
counter = counter + 1
LCDout "7"
keybutton = 7
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 9 then
counter = counter + 1
lcdout "8"
keybutton = 8
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 10 then
counter = counter + 1
lcdout "9"
keybutton = 9
pause 100
lcdout $FE, $10
lcdout "*"
endif
if keypress = 13 then
counter = counter + 1
lcdout "0"
keybutton = 0
pause 100
lcdout $FE, $10
lcdout "*"
endif
return
]
Topic archived. No new replies allowed.