|
電子密碼鎖帶源程序
0.png (31.58 KB, 下載次數: 76)
下載附件
2016-9-24 13:08 上傳
0.png (47.28 KB, 下載次數: 106)
下載附件
2016-9-24 13:09 上傳
仿真和全部源碼下載:
電子密碼鎖.zip
(28.65 KB, 下載次數: 57)
2016-9-16 13:25 上傳
點擊文件名下載附件
電子密碼鎖帶源程序 下載積分: 黑幣 -5
- /***********************************************
- *實例名稱:電子密碼鎖
- *實例說明:實現五位密碼的設置和解鎖
- *作者:yd
- *時間:09.06.17
- ***********************************************/
- #include "target.h"
- uchar setPassword[5]={0x01,0x02,0x03,0x04,0x05}; //原始密碼12345
- uchar passwordCount;
- uchar inputPassword[5]={0x00,0x00,0x00,0x00,0x00};
- uchar displayFramCount; //顯示界面序號,0x01~0x05
- void main()
- {
- uchar i;
- uchar keyValueRead;
- uchar framTwoLine; //第二個界面中記錄選擇項所在行數
- target_init();
- displayFramCount=0x01;
- passwordCount=0x00;
- framTwoLine=0x01; //第二界面中顯示第一行
- while(1)
- {
- switch(displayFramCount)
- {
- case 0x01:
- {
- displayFramOne();
- break;
- }
- case 0x02:
- {
- if(framTwoLine==0x01)
- displayFramTwo(0);
- else
- displayFramTwo(1);
- break;
- }
- case 0x03:
- {
- displayFramThree();
- break;
- }
- case 0x04:
- {
- displayFramFour();
- break;
- }
- case 0x05:
- {
- displayFramFive();
- break;
- }
- default: break;
- }
- displayFramCount|=0x80; //displayFramCount最高位置1表示界面已顯示
- keyValueRead=get_key_value();
- switch(keyValueRead)
- {
- case KEY_ONE:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x01;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_TWO:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x02;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_THREE:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x03;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_FOUR:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x04;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_FIVE:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x05;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_SIX:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x06;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_SEVEN:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x07;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_EIGHT:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x08;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_NINE:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x09;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_ZERO:
- {
- if((displayFramCount&0x80)&&(((displayFramCount&0x7f)==0x03)||((displayFramCount&0x7f)==0x04)))
- {
- if(passwordCount<0x05)
- {
- inputPassword[passwordCount]=0x00;
- passwordCount++;
- }
- }
- break;
- }
- case KEY_TRUE: //確認鍵
- {
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //設置界面進入輸密碼界面
- {
- displayFramCount=0x03; //解密或者輸密碼時都要進入輸密碼界面
- }
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x03)) //輸入密碼確認
- {
- if(passwordCount==0x05)
- {
- for(i=0;i<5;i++)
- {
- if(framTwoLine==0x01)
- {
- displayFramCount=0x05;
- }
- else
- {
- if(framTwoLine==0x02)
- {
- displayFramCount=0x04;
- }
- }
-
- if(inputPassword[i]!=setPassword[i])
- {
- displayFramCount=0x01;
- break;
- }
- }
- passwordCount=0x00;
- }
- }
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x04)) //設置密碼確認
- {
- if(passwordCount==0x05)
- for(i=0;i<5;i++)
- {
- setPassword[i]=inputPassword[i];
- }
- displayFramCount=0x01;
- }
- break;
- }
- case KEY_CLEAR: //返回主界面鍵
- {
- displayFramCount=0x01;
- passwordCount=0x00;
- break;
- }
- case KEY_SET: //由主界面進入參數設置界面
- {
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x01))
- {
- displayFramCount=0x02;
- }
- passwordCount=0x00;
- break;
- }
- case KEY_UP:
- {
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //設置界面中上移選擇行
- {
- framTwoLine=0x01;
- displayFramCount=0x02;
- }
- break;
- }
- case KEY_DOWN:
- {
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x02)) //設置界面中上移選擇行
- {
- framTwoLine=0x02;
- displayFramCount=0x02;
- }
- break;
- }
- }
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x03)) //輸密碼界面,此時顯示****
- {
- displayMima(inputPassword,passwordCount,0x01);
- }
- if((displayFramCount&0x80)&&((displayFramCount&0x7f)==0x04)) //設置密碼界面,此時顯示設置的密碼
- {
- displayMima(inputPassword,passwordCount,0x02);
- }
- }
- }
復制代碼
|
評分
-
查看全部評分
|