欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4289|回復: 2
收起左側

帶AT24C02存儲的單片機六位密碼鎖Proteus仿真+代碼

[復制鏈接]
ID:443049 發表于 2018-12-10 09:43 | 顯示全部樓層 |閱讀模式
按行列鍵盤0~9輸入六位密碼數據存儲到AT24C02,按“=”鍵從AT24C02中讀取數據并在液晶屏中顯示,再按“+/-”清屏。
按行列鍵盤0~9輸入六位密碼,按“=”驗證密碼,正確顯示“TURE”,并且亮綠燈;錯誤顯示“FLASE”,并且亮紅燈,蜂鳴器響起。
如果輸入驗證密碼過程中輸入錯誤,可按“%”退位,也可按“?”清除所有密碼。

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png 0.png 0.png

單片機源程序如下:
  1. #include <reg52.H>
  2. #include "LCD1602_run.h"
  3. #include "LCD1602_mid_run.h"
  4. #include "keypad.h"
  5. #include "timer_Init.h"
  6. #include "iic.h"
  7. #include "at24c02.h"
  8. #include <string.h>

  9. sbit LedRed = P0^0;
  10. sbit LedGreen = P0^1;

  11. void main()
  12. {        
  13.         unsigned char Cou;
  14.         unsigned char KeyBuff[7];
  15.         unsigned char KeyPassword[7];
  16.         unsigned char i;
  17.         unsigned char KeyBuffIndex=0;
  18.         unsigned char KeyBuffIndex2=0;
  19.   Timer_Init();
  20.         LCD_initial();
  21.         P0=0xff;
  22.         while(1)
  23.         {     
  24.           if((KeyNum <= '9') && (KeyNum >= '0') && (KeyNum != '=')&& (KeyNum != 'c')) /*存密碼*/
  25.                 {
  26.                         
  27.                         KeyBuff[KeyBuffIndex] = KeyNum;
  28.                         At24c02_Write_Add(KeyBuffIndex, KeyNum);
  29. //                         LCD1602_write_char(        0,KeyBuffIndex,' ');
  30.                         LCD1602_write_char(        0,KeyBuffIndex,'*');
  31.                                        
  32.                         KeyBuffIndex++;
  33.                         if(KeyBuffIndex == 6)
  34.                         {
  35.                                 KeyBuff[KeyBuffIndex] = '\0';
  36.                                 KeyBuffIndex = 0;
  37.                         }

  38.                         while(KeyNum != 0x11);
  39.                 }        
  40.                
  41.                 if(KeyNum == '=')/*顯示存儲密碼*/
  42.                 {
  43.                         
  44.                         LCD_write_cmd(0X01);
  45.                         while(KeyNum != 0x11);
  46.                         for(i = 0; i < 6; i++)
  47.                         {
  48.                                 KeyPassword [i] = At24c02_Read_Add(i);
  49.                         }
  50.                         KeyPassword [i] = '\0';
  51.                         LCD1602_write_string(1,0,KeyPassword);
  52.                         Cou = 0;
  53.                         
  54.                 }
  55.                
  56.                 if(KeyNum == 'c') /*清屏*/
  57.                 {
  58.                         
  59.                         while(KeyNum != 0x11);
  60.                         LCD_write_cmd( 0x01 );
  61.                         break;
  62.                 }                        
  63.         }
  64.         
  65.         while(1)
  66.         {
  67.                 if((KeyNum <= '9') && (KeyNum >= '0') && (KeyNum != '=') && (KeyNum != '%') && (KeyNum != '?') ) /*輸入密碼*/
  68.                         {
  69.                                 KeyBuff[KeyBuffIndex2] = KeyNum;
  70. //                                 LCD1602_write_char(        1,KeyBuffIndex2,KeyNum);
  71.                                 LCD1602_write_char(        0,KeyBuffIndex2,'*');
  72.                                 
  73.                                 KeyBuffIndex2 ++;                                
  74.                                 if(KeyBuffIndex2 == 6)
  75.                                 {                                       
  76.                                         KeyBuff[KeyBuffIndex2] = '\0';
  77.                                         KeyBuffIndex2 = 0;
  78.                                 }
  79.                                 
  80.                                 //Cou ++;
  81.                                 while(KeyNum != 0x11);
  82.                         }        
  83.                
  84.                 if( (KeyNum == '%') && (KeyBuffIndex2 > 0 ) ) /*退位*/
  85.                 {
  86.                   KeyBuffIndex2 --;
  87. //                        KeyBuff[KeyBuffIndex] = KeyNum;
  88.                         LCD1602_write_char(        0,KeyBuffIndex2,' ');
  89. //                        KeyBuffIndex2 = KeyBuffIndex2 - 1;
  90.                         //LCD1602_write_char(        0,KeyBuffIndex2,'*');
  91.                         while(KeyNum != 0x11);
  92.                 }
  93.                
  94.                 if(KeyNum == '?') /*清屏*/
  95.                 {
  96.                         
  97.                         while(KeyNum != 0x11);
  98.                         LCD_write_cmd( 0x01 );
  99.                         KeyBuffIndex2 = 0;
  100.                         
  101.                 }                        
  102.                         
  103.                 if( KeyNum == '=' )/*檢驗密碼*/
  104.                 {
  105.                   for(i = 0; i < 6; i++)
  106.                         {
  107.                                 KeyPassword [i] = At24c02_Read_Add(i);
  108.                         }
  109.                          KeyPassword [i] = '\0';
  110.                          LCD_write_cmd( 0x01 );                        
  111.                         if( strcmp( KeyBuff,KeyPassword ) == 0 )
  112.                                 {
  113. ……………………

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

所有資料51hei提供下載:
密碼鎖.rar (115.17 KB, 下載次數: 129)


評分

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

查看全部評分

回復

使用道具 舉報

ID:447989 發表于 2018-12-17 15:56 | 顯示全部樓層
謝謝分享!見識學習。
回復

使用道具 舉報

ID:442274 發表于 2021-5-18 22:15 | 顯示全部樓層
初始界面液晶無顯示,要按鍵才顯示*號的密文
回復

使用道具 舉報

無效樓層,該帖已經被刪除
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表