完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
proteus设计的密码锁中利用矩阵键盘获取按键后得到的值,来在1602显示屏中显示对应的值,但设置的条件甚至不存在仍然执行相应的函数且不断重启显示屏。
#include #include void Init_LCD_1602();//1602LCD³õʼ»¯ void Busy_LCD_1602();//æµÅÐ¶Ï void Write_Data_LCD_1602(unsigned char Data_Dat);//дÃüÁî void Write_Order_LCD_1602(unsigned char Data_Dat);//дÊý¾Ý #define LCD_1602_IO P2//lcdÊý¾Ý¿Ú¶¨Òå sbit RS_LCD_1602=P1^5;//Êý¾Ý»òÃüÁîÑ¡Ôñ¶Î sbit RW_LCD_1602=P1^6;//¶ÁдѡÔñ¶Î sbit E_LCD_1602=P1^7;//ʹÄÜ¶Ë unsigned char show_jund=0;//չʾ״̬ unsigned char lock_jund=0;//ÉÏËø״̬£¬1ΪËø unsigned char input_type=0;//ÊäÈë״̬,0 unsigned int keyword[6]={1,2,3,4,5,6};//³õʼÃÜÂë unsigned int input_keyword[6]={0,0,0,0,0,0};//ÊäÈëÃÜÂë unsigned char key_count_num=0;//ÊäÈëÃÜÂëÊý unsigned int key;//ÊäÈëÖµ unsigned int result;//¶Ô±ÈÖµ void delay(unsigned int x_ms)//ÑÓ³Ùº¯Êý£¬0.1Ãë {unsigned int i,j; for(i=x_ms;i>0;i--) for(j=114;j>0;j--); } void Busy_LCD_1602()//æµÅÐ¶Ï {unsigned char Busy_Dat=0; LCD_1602_IO=0xFF; RS_LCD_1602=0; RW_LCD_1602=1; do { E_LCD_1602=1;//ˢРBusy_Dat=LCD_1602_IO; E_LCD_1602=0; } while(Busy_Dat&0x80); LCD_1602_IO=0xFF; } void Init_LCD_1602()//³õʼ»¯ { delay(15); Write_Order_LCD_1602(0x38); delay(5); Write_Order_LCD_1602(0x38); delay(15); Write_Order_LCD_1602(0x38); Write_Order_LCD_1602(0x38); Write_Order_LCD_1602(0x08); Write_Order_LCD_1602(0x01); Write_Order_LCD_1602(0x06); Write_Order_LCD_1602(0x0E); } void Write_Data_LCD_1602(unsigned char Data_Dat)//дÊý¾Ý { Busy_LCD_1602(); E_LCD_1602=0; RS_LCD_1602=1; RW_LCD_1602=0; LCD_1602_IO=Data_Dat; E_LCD_1602=1; E_LCD_1602=0; LCD_1602_IO=0xFF; } void Write_Order_LCD_1602(unsigned char Data_Dat)//дλÖÃÃüÁî { Busy_LCD_1602(); E_LCD_1602=0; RS_LCD_1602=0; RW_LCD_1602=0; LCD_1602_IO=Data_Dat; E_LCD_1602=1; E_LCD_1602=0; LCD_1602_IO=0xFF; } void Locked()//Ëø״̬ { input_type=1; Write_Order_LCD_1602(0x80+0x06); Write_Data_LCD_1602(0x4C); Write_Data_LCD_1602(0x6F); Write_Data_LCD_1602(0x63); Write_Data_LCD_1602(0x6B); Write_Data_LCD_1602(0x65); Write_Data_LCD_1602(0x64);// //·µ»ØÃÜÂë³õʼÊäÈëλÖà } void Unlock()//д½âËøµÄÓ¢ÎÄ×Ö·û { input_type=0; Write_Order_LCD_1602(0x80+0x06); Write_Data_LCD_1602(0x55); Write_Data_LCD_1602(0x6E); Write_Data_LCD_1602(0x6C); Write_Data_LCD_1602(0x6F); Write_Data_LCD_1602(0x63); Write_Data_LCD_1602(0x6B); } void Sucess()//д³É¹¦µÄÓ¢ÎÄ×Ö·û { input_type=1; Write_Order_LCD_1602(0x80+0x06); Write_Data_LCD_1602(0x53); Write_Data_LCD_1602(0x75); Write_Data_LCD_1602(0x63); Write_Data_LCD_1602(0x65); Write_Data_LCD_1602(0x73); Write_Data_LCD_1602(0x73); } void Error()//д´íÎóµÄÓ¢ÎÄ×Ö·û { Write_Order_LCD_1602(0x80+0x06); Write_Data_LCD_1602(0x20); Write_Data_LCD_1602(0x45); Write_Data_LCD_1602(0x72); Write_Data_LCD_1602(0x72); Write_Data_LCD_1602(0x6F); Write_Data_LCD_1602(0x72); input_type=0; } void Reset()//дÖØÖõÄÓ¢ÎÄ×Ö·û {Write_Order_LCD_1602(0x80+0x06); Write_Data_LCD_1602(0x20); Write_Data_LCD_1602(0x52); Write_Data_LCD_1602(0x65); Write_Data_LCD_1602(0x73); Write_Data_LCD_1602(0x65); Write_Data_LCD_1602(0x74); input_type=1; } unsigned char keyscan()//¼üÅÌɨÃè { unsigned char num=0; static char key; //************************************* P3=0xFE; delay(10); num=P3; if(num!=0xFE) {delay(10); num=P3; if(num!=0xFE) {while(P3!=0xFE); switch(num) {case 0x7E:key=1; break; case 0xBE:key=2; break; case 0xDE:key=3; break; case 0xEE:key=-1; break; }//ÖØÖð´¼üËùÔÚλÖà } } //************************************************ P3=0xFD; delay(10); num=P3; if(num!=0xFD) {delay(10); num=P3; if(num!=0xFD) {while(P3!=0xFD); switch(num) {case 0x7D:key=4; break; case 0xBD:key=5; break; case 0xDD:key=6; break; case 0xED:key=-2; break; }//ÉÏËø°´¼üËùÔÚλÖà } } //************************************************ P3=0xFB; delay(10); num=P3; if(num!=0xFB) {delay(10); num=P3; if(num!=0xFB) {while(P3!=0xFB); switch(num) {case 0x7B:key=7; break; case 0xBB:key=8; break; case 0xDB:key=9; break; case 0xEB:key=-3; break; }//չʾ״̬ËùÔÚλÖà } } //************************************************ P3=0xF7; delay(10); num=P3; if(num!=0xF7) {delay(10); num=P3; if(num!=0xF7) {while(P3!=0xF7); switch(num) {case 0x77:key=-4; break;//ÊäÈë״̬ËùÔÚλÖà case 0xB7:key=0; break; case 0xD7:key=-5; break;//ɾ³ý°´¼üËùÔÚλÖà } } } //************************************************ return key; //·µ»ØÊäÈëÖµ } unsigned char compare()//¶Ô±ÈÊäÈëÃÜÂëÓëÄÚÖÃÃÜÂëÊÇ·ñÏàͬ { unsigned int i=0; while(input_keyword==keyword&&i ![]() video_20240626_180937
|
|
相关推荐
1个回答
|
|
从您提供的代码片段来看,您正在使用51单片机设计一个密码锁,并使用Proteus进行仿真。您提到的问题是在满足等式条件的情况下,程序仍然执行相应的函数并不断重启显示屏。为了解决这个问题,我们可以按照以下步骤进行分析和解决:
1. 首先,检查您的密码锁设计中的等式条件。确保条件是正确的,并且逻辑关系是清晰的。例如,如果您的条件是检查输入的密码是否与预设的密码相匹配,那么您需要确保这个条件是正确的。 2. 检查矩阵键盘的读取逻辑。确保您正确地从矩阵键盘读取按键值,并且在读取过程中没有出现错误。这可能涉及到对键盘扫描算法的检查和优化。 3. 检查1602显示屏的显示逻辑。确保在满足条件时,显示屏能够正确地显示对应的值,并且在不满足条件时不执行任何操作。这可能涉及到对Write_Data_LCD_1602和Write_Order_LCD_1602函数的检查和优化。 4. 检查程序中的循环结构。确保在满足条件时,程序不会进入无限循环。这可能涉及到对程序中while、for等循环结构的检查和优化。 5. 如果问题仍然存在,尝试使用调试工具(如Keil uVision)对程序进行调试。通过设置断点和观察程序的运行过程,您可以更容易地找到问题所在。 6. 最后,确保您的Proteus仿真设置是正确的。检查仿真中的单片机、矩阵键盘和1602显示屏的连接是否正确,以及仿真环境是否符合您的设计要求。 通过以上步骤,您应该能够找到问题所在并进行相应的解决。如果问题仍然存在,请提供更详细的代码和描述,以便我们能够更准确地帮助您解决问题。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-shell脚本编写之变量
396 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-shell脚本编写之本地脚本的编写和执行
539 浏览 0 评论
【xG24 Matter开发套件试用体验】深入了解Silicon Labs xG24 Matter开发套件
697 浏览 0 评论
614 浏览 0 评论
634 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10942 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-1 07:07 , Processed in 0.428690 second(s), Total 44, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191