标题: 五位电子密码锁 带单片机源程序和仿真 [打印本页]

作者: wlsys    时间: 2016-9-16 13:25
标题: 五位电子密码锁 带单片机源程序和仿真
电子密码锁带源程序



仿真和全部源码下载:
电子密码锁.zip (28.65 KB, 下载次数: 57)

  1. /***********************************************
  2. *实例名称:电子密码锁
  3. *实例说明:实现五位密码的设置和解锁
  4. *作者:yd
  5. *时间:09.06.17
  6. ***********************************************/
  7. #include "target.h"
  8. uchar setPassword[5]={0x01,0x02,0x03,0x04,0x05};  //原始密码12345
  9. uchar passwordCount;
  10. uchar inputPassword[5]={0x00,0x00,0x00,0x00,0x00};
  11. uchar displayFramCount;         //显示界面序号,0x01~0x05
  12. void main()
  13. {
  14.   uchar  i;
  15.   uchar  keyValueRead;
  16.   uchar  framTwoLine;  //第二个界面中记录选择项所在行数
  17.   target_init();
  18.   displayFramCount=0x01;
  19.   passwordCount=0x00;
  20.   framTwoLine=0x01;   //第二界面中显示第一行
  21.   while(1)
  22.   {
  23.     switch(displayFramCount)
  24.         {
  25.           case 0x01:
  26.           {
  27.             displayFramOne();
  28.                    break;
  29.           }
  30.           case 0x02:
  31.           {
  32.             if(framTwoLine==0x01)
  33.               displayFramTwo(0);
  34.                 else
  35.                   displayFramTwo(1);
  36.             break;
  37.           }
  38.           case 0x03:
  39.           {
  40.             displayFramThree();
  41.             break;
  42.           }
  43.           case 0x04:
  44.           {
  45.             displayFramFour();
  46.             break;
  47.           }
  48.           case 0x05:
  49.           {
  50.             displayFramFive();
  51.                    break;
  52.           }
  53.           default: break;
  54.         }
  55.         displayFramCount|=0x80;  //displayFramCount最高位置1表示界面已显示
  56.         keyValueRead=get_key_value();
  57.     switch(keyValueRead)
  58.         {
  59.           case KEY_ONE:
  60.            {
  61.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  62.                  {
  63.                    if(passwordCount<0x05)
  64.                    {
  65.                      inputPassword[passwordCount]=0x01;
  66.                          passwordCount++;
  67.                    }
  68.                  }
  69.              break;
  70.            }
  71.           case KEY_TWO:
  72.            {
  73.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  74.                  {
  75.                    if(passwordCount<0x05)
  76.                    {
  77.                      inputPassword[passwordCount]=0x02;
  78.                          passwordCount++;
  79.                    }
  80.                  }
  81.              break;
  82.            }
  83.           case KEY_THREE:
  84.            {
  85.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  86.                  {
  87.                    if(passwordCount<0x05)
  88.                    {
  89.                      inputPassword[passwordCount]=0x03;
  90.                          passwordCount++;
  91.                    }
  92.                  }
  93.              break;
  94.            }
  95.           case KEY_FOUR:
  96.            {
  97.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  98.                  {
  99.                    if(passwordCount<0x05)
  100.                    {
  101.                      inputPassword[passwordCount]=0x04;
  102.                          passwordCount++;
  103.                    }
  104.                  }
  105.              break;
  106.            }
  107.           case KEY_FIVE:
  108.            {
  109.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  110.                  {
  111.                    if(passwordCount<0x05)
  112.                    {
  113.                      inputPassword[passwordCount]=0x05;
  114.                          passwordCount++;
  115.                    }
  116.                  }
  117.              break;
  118.            }
  119.           case KEY_SIX:
  120.            {
  121.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  122.                  {
  123.                    if(passwordCount<0x05)
  124.                    {
  125.                      inputPassword[passwordCount]=0x06;
  126.                          passwordCount++;
  127.                    }
  128.                  }
  129.              break;
  130.            }
  131.           case KEY_SEVEN:
  132.            {
  133.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  134.                  {
  135.                    if(passwordCount<0x05)
  136.                    {
  137.                      inputPassword[passwordCount]=0x07;
  138.                          passwordCount++;
  139.                    }
  140.                  }
  141.              break;
  142.            }
  143.           case KEY_EIGHT:
  144.            {
  145.              if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  146.                  {
  147.                    if(passwordCount<0x05)
  148.                    {
  149.                      inputPassword[passwordCount]=0x08;
  150.                          passwordCount++;
  151.                    }
  152.                  }
  153.              break;
  154.            }
  155.           case KEY_NINE:
  156.            {
  157.             if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  158.                  {
  159.                    if(passwordCount<0x05)
  160.                    {
  161.                      inputPassword[passwordCount]=0x09;
  162.                          passwordCount++;
  163.                    }
  164.                  }
  165.              break;
  166.            }
  167.           case KEY_ZERO:
  168.            {
  169.             if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
  170.                  {
  171.                    if(passwordCount<0x05)
  172.                    {
  173.                      inputPassword[passwordCount]=0x00;
  174.                          passwordCount++;
  175.                    }
  176.                  }
  177.              break;
  178.            }
  179.           case KEY_TRUE: //确认键
  180.            {
  181.              if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //设置界面进入输密码界面
  182.                  {
  183.                    displayFramCount=0x03;  //解密或者输密码时都要进入输密码界面
  184.                  }
  185.                  if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x03))  //输入密码确认
  186.                  {
  187.                    if(passwordCount==0x05)
  188.                    {
  189.                      for(i=0;i<5;i++)
  190.                          {
  191.                            if(framTwoLine==0x01)
  192.                            {
  193.                              displayFramCount=0x05;
  194.                            }
  195.                            else
  196.                            {
  197.                              if(framTwoLine==0x02)
  198.                                  {
  199.                                    displayFramCount=0x04;
  200.                                  }
  201.                            }
  202.                           
  203.                            if(inputPassword[i]!=setPassword[i])
  204.                            {
  205.                              displayFramCount=0x01;
  206.                                  break;
  207.                            }
  208.                          }
  209.                          passwordCount=0x00;
  210.                    }
  211.                  }
  212.                  if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x04))  //设置密码确认
  213.                  {
  214.                    if(passwordCount==0x05)
  215.                    for(i=0;i<5;i++)
  216.                    {
  217.                     setPassword[i]=inputPassword[i];
  218.                    }
  219.                    displayFramCount=0x01;
  220.                  }
  221.                  break;
  222.            }
  223.           case KEY_CLEAR:    //返回主界面键
  224.            {
  225.              displayFramCount=0x01;
  226.                  passwordCount=0x00;
  227.              break;
  228.            }
  229.           case KEY_SET:            //由主界面进入参数设置界面
  230.            {
  231.              if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x01))
  232.                  {
  233.                    displayFramCount=0x02;
  234.                  }
  235.                  passwordCount=0x00;
  236.              break;
  237.            }
  238.           case KEY_UP:
  239.            {
  240.              if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //设置界面中上移选择行
  241.                  {
  242.                      framTwoLine=0x01;
  243.                          displayFramCount=0x02;     
  244.                  }
  245.              break;
  246.            }
  247.           case KEY_DOWN:
  248.            {
  249.             if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //设置界面中上移选择行
  250.                 {
  251.                    framTwoLine=0x02;
  252.                    displayFramCount=0x02;
  253.                 }
  254.              break;
  255.            }
  256.         }
  257.    if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x03))  //输密码界面,此时显示****
  258.    {
  259.      displayMima(inputPassword,passwordCount,0x01);
  260.    }
  261.    if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x04))  //设置密码界面,此时显示设置的密码
  262.    {
  263.      displayMima(inputPassword,passwordCount,0x02);
  264.    }
  265.   }
  266. }
复制代码



作者: WFX777888    时间: 2016-9-16 13:41
谢谢分享资料收藏
作者: 慌张    时间: 2016-9-26 13:11
源程序不全啊
作者: 我爱傻瓜    时间: 2016-11-8 19:10
cghuvjulh
作者: 炳文    时间: 2016-12-3 09:21
源程序不全吗
作者: 翯panda    时间: 2016-12-27 23:19
很好五位电子密码锁
作者: 9ing.    时间: 2018-1-2 11:19
想下载文件学习学习
单片机有你更精彩!
作者: 技术求助    时间: 2018-1-14 08:14
好资料,51黑有你更精彩




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1