📄 1.txt
字号:
else
_nop_();
ScanLine = line_3;
}
else if (ScanLine == line_3)
{
if (P2_3 = P2_2 = P2_1 = 1 && P2_0 = 0) CurKey = 3;
else if (P2_3 = P2_2 = P2_0 = 1 && P2_1 = 0) CurKey = 6;
else if (P2_3 = P2_1 = P2_0 = 1 && P2_2 = 0) CurKey = 9;
else if (P2_2 = P2_1 = P2_0 = 1 && P2_3 = 0) CurKey = 10;
else
_nop_();
ScanLine = line_4;
}
else (ScanLine == line_4)
{
ScanLine = line_1;
if (P2_3 = P2_2 = P2_1 = 1 && P2_0 = 0) CurKey = 11;
else if (P2_3 = P2_2 = P2_0 = 1 && P2_1 = 0) CurKey = 12;
else if (P2_3 = P2_1 = P2_0 = 1 && P2_2 = 0) CurKey = 13;
else if (P2_2 = P2_1 = P2_0 = 1 && P2_3 = 0) CurKey = 14;
else
_nop_();
ScanLine = line_1;
}
}
//更新显示内容
void ChDisp(void)
{
unsigned tled[5];
unsigned char i;
tled[0] = tled[1] = tled[2] = tled[3] = tled[4] = tled[5] = 0xFF; //关闭显示
if (CurKey <= 9 && CurKey >== 0) //按下数字键0~9时,在数码上显示0~9
{
if (CurKey == 0) C_CurKey = LED_CODE[0];
else if (CurKey == 1) C_CurKey = LED_CODE[1];
else if (CurKey == 2) C_CurKey = LED_CODE[2];
else if (CurKey == 3) C_CurKey = LED_CODE[3];
else if (CurKey == 4) C_CurKey = LED_CODE[4];
else if (CurKey == 5) C_CurKey = LED_CODE[5];
else if (CurKey == 6) C_CurKey = LED_CODE[6];
else if (CurKey == 7) C_CurKey = LED_CODE[7];
else if (CurKey == 8) C_CurKey = LED_CODE[8];
else C_CurKey = LED_CODE[9];
}
tled[0] = C_CurKey; //当前输入值在最低位显示
for (i = 5; i >= 1; i--;) //输入左移
tled[i] = tled[i-1];
LED[0] = tled[0];
LED[1] = tled[1];
LED[2] = tled[2];
LED[3] = tled[3];
LED[4] = tled[4];
LED[5] = tled[5];
}
//输入密码子程序
void InputPassword(void)
{
unsigned char j;
while(1)
{
for(j = 1; j <= 6; j++)
{
BeepSet(BT_BUTTON);
void ChDisp(void);
}
if (CurKey == 12)
{
BeepSet(BT_BUTTON);
break;
}
}
}
//输入新密码子程序1
void InputNewPassword_1(void)
{
unsigned char k;
while(1)
{
for(k = 1; k <= 6; j++)
{
BeepSet(BT_BUTTON);
void ChDisp(void);
}
if (CurKey == 12)
{
BeepSet(BT_BUTTON);
break;
}
}
LED[0] = Password_1[0];
LED[1] = Password_1[1];
LED[2] = Password_1[2];
LED[3] = Password_1[3];
LED[4] = Password_1[4];
LED[5] = Password_1[5];
}
/输入新密码子程序2
void InputNewPassword_2(void)
{
unsigned char b;
while(1)
{
for(b = 1; b <= 6; b++)
{
BeepSet(BT_BUTTON);
void ChDisp(void);
}
if (CurKey == 12)
{
BeepSet(BT_BUTTON);
break;
}
}
LED[0] = Password_2[0];
LED[1] = Password_2[1];
LED[2] = Password_2[2];
LED[3] = Password_2[3];
LED[4] = Password_2[4];
LED[5] = Password_2[5];
}
//按键动作
void KeyDone(void)
{
unsigned char a;
void InputPassword(void);
void InputNewPassword(void);
if (CurKey == 11) //检测是否按下"输入/核对"键
{
BeepSet(BT_BUTTON);
InputPassword(void); //第1次输入密码
if ((LED[0] == Password_1[0]) & (LED[1] == Password_1[1]) & (LED[2] == Password_1[2]) & (LED[3] == Password_1[3]) & (LED[4] == Password_1[4]) & (LED[5] == Password_1[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(开锁)
if (CurKey == 10) //检测是否按下"修改键",进入密码修改状态
{
BeepSet(BT_BUTTON);
InputNewPassword_1();
}
}
else
{
Wrong = 1; //第1次输入密码错误,点亮黄灯,报警
LightType = LightingYellow;
LightCtrl(200);
BeepSet(BT_ALARM_2);
InputPassword(void); //第2次输入密码
if ((LED[0] == Password_1[0]) & (LED[1] == Password_1[1]) & (LED[2] == Password_1[2]) & (LED[3] == Password_1[3]) & (LED[4] == Password_1[4]) & (LED[5] == Password_1[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(开锁)
if (CurKey == 10) //检测是否按下"修改键",进入密码修改状态
{
BeepSet(BT_BUTTON);
InputNewPassword_1();
}
}
else
{
Wrong = 2; //第2次输入密码错误,点亮黄灯,报警
LightType = LightingYellow;
LightCtrl(200);
BeepSet(BT_ALARM_2);
InputPassword(void); //第3次输入密码
if ((LED[0] == Password_1[0]) & (LED[1] == Password_1[1]) & (LED[2] == Password_1[2]) & (LED[3] == Password_1[3]) & (LED[4] == Password_1[4]) & (LED[5] == Password_1[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(开锁)
if (CurKey == 10) //检测是否按下"修改键",进入密码修改状态
{
BeepSet(BT_BUTTON);
InputNewPassword_1();
}
}
else
{
Wrong = 3; //第3次输入密码错误,点亮红灯,报警
LightType = LightingRed;
LightCtrl(0);
BeepSet(BT_ALARM_1);
}
}
}
if (Wrong >= 3)
Wrong = 0;
}
else if (CurKey == 13) //检测是否按下"上锁"键
{
BeepSet(BT_BUTTON);
if (CurKey == 11) //检测是否按下"输入"键
{
BeepSet(BT_BUTTON);
InputNewPassword_2();
if (CurKey <= 14 && CurKey >== 0) ///锁住键盘 (除按下解锁键外键盘无任何反应)
_nop_();
}
}
else if (CurKey == 15) //检测是否按下"解锁"键
{
BeepSet(BT_BUTTON);
if (CurKey == 11) //检测是否按下"输入"键
{
BeepSet(BT_BUTTON);
InputPassword(void); //第1次输入密码
if ((LED[0] == Password_2[0]) & (LED[1] == Password_2[1]) & (LED[2] == Password_2[2]) & (LED[3] == Password_2[3]) & (LED[4] == Password_2[4]) & (LED[5] == Password_2[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(解锁)
//键盘解锁
}
else
{
Wrong = 1; //第1次输入密码错误,点亮黄灯,报警2
LightType = LightingYellow;
LightCtrl(200);
BeepSet(BT_ALARM_2);
InputPassword(void); //第2次输入密码
if ((LED[0] == Password_1[0]) & (LED[1] == Password_1[1]) & (LED[2] == Password_1[2]) & (LED[3] == Password_1[3]) & (LED[4] == Password_1[4]) & (LED[5] == Password_1[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(解锁)
//键盘解锁
}
else
{
Wrong = 2; //第2次输入密码错误,点亮黄灯,报警2
LightType = LightingYellow;
LightCtrl(200);
BeepSet(BT_ALARM_2);
InputPassword(void); //第3次输入密码
if ((LED[0] == Password_1[0]) & (LED[1] == Password_1[1]) & (LED[2] == Password_1[2]) & (LED[3] == Password_1[3]) & (LED[4] == Password_1[4]) & (LED[5] == Password_1[5]))
{
LightType = LightingGreen;
LightCtrl(200); //输入密码正确,点亮绿灯(解锁)
//键盘解锁
}
else
{
Wrong = 3; //第3次输入密码错误,点亮红灯,报警1
LightType = LightingRed;
LightCtrl(0);
BeepSet(BT_ALARM_1);
if (CurKey <= 14 && CurKey >== 0) ///锁住键盘 (除按下解锁键外键盘无任何反应)
_nop_()
}
}
}
if (Wrong >= 3)
Wrong = 0;
}
}
}
// 主程序
void main(void)
{
// 系统变量初始化
halfCount = 0;
InitSys();
// 启动中断,启动定时器
TR2 =1;
EA = 1;
// 程序主循环
while (1)
{
if (Flag10ms)
{
Flag10ms = 0;
// 数码管动态扫描
UpdateLed();
// 更新显示内容
ChDisp();
// 按键扫描每0.1秒扫描一次
if (++ halfCount >= 10)
{
halfCount = 0;
KeyScan();
// 按键动作
KeyDone();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -