專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

單片機(jī)電子密碼鎖子程序

作者:佚名   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年10月16日   【字體:

仿真文件和完整源碼下載地址:http://www.torrancerestoration.com/bbs/dpj-22586-1.html
論文下載地址:http://www.torrancerestoration.com/f/電子密碼鎖論文最終稿.docx
下面是mima.c子程序:

#include <reg52.h>
#include "mima.h"
#include "1602.h"
#include "矩陣鍵盤(pán).h"
#include "delay_ms.h"

/*比較密碼函數(shù),密碼正確返回1,不正確返回0*/

bit mimaduibi(unsigned char *string1,unsigned char *string2)
{
 unsigned char count;
 for(count = 0; count < 6; count++)
 {
  if(string1[count] != string2[count])
  return 0;
 }
 return 1;
}

/*選擇輸入密碼或修改密碼函數(shù),輸入密碼返回A,修改密碼返回B*/

unsigned char step_choose(void)//選擇輸入密碼或修改密碼處理函數(shù)
{
 uchar key;
 key = 0xff;
 write_com(0x06);//寫(xiě)一個(gè)字符后地址指針加 1
    write_com(0x01);//顯示清零,數(shù)據(jù)指針清零
 lcd_pos(0,0);
 write_n_char(" Input password ");
 lcd_pos(1,0);
 write_n_char("  Press key A  "); 
 while((key != A) && (key != B))
  key = keyscan(); 
 return key;
}
/*輸入密碼函數(shù),密碼正確返回1,錯(cuò)誤返回0*/

bit input_mima(uchar * mima)//輸入密碼函數(shù)
{
 unsigned char count,key;
 lcd_pos(1,0);
 for(count = 0; count < 7; count++)
 {
  delay_ms(100);
  if(count < 6)
  {
   do{key = keyscan();}//掃描鍵盤(pán)
   while(key == 0xff);
   if((key != backspace) && (key != A) && (key != enter))//不是退格也不是確認(rèn)鍵
   {
    write_data('*');//是數(shù)字鍵顯示*
    mima[count] = key;
   // continue;
   }
   if(key == backspace)//是退格鍵
   {
    if(count > 0)
    {
        lcd_pos(1,--count);//光標(biāo)前移一位
     write_data(' ');//清空一位
     mima[count] = ' ';//寫(xiě)空
     lcd_pos(1,count);
     count--;//密碼計(jì)數(shù)器減一 ,因?yàn)檠h(huán)后會(huì)+1,所以在這里要加1
    }
   }
   if(key == enter)//沒(méi)完成密碼輸入返回錯(cuò)誤信息
   {
    lcd_pos(0,0);
    return(0);
   }
  }
  if(count==6)
  {
   do{key = keyscan();}
   while((key != backspace)&&(key != enter));
   if(key == backspace)
   {
    lcd_pos(1,--count);
    write_data(' ');
    mima[count]=' ';
    lcd_pos(1,count);
    count--;
   }
   if(key == enter)//密碼位數(shù)正確
   {
    return(1);//返回1正確信號(hào)
   }
  }
 }
 
}

 

關(guān)閉窗口

相關(guān)文章