|
初始密碼為12345678,輸入初始密碼后可更改為自己的密碼;‘ON/C’為返回或清零鍵‘ON/C’為返回或清零鍵‘=’為確認(rèn)鍵
LCD12864中文顯示的單片機(jī)電子密碼鎖所有資料下載:
電子密碼鎖LCD12864中文顯示.rar
(87.42 KB, 下載次數(shù): 53)
2016-9-26 13:12 上傳
點擊文件名下載附件
源程序:
- /***** LCD 12864 with KS0108B controller display driver *****/
- #define uchar unsigned char
- #include<drive_functions.h>
- #include<get_keys.h>
- bit verify=0;
- bit cursor=1;
- bit modify_flag=0,modify=0;
- uint time_counter=0;
- uchar counter=0,j=0,i,k;
- uchar PASS[8]={1,2,3,4,5,6,7,8};
- uchar PW[8]={0,0,0,0,0,0,0,0};
- uchar PW_NULL[8]={0,0,0,0,0,0,0,0};
- uchar MODIFY_BUF[8]={0,0,0,0,0,0,0,0};
- /****************************verify pw ************************/
- bit VerifyAray(void)
- {
- uchar i;
- bit temp=FAULSE;
- for(i=0;i<8;i++)
- {
- if(PW[i]==PASS[i])temp=TRUE;
- else
- {
- temp=FAULSE;
- i=8; //end for loop
- }
- }
- return(temp);
- }
- /*********************** main ************************/
- void main(void)
- {
- E=1;
- DspOn();
- ClearLCD();
- // IT0=1;
- // IT1=1;
- // EX0=1;
- // EX1=1;
- TMOD=0x10;
- ET1=1;
- EA=1;
- TH1=0x00;
- TL1=0x00;
- TR1=1;
-
- while(1)
- {
- /******************fist line****************************/
- uchar i;
- SetStartLine(0);
- re_input:
- for(i=0;i<4;i++)
- {
- SetPage(0);
- SetColumn(i<<4); // i*16
- DspUp(&QING_SHU[i-1][32],1);
- DspUp(&QING_SHU[i-1+4][32],2);
- SetPage(1);
- SetColumn(i<<4); // i*16
- DspDown(&QING_SHU[i-1][32],1);
- DspDown(&QING_SHU[i-1+4][32],2);
- }
- /**************second line***************************/
- for(i=0;i<4;i++)
- {
- SetPage(6);
- SetColumn(i<<4); // i*16
- DspUp(&QING_CHU[i-1][32],1);
- DspUp(&QING_CHU[i+4-1][32],2);
- SetPage(7);
- SetColumn(i<<4); // i*16
- DspDown(&QING_CHU[i-1][32],1);
- DspDown(&QING_CHU[i+4-1][32],2);
- }
- /***************************光標(biāo)顯示***********************************/
- if(counter<8) //如果輸入到第8位,光標(biāo)不再顯示
- {
- if(cursor)
- {
- i=counter;
- SetPage(2);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspUp(&GUANG_BIAO_KONG[-1][32],(i<4)?1:2);
- SetPage(3);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspDown(&GUANG_BIAO_KONG[-1][32],(i<4)?1:2);
- }
- else
- {
- i=counter;
- SetPage(2);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspUp(&GUANG_BIAO_KONG[0][32],(i<4)?1:2);
- SetPage(3);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspDown(&GUANG_BIAO_KONG[0][32],(i<4)?1:2);
- }
-
- }
- /***********************get key's value**************************/
- if(CheckState())
- {
- delay();
-
- if(CheckState())
- {
- key=GetKeys();
-
- if(key==0x82) //clear input
- {
- if(modify_flag){counter=0;MODIFY_BUF[8]=PW_NULL[8];}
- else {counter=0;PW[8]=PW_NULL[8];}
-
- for(i=0;i<8;i++)
- {
- SetPage(2);
- SetColumn(i<<4);
- DspUp(&GUANG_BIAO_KONG[0][32],1);
- DspUp(&GUANG_BIAO_KONG[0][32],2);
- SetPage(3);
- SetColumn(i<<4);
- DspDown(&GUANG_BIAO_KONG[0][32],1);
- DspDown(&GUANG_BIAO_KONG[0][32],2);
-
- }
- }
- else if(key==0x88) //verify password
- {
- if(modify_flag){modify=1;goto modify_operation;}
- else {verify=1;goto verify_password;}
-
- }
-
- else if(counter<8) //get keys
- {
- switch(key)
- {
- case 0x84:
- if(modify_flag)MODIFY_BUF[counter]=0;
- else PW[counter]=0;
- break;
- case 0x42:
- if(modify_flag)MODIFY_BUF[counter]=1;
- else PW[counter]=1;
- break;
- case 0x44:
- if(modify_flag)MODIFY_BUF[counter]=2;
- else PW[counter]=2;
- break;
- case 0x48:
- if(modify_flag)MODIFY_BUF[counter]=3;
- else PW[counter]=3;
- break;
- case 0x22:
- if(modify_flag)MODIFY_BUF[counter]=4;
- else PW[counter]=4;
- break;
- case 0x24:
- if(modify_flag)MODIFY_BUF[counter]=5;
- else PW[counter]=5;
- break;
- case 0x28:
- if(modify_flag)MODIFY_BUF[counter]=6;
- else PW[counter]=6;
- break;
- case 0x12:
- if(modify_flag)MODIFY_BUF[counter]=7;
- else PW[counter]=7;
- break;
- case 0x14:
- if(modify_flag)MODIFY_BUF[counter]=8;
- else PW[counter]=8;
- break;
- case 0x18:
- if(modify_flag)MODIFY_BUF[counter]=9;
- else PW[counter]=9;
- break;
- default:
- break;
- }
- counter++;
- }
-
- }
- }
- /************************display password input **************************/
- for(i=0;i<counter;i++)
- {
- if(modify_flag==1)j=MODIFY_BUF[i];
- else j=PW[i];
- SetPage(2);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspUp(&NUMBER_ARRY[j-1][32],(i<4)?1:2);
- SetPage(3);
- SetColumn((i<4)?(i*16):((i-4)*16));
- DspDown(&NUMBER_ARRY[j-1][32],(i<4)?1:2);
- }
-
- /*******************************verify_password*************************/
- verify_password: if(verify)
- {
- if(VerifyAray())
- {
- ClearLCD();
- loop1: for(i=0;i<4;i++)
- {
- SetPage(0);
- SetColumn(i<<4); // i*16
- DspUp(&TONG_GUO[i-1][32],1);
- DspUp(&TONG_GUO[i-1+4][32],2);
- SetPage(1);
- SetColumn(i<<4); // i*16
- DspDown(&TONG_GUO[i-1][32],1);
- DspDown(&TONG_GUO[i-1+4][32],2);
-
- SetPage(6);
- SetColumn(i<<4); // i*16
- DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
- DspUp(&TONG_GUO_TI_SHI[i-1+4][32],2);
- SetPage(7);
- SetColumn(i<<4); // i*16
- DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
- DspDown(&TONG_GUO_TI_SHI[i-1+4][32],2);
- }
- if(CheckState())
- {
- delay();
-
- if(CheckState())
- {
- key=GetKeys();
-
- if(key==0x82)
- {counter=0;verify=0;goto re_input;}
- else if(key==0x88)
- {counter=0;modify_flag=1;verify=0;goto re_input;}
- }
- }
-
- else goto loop1;
- }
- else
- {
- ClearLCD();
- loop2: for(i=0;i<4;i++)
- {
- SetPage(0);
- SetColumn(i<<4); // i*16
- DspUp(&BU_TONG_GUO[i-1][32],1);
- DspUp(&BU_TONG_GUO[i-1+4][32],2);
- SetPage(1);
- SetColumn(i<<4); // i*16
- DspDown(&BU_TONG_GUO[i-1][32],1);
- DspDown(&BU_TONG_GUO[i-1+4][32],2);
- SetPage(6);
- SetColumn(i<<4); // i*16
- DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
-
- SetPage(7);
- SetColumn(i<<4); // i*16
- DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
-
- }
- if(CheckState())
- {
- delay();
-
- if(CheckState())
- {
- key=GetKeys();
-
- if(key==0x82)
- {counter=0;verify=0;goto re_input;}
- }
- }
- else goto loop2;
- }
- }
- }
- //}
- /*********************modify password operation *********************/
- modify_operation: if(modify)
- {
- modify_flag=0;
- if(1)
- {
- for(i=0;i<8;i++){PASS[i]=MODIFY_BUF[i];}
- //PASS[8]=MODIFY_BUF[8];
-
-
- ClearLCD();
-
- loop3: for(i=0;i<4;i++)
- {
- SetPage(0);
- SetColumn(i<<4); // i*16
- DspUp(&GAI_CHENG_GONG[i-1][32],1);
- DspUp(&GAI_CHENG_GONG[i-1+4][32],2);
- SetPage(1);
- SetColumn(i<<4); // i*16
- DspDown(&GAI_CHENG_GONG[i-1][32],1);
- DspDown(&GAI_CHENG_GONG[i-1+4][32],2);
- SetPage(2);
- SetColumn(i<<4); // i*16
- DspUp(&GAI_HOU_TI_SHI[i-1][32],1);
- DspUp(&GAI_HOU_TI_SHI[i-1+4][32],2);
- SetPage(3);
- SetColumn(i<<4); // i*16
- DspDown(&GAI_HOU_TI_SHI[i-1][32],1);
- DspDown(&GAI_HOU_TI_SHI[i-1+4][32],2);
- j=PASS[i];
- k=PASS[i+4];
- SetPage(4);
- SetColumn(i<<4);
- DspUp(&NUMBER_ARRY[j-1][32],1);
- DspUp(&NUMBER_ARRY[k-1][32],2);
- SetPage(5);
- SetColumn(i<<4);
- DspDown(&NUMBER_ARRY[j-1][32],1);
- DspDown(&NUMBER_ARRY[k-1][32],2);
- SetPage(6);
- SetColumn(i<<4); // i*16
- DspUp(&TONG_GUO_TI_SHI[i-1][32],1);
- SetPage(7);
- SetColumn(i<<4); // i*16
- DspDown(&TONG_GUO_TI_SHI[i-1][32],1);
- }
- if(CheckState())
- {
- delay();
-
- if(CheckState())
- {
- key=GetKeys();
-
- if(key==0x82)
- {counter=0;modify=0;ClearLCD();goto re_input;}
- }
- }
- else goto loop3;
- }
- }
-
- }
- /*******timer1 interrupt to change cursor display on and off ******/
- void Timer1(void) interrupt 3 using 1
- {
-
- TH1=0x00;
- TL1=0x00;
- TR1=1;
- if(time_counter>10)
- {
- time_counter=0;
- cursor=~cursor;
- }
- else time_counter++;
- }
-
-
- /************* INT0 interrupt to scroll up by press switch P3.2 **********************/
- /*void INT0_ON(void) interrupt 0 using 2
- {
- direction=UP;
- }
- /************** INT1 interrupt to scroll down by press switch P3.3***********************/
- /*void INT1_OFF(void) interrupt 2 using 3
- {
- direction=DOWN;
- }
- */
復(fù)制代碼
|
評分
-
查看全部評分
|