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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 9261|回復(fù): 25
打印 上一主題 下一主題
收起左側(cè)

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

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

分享電子密碼鎖項(xiàng)目

第一次發(fā)帖,分享電子密碼鎖項(xiàng)目。關(guān)鍵代碼段注釋詳盡。
仿真視頻如下連接:







單片機(jī)源程序如下:
  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. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

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


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

項(xiàng)目樹中的“l(fā)xl_24C02C.c”就是軟件模擬I2C通信協(xié)議
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

如果把C52改成C51得話這個(gè)得怎么改啊
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

把<reg52.h>改一下就行了。
回復(fù)

使用道具 舉報(bào)

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

可以的,本質(zhì)上沒變,僅僅是外觀變了
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

18#
ID:495287 發(fā)表于 2020-6-27 13:46 | 只看該作者
馬克,后面再仔細(xì)學(xué)習(xí),謝謝分享。
回復(fù)

使用道具 舉報(bào)

19#
ID:782689 發(fā)表于 2020-6-29 02:34 | 只看該作者

改完之后可以直接實(shí)現(xiàn)這個(gè)功能嗎?新手求告知
回復(fù)

使用道具 舉報(bào)

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

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

22#
ID:771985 發(fā)表于 2020-8-7 17:53 | 只看該作者
樓主,這程序是不是可以實(shí)現(xiàn)多個(gè)密碼開鎖
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

回復(fù)

使用道具 舉報(bào)

25#
ID:1063561 發(fā)表于 2023-11-5 09:18 | 只看該作者
MAAAAAARK學(xué)習(xí),謝謝分享。
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 欧美日日| 欧美男人天堂 | 精品国产欧美一区二区三区成人 | 日本午夜网站 | xxxxxx国产| 久久机热 | 在线看一区二区 | 色香婷婷 | 91日日| 国产精品免费一区二区三区四区 | 国产高清免费 | 99re免费| 黄网站在线观看 | 99精品电影 | 成人二区 | 天堂网中文字幕在线观看 | 久久亚洲一区二区 | 久久久精品一区二区三区 | 在线看91| 国产精品精品久久久 | 在线中文字幕日韩 | 少妇精品久久久久久久久久 | 天天艹| 91在线视频免费观看 | 免费黄色的视频 | 久久精品国产免费 | 在线免费观看日本视频 | 国产一区二区三区www | 国产精品视频网 | 日韩成人免费在线视频 | 18成人在线观看 | 黄a在线观看 | 亚洲精品一区二区三区中文字幕 | 欧美激情国产日韩精品一区18 | 精品网 | 国产精品久久福利 | 亚洲精品中文字幕av | 国产精品18久久久久久白浆动漫 | 一区二区三区视频在线观看 | 欧美精品在线免费 | 久久99精品久久久久 |