下面是我写的,改密码那个想不出来,请大神帮忙修改代码
#include <f330lib.h>
unsigned char n[4];
unsigned char p[4]={'2','4','1','0'};
// compare password 2410
void keyGetPwd(void)
//define function "keyGetPwd"
{
unsigned char i,j=0;
// unsigned i,j
lcdInit();
// initialise lcd screen
lcdSetXY(0,0);
// 1st column and 1st row
lcdPutStr("WELCOME");
// place "WELCOME" at 1st column and 1st row
lcdSetXY(0,1);
// 1st column and 2nd row
lcdPutStr("Password:");
// palce "Password:" at 1st column and 2nd row
for (i=1;i<5;i++)
// for loop get key char,until i=4,total 4 words(2410)
{
j=keyGet();
// j get from keypad
lcdPutCh('*');
// "*" is present instead of what char get from key pad
n[i-1]=j;
// use "*" to clear the word
if (j==0x2A)
// if "*" entered
{
lcdInit();
lcdSetXY(0,0);
lcdPutStr("WELCOME");
lcdSetXY(0,1);
lcdPutStr("Password:");
i = 0;
// after clear restart
}
else if (j==0X23)
// if "#" entered
{
lcdInit();
lcdSetXY(0,0);
lcdPutStr("New Password:");
lcdSetXY(0,1);
lcdPutStr("");
}
}
}
void main (void)
{
unsigned char m = 0;
Init_Device();
// initialize device
keyInit();
// initialize keypad
lcdInit();
// initialize lcd screen
while(1)
{
keyGetPwd();
// keygetpassword function
if ((p[0] == n[0])&&(p[1] == n[1])&&(p[2] == n[2])&&(p[3]))
// compare the n[] array data from key set with unsigned char p[] array
{
lcdInit();
lcdSetXY(0,0);
lcdPutStr("WELCOME");
lcdSetXY(0,1);
lcdPutStr("Correct");
// if 2 array are same, display Correct
m = 0;
// if correct password rerun
}
else
{
lcdInit();
lcdSetXY(0,0);
lcdPutStr("WELCOME");
lcdSetXY(0,1);
lcdPutStr("Incorrect");
// if 2 array are not same, display Incorrect
m++;
if (m == 3)
// only can keyin 3 times wrong password
{
lcdInit();
lcdSetXY(0,1);
lcdPutStr("Entry is Locked!"); // after key 3 times wrong password display
while(1);
// refuse any password entry
}
}
delayms (5000);
// delay 5 seconds
}
}