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..
here is my coding:
' ===================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

Define OSC 4
TRISD = %00001111
'===================program starts==========================
start:
counter = 0
submenu = 0
read 5, ROM
if rom = 255 then
menu = 0
LCDOUT $FE, 1 , "Enter Password: "
lcdout $FE, $C0
gosub ValidateUser
ENDIF
lcdout $FE, 1 , "Password Stored"
pause 2000
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 start

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 start

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 start

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 start

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 start

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 start