有没有大佬帮忙看一下,这个功能该怎么加进去

普中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显示键码
                }
        }
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值