找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5477|回复: 3
打印 上一主题 下一主题
收起左侧

电子密码锁LCD12864中文显示,非常不错,毕业设计的同学的福音啊

[复制链接]
跳转到指定楼层
楼主
电子密码锁LCD12864中文显示的仿真原理图如下:

部资料下载:
电子密码锁LCD12864中文显示.rar (87.89 KB, 下载次数: 124)


  1. /***** LCD 12864 with KS0108B controller display driver *****/

  2. #define uchar unsigned char
  3. #include<drive_functions.h>
  4. #include<get_keys.h>
  5. bit verify=0;
  6. bit cursor=1;
  7. bit modify_flag=0,modify=0;
  8. uint time_counter=0;
  9. uchar counter=0,j=0,i,k;
  10. uchar PASS[8]={1,2,3,4,5,6,7,8};
  11. uchar PW[8]={0,0,0,0,0,0,0,0};
  12. uchar PW_NULL[8]={0,0,0,0,0,0,0,0};
  13. uchar MODIFY_BUF[8]={0,0,0,0,0,0,0,0};


  14. /****************************verify pw  ************************/
  15. bit VerifyAray(void)
  16. {
  17.                 uchar i;
  18.                 bit temp=FAULSE;
  19.                 for(i=0;i<8;i++)
  20.                         {
  21.                         if(PW[i]==PASS[i])temp=TRUE;

  22.                           else
  23.                            {
  24.                          temp=FAULSE;
  25.                                  i=8;                       //end for loop
  26.                                  }
  27.                                  }
  28.                            return(temp);
  29.         }


  30. /*********************** main ************************/

  31. void main(void)
  32. {
  33.         E=1;
  34.         DspOn();
  35.         ClearLCD();

  36. //        IT0=1;
  37. //        IT1=1;
  38. //        EX0=1;
  39. //        EX1=1;

  40.         TMOD=0x10;
  41.         ET1=1;
  42.         EA=1;
  43.         TH1=0x00;
  44.         TL1=0x00;
  45.         TR1=1;
  46.         
  47.         while(1)
  48.         {
  49.         /******************fist line****************************/
  50.         uchar i;
  51.         SetStartLine(0);
  52. re_input:
  53.         for(i=0;i<4;i++)
  54.         {
  55.         SetPage(0);
  56.         SetColumn(i<<4);                           // i*16
  57.         DspUp(&QING_SHU[i-1][32],1);
  58.         DspUp(&QING_SHU[i-1+4][32],2);

  59.         SetPage(1);
  60.         SetColumn(i<<4);                          // i*16
  61.         DspDown(&QING_SHU[i-1][32],1);
  62.         DspDown(&QING_SHU[i-1+4][32],2);
  63.         }

  64.     /**************second line***************************/

  65.         for(i=0;i<4;i++)
  66.         {
  67.         SetPage(6);
  68.         SetColumn(i<<4);                           // i*16
  69.         DspUp(&QING_CHU[i-1][32],1);
  70.         DspUp(&QING_CHU[i+4-1][32],2);

  71.         SetPage(7);
  72.         SetColumn(i<<4);                          // i*16
  73.         DspDown(&QING_CHU[i-1][32],1);
  74.         DspDown(&QING_CHU[i+4-1][32],2);
  75.         }

  76. /***************************光标显示***********************************/
  77. if(counter<8)           //如果输入到第8位,光标不再显示
  78. {
  79. if(cursor)
  80. {
  81.     i=counter;
  82.         SetPage(2);
  83.         SetColumn((i<4)?(i*16):((i-4)*16));                           
  84.         DspUp(&GUANG_BIAO_KONG[-1][32],(i<4)?1:2);

  85.         SetPage(3);
  86.         SetColumn((i<4)?(i*16):((i-4)*16));                          
  87.         DspDown(&GUANG_BIAO_KONG[-1][32],(i<4)?1:2);
  88.         }

  89. else
  90. {
  91.         i=counter;
  92.         SetPage(2);
  93.         SetColumn((i<4)?(i*16):((i-4)*16));                           
  94.         DspUp(&GUANG_BIAO_KONG[0][32],(i<4)?1:2);

  95.         SetPage(3);
  96.         SetColumn((i<4)?(i*16):((i-4)*16));                          
  97.         DspDown(&GUANG_BIAO_KONG[0][32],(i<4)?1:2);
  98.         }  
  99.         
  100. }

  101. /***********************get key's value**************************/

  102. if(CheckState())
  103.                 {
  104.                         delay();
  105.                         
  106.                         if(CheckState())
  107.                         {
  108.                                 key=GetKeys();
  109.                                 
  110.                            if(key==0x82)                     //clear input
  111.                            {
  112.                                      if(modify_flag){counter=0;MODIFY_BUF[8]=PW_NULL[8];}
  113.                               else {counter=0;PW[8]=PW_NULL[8];}
  114.                                  
  115.                                         for(i=0;i<8;i++)                 
  116.                                            {        
  117.                                                 SetPage(2);
  118.                                                 SetColumn(i<<4);                           
  119.                                                 DspUp(&GUANG_BIAO_KONG[0][32],1);
  120.                                                 DspUp(&GUANG_BIAO_KONG[0][32],2);

  121.                                                 SetPage(3);
  122.                                                 SetColumn(i<<4);
  123.                         DspDown(&GUANG_BIAO_KONG[0][32],1);
  124.                                                 DspDown(&GUANG_BIAO_KONG[0][32],2);
  125.                                                 
  126.                                                 }
  127.                                   }

  128.                           else if(key==0x88)                       //verify password
  129.                           {        
  130.                                         if(modify_flag){modify=1;goto modify_operation;}
  131.                                           else {verify=1;goto verify_password;}
  132.                                           
  133.                                         }
  134.                                 
  135.                           else if(counter<8)                      //get keys
  136.                                         {
  137.                                         switch(key)
  138.                                                 {
  139.                                                   case 0x84:
  140.                                                                           if(modify_flag)MODIFY_BUF[counter]=0;
  141.                                                                         else PW[counter]=0;
  142.                                                                         break;
  143.                                                  case 0x42:
  144.                                                                          if(modify_flag)MODIFY_BUF[counter]=1;
  145.                                                                         else PW[counter]=1;
  146.                                                                         break;
  147.                                                  case 0x44:
  148.                                                                          if(modify_flag)MODIFY_BUF[counter]=2;
  149.                                                                         else PW[counter]=2;
  150.                                                                         break;
  151.                                                  case 0x48:
  152.                                                                          if(modify_flag)MODIFY_BUF[counter]=3;
  153.                                                                         else PW[counter]=3;
  154.                                                                         break;
  155.                                                  case 0x22:
  156.                                                                          if(modify_flag)MODIFY_BUF[counter]=4;
  157.                                                                         else PW[counter]=4;
  158.                                                                         break;
  159.                                                  case 0x24:
  160.                                                                          if(modify_flag)MODIFY_BUF[counter]=5;
  161.                                                                         else PW[counter]=5;
  162.                                                                         break;
  163.                                                  case 0x28:
  164.                                                                          if(modify_flag)MODIFY_BUF[counter]=6;
  165.                                                                         else PW[counter]=6;
  166.                                                                         break;
  167.                                                  case 0x12:
  168.                                                                          if(modify_flag)MODIFY_BUF[counter]=7;
  169.                                                                         else PW[counter]=7;
  170.                                                                         break;
  171.                                                  case 0x14:
  172.                                                                          if(modify_flag)MODIFY_BUF[counter]=8;
  173.                                                                         else PW[counter]=8;
  174.                                                                         break;
  175.                                                  case 0x18:
  176.                                                                          if(modify_flag)MODIFY_BUF[counter]=9;
  177.                                                                         else PW[counter]=9;
  178.                                                                         break;
  179.                                                  default:
  180.                                                                          break;
  181.                             }
  182.                                                 counter++;
  183.                                   }

  184.                         
  185.                    }
  186.                    }

  187. /************************display password input **************************/

  188. for(i=0;i<counter;i++)        
  189.   {        
  190.           if(modify_flag==1)j=MODIFY_BUF[i];
  191.         else j=PW[i];
  192.         SetPage(2);
  193.         SetColumn((i<4)?(i*16):((i-4)*16));                           
  194.         DspUp(&NUMBER_ARRY[j-1][32],(i<4)?1:2);

  195.         SetPage(3);
  196.         SetColumn((i<4)?(i*16):((i-4)*16));                          
  197.         DspDown(&NUMBER_ARRY[j-1][32],(i<4)?1:2);
  198. }



  199. /*******************************verify_password*************************/

  200. verify_password:    if(verify)
  201.                                         {

  202.                                                 if(VerifyAray())
  203.                                                   {
  204.                                                    ClearLCD();
  205.                                 loop1:         for(i=0;i<4;i++)
  206.                                                         {
  207.                                                         SetPage(0);
  208.                                                         SetColumn(i<<4);                           // i*16
  209.                                                         DspUp(&TONG_GUO[i-1][32],1);
  210.                                                         DspUp(&TONG_GUO[i-1+4][32],2);

  211.                                                         SetPage(1);
  212.                                                         SetColumn(i<<4);                          // i*16
  213.                                                         DspDown(&TONG_GUO[i-1][32],1);
  214.                                                         DspDown(&TONG_GUO[i-1+4][32],2);
  215.                                                         
  216.                                                         SetPage(6);
  217.                                                         SetColumn(i<<4);                           // i*16
  218.                                                         DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
  219.                                                         DspUp(&TONG_GUO_TI_SHI[i-1+4][32],2);

  220.                                                         SetPage(7);
  221.                                                         SetColumn(i<<4);                          // i*16
  222.                                                         DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
  223.                                                         DspDown(&TONG_GUO_TI_SHI[i-1+4][32],2);
  224.                                                         }

  225.                                                         if(CheckState())
  226.                                                         {
  227.                                                                 delay();
  228.                         
  229.                                                                 if(CheckState())
  230.                                                                         {
  231.                                                                                 key=GetKeys();
  232.                                 
  233.                                                                                    if(key==0x82)
  234.                                                                                 {counter=0;verify=0;goto re_input;}

  235.                                                                                 else if(key==0x88)
  236.                                                                                 {counter=0;modify_flag=1;verify=0;goto re_input;}
  237.                                                                                 }
  238.                                                                 }
  239.    
  240.                                                  else  goto loop1;
  241.                                                         }
  242.                                           else
  243.                                           {
  244.                                                           ClearLCD();
  245.                                         loop2:        for(i=0;i<4;i++)
  246.                                                         {
  247.                                                         SetPage(0);
  248.                                                         SetColumn(i<<4);                           // i*16
  249.                                                         DspUp(&BU_TONG_GUO[i-1][32],1);
  250.                                                         DspUp(&BU_TONG_GUO[i-1+4][32],2);

  251.                                                         SetPage(1);
  252.                                                         SetColumn(i<<4);                          // i*16
  253.                                                         DspDown(&BU_TONG_GUO[i-1][32],1);
  254.                                                         DspDown(&BU_TONG_GUO[i-1+4][32],2);

  255.                                                         SetPage(6);
  256.                                                         SetColumn(i<<4);                           // i*16
  257.                                                         DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
  258.                                                         
  259.                                                         SetPage(7);
  260.                                                         SetColumn(i<<4);                          // i*16
  261.                                                         DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
  262.                                                 
  263.                                                                 }
  264.                                                         if(CheckState())
  265.                                                                 {
  266.                                                                         delay();
  267.                         
  268.                                                                 if(CheckState())
  269.                                                                         {
  270.                                                                                 key=GetKeys();
  271.                                 
  272.                                                                                    if(key==0x82)
  273.                                                                                 {counter=0;verify=0;goto re_input;}
  274.                                                                                 }
  275.                                                                                 }
  276.                                                         else goto loop2;
  277.                                                         }
  278.                                                         }

  279. }
  280. //}


  281. /*********************modify password operation *********************/

  282. modify_operation:  if(modify)
  283.                                         {
  284.                                                 modify_flag=0;
  285.                                                   if(1)
  286.                                                    {
  287.                                                          for(i=0;i<8;i++){PASS[i]=MODIFY_BUF[i];}
  288.                                                           //PASS[8]=MODIFY_BUF[8];
  289.                                                         
  290.                                                         
  291.                                                         ClearLCD();
  292.                                                                                                 
  293.                                         loop3:        for(i=0;i<4;i++)
  294.                                                         {
  295.                                                         SetPage(0);
  296.                                                         SetColumn(i<<4);                           // i*16
  297.                                                         DspUp(&GAI_CHENG_GONG[i-1][32],1);
  298.                                                         DspUp(&GAI_CHENG_GONG[i-1+4][32],2);
  299.                                                         SetPage(1);
  300.                                                         SetColumn(i<<4);                          // i*16
  301.                                                         DspDown(&GAI_CHENG_GONG[i-1][32],1);
  302.                                                         DspDown(&GAI_CHENG_GONG[i-1+4][32],2);

  303.                                                         SetPage(2);
  304.                                                         SetColumn(i<<4);                           // i*16
  305.                                                         DspUp(&GAI_HOU_TI_SHI[i-1][32],1);
  306.                                                         DspUp(&GAI_HOU_TI_SHI[i-1+4][32],2);
  307.                                                         SetPage(3);
  308.                                                         SetColumn(i<<4);                          // i*16
  309.                                                         DspDown(&GAI_HOU_TI_SHI[i-1][32],1);
  310.                                                         DspDown(&GAI_HOU_TI_SHI[i-1+4][32],2);

  311.                                                         j=PASS[i];
  312.                                                         k=PASS[i+4];

  313.                                                         SetPage(4);
  314.                                                         SetColumn(i<<4);
  315.                                                         DspUp(&NUMBER_ARRY[j-1][32],1);
  316.                                                         DspUp(&NUMBER_ARRY[k-1][32],2);
  317.                                                         SetPage(5);
  318.                                                         SetColumn(i<<4);
  319.                                                         DspDown(&NUMBER_ARRY[j-1][32],1);
  320.                                                         DspDown(&NUMBER_ARRY[k-1][32],2);


  321.                                                         SetPage(6);
  322.                                                         SetColumn(i<<4);                           // i*16
  323.                                                         DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
  324.                                                         SetPage(7);
  325.                                                         SetColumn(i<<4);                          // i*16
  326.                                                         DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
  327.                                                                 }
  328.                                                         if(CheckState())
  329.                                                                 {
  330.                                                                         delay();
  331.                         
  332.                                                                 if(CheckState())
  333.                                                                         {
  334.                                                                                 key=GetKeys();
  335.                                 
  336.                                                                                    if(key==0x82)
  337.                                                                                 {counter=0;modify=0;ClearLCD();goto re_input;}
  338.                                                                                 }
  339.                                                                                 }
  340.                                                         else goto loop3;
  341.                                                         }
  342.                                                         }
  343.                                        
  344.                                                 }

  345. /*******timer1 interrupt to change cursor display on and off ******/

  346. void Timer1(void) interrupt 3 using 1
  347. {
  348.         
  349.         TH1=0x00;
  350.         TL1=0x00;
  351.         TR1=1;
  352.         if(time_counter>10)
  353.         {
  354.                 time_counter=0;
  355.                 cursor=~cursor;
  356.                 }
  357.          else time_counter++;

  358.          }  
  359.         
  360.         

  361. /************* INT0 interrupt to scroll up by press switch P3.2 **********************/

  362. /*void INT0_ON(void) interrupt 0 using 2
  363. {
  364.         direction=UP;
  365.         }


  366. /************** INT1 interrupt to scroll down by press switch P3.3***********************/

  367. /*void INT1_OFF(void) interrupt 2 using 3
  368. {
  369.         direction=DOWN;
  370.         }
  371. */

复制代码



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏6 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:287925 发表于 2018-8-6 13:05 | 只看该作者
很好的参考资料,谢谢楼主
回复

使用道具 举报

板凳
ID:436945 发表于 2019-12-27 16:55 | 只看该作者
确实强大,如果能增加不同的密码打开不同的柜子(开关)就更好了。
回复

使用道具 举报

地板
ID:453281 发表于 2020-6-3 13:56 | 只看该作者
有仿真吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表