久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9296|回復: 25
打印 上一主題 下一主題
收起左側

Proteus仿真C51單片機的電子密碼鎖程序 24C02C

  [復制鏈接]
回帖獎勵 10 黑幣 回復本帖可獲得 1 黑幣獎勵! 每人限 1 次
跳轉到指定樓層
樓主
本帖最后由 lxl_51h 于 2020-5-22 23:14 編輯

分享電子密碼鎖項目

第一次發帖,分享電子密碼鎖項目。關鍵代碼段注釋詳盡。
仿真視頻如下連接:







單片機源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>

  3. #include "lxl_24C02C.h"
  4. #include "uart.h"
  5. #include "LCD1602.h"
  6. #include <keypad44.h>

  7. sbit greenled=P2^3;                                                //Enter the right passwords,green led will lighting.
  8. sbit lock=P2^4;                                                                //Enter the right passwords,electronic lock will unlock.
  9. sbit redled=P2^5;                                                        //Enter the wrong passwords,red led will lighting.
  10. void show_base_infromation()        //show something personal information on the screen of LCD1206.just delay for a moment than cleanning all screen.
  11. {
  12.         uchar i;
  13.         LCMDisplayString(0,0,"Design:LiXinLong");
  14.         LCMDisplayString(1,0,"My ID:208171421");        
  15.         for(i=0;i<4;i++)keypad_delay(65535);                //delay for a moment
  16.         LCMClear();                                                                                                                        //clean all screen.
  17. }

  18. void set_init_password()                        //set users' initialize passwords.
  19. {
  20.         Master_writeByte(1,1);                        //The user 1 ,password:0001,password saved in register 1 of 24C02C.
  21.         Master_writeByte(2,2);                        //The user 2 ,password:0002,password saved in register 2 of 24C02C.
  22.         Master_writeByte(3,3);                        //The user 3 ,password:0003,password saved in register 3 of 24C02C.
  23. }
  24. int get_user_password(uchar i)//Get users' password ,i is the register number of the specific user.
  25. {
  26.         int read=Master_readByte(i);//read the appointed register.
  27.         return _cror_(read,8);                        //translated the value to int,and return the value.
  28. }
  29. void main()
  30. {
  31.         
  32.         uchar presstimes=0;                                        //the register keep user's press times,maximum are 4,because the munber of password bits are defined as 4.  
  33.         uchar enter_times=0;                                //if user enter wrong password ,the register keep user's press times of "Enter",maximum are 3,beyond 3 account will locked(forbid to enter any number.).
  34.         bit changepswd_state=0;                        //flage bit of user pressed "Reset password" key,1:pressed,0:not pressed.
  35.         bit change_use1=0;                                        //flage bit of user1 entered the old password correctly,and input the new passwords done.
  36.         bit change_use2=0;                                        //*****************************similar to change_use1***********************************
  37.         bit change_use3=0;                                        //*****************************similar to change_use1***********************************
  38.         bit beyond3times=1;                                        //flage bit of users' entered the wrong password beyond 3 times.1: not beyond,0:beyond.

  39.         
  40.         int readkeypad;                                                                                                                //the register keep the keypad return value.
  41.         int keypadvalue=0;                                                                                                //the register keep the value when 4 times pressed.
  42.         int press1,press2,press3,press4;                                        //press1:the value of 1st keypad return value multiple oppointed scale.press2-3 are similar to this.
  43.         UartInit();                                                                                                                                //initialize the USART for printf() to debug.
  44.         LCMInit();                                                                                                                                //initialize the LCD1206.
  45.         printf("\nshow some \npersonal \ninfromation!\n");
  46.         show_base_infromation();
  47.         printf("\nplease enter your\npassword\n");
  48.         keypad_delay(65535);        
  49.         set_init_password();
  50.         LCMDisplayString(0,0,"Input pswd:");
  51.         LCMDisplayString(1,0,"You error 0 Time");
  52.         
  53.         while(1)
  54.         {
  55.                 readkeypad=key_scan();
  56.                 if(((readkeypad<10)||(readkeypad==14)||(readkeypad==13))&&beyond3times)//allowed press 0-9,"clean" or "enter" when account not lock(wrong password not beyond 3 times).
  57.                 {
  58.                         presstimes=presstimes+1;
  59.                         switch(presstimes)
  60.                         {
  61.                                 case 1:                                                                                                                        //the 1st bit of 4bits password.
  62.                                         {
  63.                                                 press1=readkeypad*1000;        
  64.                                                 LCMDisplayString(0,11,"*");               
  65.                                                 printf("pressed %d\n",readkeypad);
  66.                                         }break;
  67.                                 case 2:                                                                                                                        //the 2nd bit of 4bits password.
  68.                                         {
  69.                                                 press2=readkeypad*100;
  70.                                                 LCMDisplayString(0,11,"**");
  71.                                                 printf("pressed %d\n",readkeypad);
  72.                                         }break;
  73.                                 case 3:                                                                                                                        //the 3rd bit of 4bits password.
  74.                                         {
  75.                                                 press3=readkeypad*10;
  76.                                                 LCMDisplayString(0,11,"***");
  77.                                                 printf("pressed %d\n",readkeypad);
  78.                                         }break;
  79.                                 case 4:                                                                                                                        //the 4th bit of 4bits password.
  80.                                         {
  81.                                                 press4=readkeypad;
  82.                                                 LCMDisplayString(0,11,"****");
  83.                                                 printf("pressed %d\n\n",readkeypad);
  84.                                         }break;
  85.                                 default:break;                                
  86.                         }                        
  87.                 }
  88.                
  89.                 if((presstimes<=5)&&(readkeypad>11))                //Entered 4bits password,checking whether "Enter" or "Clean" pressed.
  90.                         {
  91.                                 switch(readkeypad)
  92.                                 {
  93.                                         case 14:                                                                                                        //pressed 'Enter' key
  94.                                         {
  95.                                                 keypadvalue=press1+press2+press3+press4;
  96.                                                 presstimes=0;
  97.                                                 if(enter_times<3)LCMDisplayString(0,11,"    ");
  98.                                                 if(change_use1)                                                                        
  99.                                                         {
  100.                                                                 Master_writeByte(1,keypadvalue);
  101.                                                                 change_use1=0;
  102.                                                                 LCMClear();
  103.                                                                 LCMDisplayString(0,0,"Input pswd:");
  104.                                                                 LCMDisplayString(1,0,"You error 0 Time");
  105.                                                         }
  106.                                                 if(change_use2)
  107.                                                         {
  108.                                                                 Master_writeByte(2,keypadvalue);
  109.                                                                 change_use2=0;LCMClear();
  110.                                                                 LCMDisplayString(0,0,"Input pswd:");
  111.                                                                 LCMDisplayString(1,0,"You error 0 Time");
  112.                                                         }
  113.                                                 if(change_use3)
  114.                                                         {
  115.                                                                 Master_writeByte(3,keypadvalue);
  116.                                                                 change_use3=0;
  117.                                                                 LCMClear();
  118.                                                                 LCMDisplayString(0,0,"Input pswd:");
  119.                                                                 LCMDisplayString(1,0,"You error 0 Time");
  120.                                                         }//printf("pswd changed!\n");
  121.                                                 
  122.                                                 if((keypadvalue==get_user_password(1))||(keypadvalue==get_user_password(2))||(keypadvalue==get_user_password(3)))//matching password saved in 24C02C,only password are correct can match successful.
  123.                                                 {
  124.                                                         greenled=0;
  125.                                                         lock=0;
  126.                                                         redled=1;
  127.                                                         printf("\nWelcome You to\nGo Home!\n");
  128.                                                         enter_times=0;
  129.                                                         LCMDisplayChar(1,10,'0');
  130.                                                 }else                                                                                                                //match password failed.
  131.                                                 {
  132.                                                         greenled=1;
  133.                                                         lock=1;
  134.                                                         redled=0;
  135.                                                         printf("\nPasswords error\nplease try\nagain!\n");
  136.                                                         enter_times++;
  137.                                                         switch(enter_times)                                                //show times of enter wrong password.
  138.                                                         {
  139.                                                                 case 0:LCMDisplayChar(1,10,'0');break;
  140.                                                                 case 1:LCMDisplayChar(1,10,'1');break;
  141.                                                                 case 2:LCMDisplayChar(1,10,'2');break;
  142.                                                                 default:                                                                                //enter wrong password 3 times,lock the account!
  143.                                                                         {
  144.                                                                                 beyond3times=0;
  145.                                                                                 LCMClear();
  146.                                                                                 LCMDisplayString(0,0,"Account Locked!");
  147.                                                                                 LCMDisplayString(1,0,"Call 1401856153");
  148.                                                                                 printf("\nInput error\nbeyond 3 times\nthe account\nlocked!\nplease Contact \nadministrator\n");
  149.                                                                         }break;
  150.                                                         }
  151.                                                 }
  152.                                         }break;
  153.                                         case 13:                                                                                                        //press 'Clean' key,clean all entered numbers.
  154.                                         {
  155.                                                 presstimes=0;
  156.                                                 LCMDisplayString(0,11,"    ");
  157.                                                 greenled=1;
  158.                                                 lock=1;
  159.                                                 printf("\nPressed Clean!\n");
  160.                                                 
  161.                                         }break;
  162.                                         default:break;
  163.                                 }
  164.                                 
  165.                         }
  166.                         
  167.                         if((presstimes==5)&&(readkeypad<10))//if 5th entered is a number of 0-9.clean all entered passwords,because passwords were designed 4bits.
  168.                         {                                
  169.                                 presstimes=0;
  170.                                 LCMDisplayString(0,11,"    ");
  171.                                 printf("\nPlease Reenter Your\nPassword\n");
  172.                         }
  173.                         
  174.                         if(readkeypad==12)                                                                        //Press "reset password" key,enter to reset passwords process while loop.
  175.                         {
  176.                                 changepswd_state=1;
  177.                                 LCMClear();
  178.                                 LCMDisplayString(0,0,"Enter Old pswd:");
  179.                                 printf("\nEnter your old\npswd now:\n");
  180.                         }else changepswd_state=0;
  181.                         
  182.                         while(changepswd_state)                                                        //Reset passwords while loop
  183.                         {
  184.                                 readkeypad=key_scan();
  185.                                         if((readkeypad<10)||(readkeypad==14)||(readkeypad==13))
  186.                                         {
  187.                                                 presstimes=presstimes+1;
  188.                                                 switch(presstimes)
  189.                                                 {
  190.                                                         case 1:        
  191.                                                                 {
  192.                                                                         press1=readkeypad*1000;        
  193.                                                                         LCMDisplayString(1,0,"*");               
  194.                                                                         printf("pressed %d\n",readkeypad);
  195.                                                                 }break;
  196.                                                         case 2:
  197.                                                                 {
  198.                                                                         press2=readkeypad*100;               
  199.                                                                         LCMDisplayString(1,0,"**");               
  200.                                                                         printf("pressed %d\n",readkeypad);
  201.                                                                 }break;
  202.                                                         case 3:
  203.                                                                 {
  204.                                                                         press3=readkeypad*10;               
  205.                                                                         LCMDisplayString(1,0,"***");        
  206.                                                                         printf("pressed %d\n",readkeypad);
  207.                                                                 }break;
  208.                                                         case 4:        
  209.                                                                 {
  210.                                                                         press4=readkeypad;                                
  211.                                                                         LCMDisplayString(1,0,"****");        
  212.                                                                         printf("pressed %d\n\n",readkeypad);
  213.                                                                 }break;
  214.                                                         default:break;                                
  215.                                                 }                        
  216.                                         }
  217.                                        
  218.                                         if((presstimes<=5)&&(readkeypad>11))
  219.                                         {
  220.                                                 switch(readkeypad)
  221.                                                 {
  222.                                                         case 14:                                                                                //press 'enter' key
  223.                                                                 {
  224.                                                                                 keypadvalue=press1+press2+press3+press4;
  225.                                                                                 presstimes=0;
  226.                                                                                 LCMDisplayString(1,0,"    ");
  227.                                                                                 if(keypadvalue==get_user_password(1))                                //matched user1's passwords.
  228.                                                                                 {
  229.                                                                                         LCMClear();
  230.                                                                                         LCMDisplayString(1,0,"Enter New pswd:");
  231.                                                                                         presstimes=0;
  232.                                                                                         change_use1=1;
  233.                                                                                         changepswd_state=0;
  234.                                                                                 }else if(keypadvalue==get_user_password(2))        //matched user2's passwords.
  235.                                                                                 {
  236.                                                                                         LCMClear();
  237.                                                                                         LCMDisplayString(1,0,"Enter New pswd:");
  238.                                                                                         presstimes=0;
  239.                                                                                         change_use2=1;
  240.                                                                                         changepswd_state=0;
  241. ……………………

  242. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
PASSWORDLOCK.zip (642.67 KB, 下載次數: 220)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏6 分享淘帖 頂1 踩

相關帖子

回復

使用道具 舉報

沙發
ID:524698 發表于 2020-5-28 15:40 | 只看該作者
特別好用,有紅外功能就好了
回復

使用道具 舉報

板凳
ID:755919 發表于 2020-5-28 16:15 | 只看該作者
特別好用,收藏收藏,感謝分享
回復

使用道具 舉報

地板
ID:763926 發表于 2020-5-29 03:34 | 只看該作者
感覺不錯啊,樓樓,就是不知道用起來如何,一會下載試一試
回復

使用道具 舉報

5#
ID:302325 發表于 2020-6-1 01:54 | 只看該作者
感謝分享                           
回復

使用道具 舉報

6#
ID:766915 發表于 2020-6-8 21:40 | 只看該作者
樓主這個有i2c嗎
回復

使用道具 舉報

7#
ID:751649 發表于 2020-6-9 10:20 | 只看該作者
sf666 發表于 2020-6-8 21:40
樓主這個有i2c嗎

項目樹中的“lxl_24C02C.c”就是軟件模擬I2C通信協議
回復

使用道具 舉報

8#
ID:774738 發表于 2020-6-10 10:13 | 只看該作者
不錯,我先試試能不能行
回復

使用道具 舉報

9#
ID:775010 發表于 2020-6-11 21:48 | 只看該作者
感謝大佬分享
回復

使用道具 舉報

10#
ID:768868 發表于 2020-6-14 14:33 | 只看該作者
如果把C52改成C51得話這個得怎么改啊
回復

使用道具 舉報

11#
ID:776555 發表于 2020-6-14 15:57 | 只看該作者

如果把C52改成C51得話這個得怎么改啊
回復

使用道具 舉報

12#
ID:778494 發表于 2020-6-14 17:02 | 只看該作者
感謝分享,有個想法,如果那個輸入部分換成那種獨立按鍵的怎么樣
回復

使用道具 舉報

13#
ID:751649 發表于 2020-6-15 08:11 | 只看該作者
sdsfsade 發表于 2020-6-14 15:57
如果把C52改成C51得話這個得怎么改啊

把<reg52.h>改一下就行了。
回復

使用道具 舉報

14#
ID:751649 發表于 2020-6-15 08:12 | 只看該作者
jiafangyuan 發表于 2020-6-14 17:02
感謝分享,有個想法,如果那個輸入部分換成那種獨立按鍵的怎么樣

可以的,本質上沒變,僅僅是外觀變了
回復

使用道具 舉報

15#
ID:777893 發表于 2020-6-15 08:57 | 只看該作者
這個真的可以牛批
回復

使用道具 舉報

16#
ID:781759 發表于 2020-6-24 11:23 | 只看該作者
謝謝樓主
回復

使用道具 舉報

17#
ID:789099 發表于 2020-6-25 00:59 | 只看該作者
感謝樓主
回復

使用道具 舉報

18#
ID:495287 發表于 2020-6-27 13:46 | 只看該作者
馬克,后面再仔細學習,謝謝分享。
回復

使用道具 舉報

19#
ID:782689 發表于 2020-6-29 02:34 | 只看該作者
lxl_51h 發表于 2020-6-15 08:11
把改一下就行了。

改完之后可以直接實現這個功能嗎?新手求告知
回復

使用道具 舉報

20#
ID:751649 發表于 2020-6-29 17:36 | 只看該作者
aaabbbcd 發表于 2020-6-29 02:34
改完之后可以直接實現這個功能嗎?新手求告知

項目中未用到定時器T和中斷,所以51系列的微控器都可以實現此功能。僅僅改一下頭文件就信了。
回復

使用道具 舉報

21#
ID:795233 發表于 2020-7-3 16:53 | 只看該作者
不會用啊,誰能教教我
回復

使用道具 舉報

22#
ID:771985 發表于 2020-8-7 17:53 | 只看該作者
樓主,這程序是不是可以實現多個密碼開鎖
回復

使用道具 舉報

23#
ID:595237 發表于 2020-8-8 10:09 | 只看該作者
4位密碼?
回復

使用道具 舉報

24#
ID:1097230 發表于 2023-10-25 12:36 | 只看該作者
真的很牛的!

回復

使用道具 舉報

25#
ID:1063561 發表于 2023-11-5 09:18 | 只看該作者
MAAAAAARK學習,謝謝分享。
回復

使用道具 舉報

26#
ID:1103460 發表于 2023-12-9 21:01 | 只看該作者
宿舍可以使用嗎
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产激情在线看 | 精品粉嫩aⅴ一区二区三区四区 | 国产精品久久久精品 | 日韩欧美国产综合 | av在线免费观看网站 | 国产一区二区三区色淫影院 | 亚洲综合色站 | 欧美性网| 日韩一区二区三区视频 | 自拍偷拍第一页 | 特黄特色大片免费视频观看 | 国产一区二区在线播放视频 | 久久国产一区二区三区 | 男人的天堂久久 | 亚洲欧美激情国产综合久久久 | 91在线网站 | 久久精品国产一区 | 欧美一级欧美三级在线观看 | 欧美日韩久久 | 欧美精品一区二区三区在线 | 成人黄色电影在线播放 | 91 在线 | 国产激情在线观看 | 欧美一区二区黄 | 欧美视频三级 | 在线视频国产一区 | 国产偷录视频叫床高潮对白 | 欧美一区二区视频 | 国产精品久久久久久久久久久久冷 | 精品视频一区二区三区 | 国产在线网站 | 另类一区| 神马久久久久久久久久 | 欧美日韩在线一区 | 亚洲一区电影 | 亚洲精品乱码久久久久久蜜桃91 | 国产精品久久久久无码av | 国产黄色网址在线观看 | 久夜精品| 婷婷久久精品一区二区 | 成年人视频免费在线观看 |