普中51单片机,我想在下面密码锁代码里加上光敏和数码管显示温度的功能,但是怎么都解决不了,是我程序本身有什么问题吗?希望大佬们帮忙看看
#include <REGX52.H>
#include "Delay.h" //包含Delay头文件
#include "LCD1602.h" //包含LCD1602头文件
#include "MatrixKey.h" //包含矩阵键盘头文件
typedef unsigned int u16;
typedef unsigned char u8;
unsigned char KeyNum;
unsigned int Password,count;
sbit DC_Motor=P1^0;
#define DC_MOTOR_RUN_TIME 5000
sbit BEEP=P2^5;
void main()
{
u16 i=2000;
LCD_Init(); //LCD初始化
LCD_ShowString(1,1,"PASSWORD:"); //LCD显示字符串
while(1)
{
DC_Motor=0;
KeyNum=MatrixKey(); //获取矩阵键盘键码
if(KeyNum) //如果有按键按下
{
if(KeyNum==1||KeyNum==2||KeyNum==3||KeyNum==4||KeyNum==5||KeyNum==6||KeyNum==7||KeyNum==8||KeyNum==9||KeyNum==10)
{
if (count<4)
{
Password*=10;
Password += KeyNum%10;
}
count++;
}
LCD_ShowNum(2,1,Password,4); //LCD显示键码
//DC_Motor=1;
if (KeyNum ==12)//确认
{
LCD_ShowString(1,11," ");
if(Password == 8888)
{
LCD_ShowString(1,14,"OK");
Password =0;
count =0;
LCD_ShowNum(2,1,Password,4);
DC_Motor=0;//¿ªÆôµç»ú
Delay(DC_MOTOR_RUN_TIME);
DC_Motor=1;
}
else
{
LCD_ShowString(1,11,"ERROR");
Password =0;
count =0;
LCD_ShowNum(2,1,Password,4); //更新LCD显示键码
while(i--)//Ñ»·2000´Î
{
BEEP=!BEEP;//²úÉúÒ»¶¨ÆµÂʵÄÂö³åÐźÅ
Delay(100);
}
i=0;//ÇåÁã
BEEP=0;//¹Ø±Õ·äÃùÆ÷
}
}
if (KeyNum ==11)//取消
{
Password =0;
count =0;
LCD_ShowNum(2,1,Password,4); //更新LCD显示键码
}
}
}
}