源程序
#include
#define uchar unsigned char
#define uint unsigned int
sbit lcdrs=P3^0;
sbit lcdrw=P3^1;
sbit lcden=P3^2;
sbit h1=P1^0;
sbit h2=P1^1;
sbit h3=P1^2;
sbit sa=P1^3;
sbit sb=P1^4;
sbit sc=P1^5;
sbit sd=P1^6;
sbit kd=P3^7;
uchar code table[]="? PLEASE INPUT ";
uchar code table1[]="CODE:??????? ";
uchar code table2[]=" *****WIN*****";
uchar code table3[]=" PLEASE AFFIRM";
uchar code table4[]=" *****FAIL*****";
uchar code table5[]="?? MODIFICATION";
uchar code table6[]=" IDENTITY LIMITS ";
uchar unm,M1,M2,M3,M4,M5,M6,sex,k1,k2,k3,k4,k5,k6,flge,flge1;
uchar q1,q2,q3,q4,q5,q6,w1,w2,w3,w4,w5,w6,g;
void delay(int z)
{
?int x,y;
?for(x=z;x>0;x--)
? for(y=110;y>0;y--);
}
void delay1(int z)
{
?int x,y;
?for(x=z;x>0;x--)
? for(y=20000;y>0;y--);
}
void writen_com(uchar com)?? //1602寫命令
{
?lcdrs=0;
?P0=com;
?delay(1);
?lcden=1;
?delay(1);
?lcden=0;
}
void writen_dat(uchar dat)?? //1602寫數據
{
?lcdrs=1;
?P0=dat;
?delay(1);
?lcden=1;
?delay(1);
?lcden=0;
}
void main();
void cheak_mima()??? //檢查第二次確認密碼是否與第一次相同
{
if(q1==w1)
{
?if(q2==w2)
?{
? if(q3==w3)
? {
?? if(q4==w4)
?? {
??? if(q5==w5)
?{
? if(q6==w6)
? {
??? writen_com(0x01);
??? writen_com(0x0f);
?????? writen_com(0x06);
?????? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table5[unm]);
??????? delay(5);
????? }
?????? writen_com(0x80+0x40+1);
??????? for(unm=0;unm<14;unm++)
???????? {
????????? writen_dat(table2[unm]);
??? delay(5);
???????? }
????
??????? M1=w1;
??M2=w2;
??M3=w3;
??M4=w4;
??M5=w5;
??M6=w6;
??delay1(6);
??main();
?? }
/*-----------------------------------*/???//密碼確認錯誤返回
?? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
??? }? ?????
?? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
?? }
????? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
? }
????? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
? }
????? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
?}
????? writen_com(0x01);
?? writen_com(0x80);
????? for(unm=0;unm<14;unm++)
????? {
??????? writen_dat(table4[unm]);
??????? delay(5);
????? }
?? delay1(6);
?? main();
}
/*------------------------------------*/? //第二次確認密碼
void affirm_code()
{
?P1=0x07;
?if(P1!=0x07)
? delay(1);
? if(P1!=0x07)
?? {
??? P1=0x77;
??? if(h1==0)
? {
?? delay(1);
?? if(h1==0)
?? {
??? while(!h1);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=1;break;
??? case 1:w2=1;break;
??? case 2:w3=1;break;
??? case 3:w4=1;break;
??? case 4:w5=1;break;
??? case 5:w6=1;break;
?? }
?? sex++;
? }
?}
??? if(h2==0)
? {
?? delay(1);
?? if(h2==0)
?? {
??? while(!h2);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=2;break;
??? case 1:w2=2;break;
??? case 2:w3=2;break;
??? case 3:w4=2;break;
??? case 4:w5=2;break;
??? case 5:w6=2;break;
?? }
?? sex++;
? }
?}
?if(h3==0)
? {
?? delay(1);
?? if(h3==0)
?? {
??? while(!h3);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=3;break;
??? case 1:w2=3;break;
??? case 2:w3=3;break;
??? case 3:w4=3;break;
??? case 4:w5=3;break;
??? case 5:w6=3;break;
?? }
?? sex++;
? }
?}
/*-------------------------------*/
??? P1=0x6f;
??? if(h1==0)
? {
?? delay(1);
?? if(h1==0)
?? {
??? while(!h1);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=4;break;
??? case 1:w2=4;break;
??? case 2:w3=4;break;
??? case 3:w4=4;break;
??? case 4:w5=4;break;
??? case 5:w6=4;break;
?? }
?? sex++;
? }
?}
??? if(h2==0)
? {
?? delay(1);
?? if(h2==0)
?? {
??? while(!h2);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=5;break;
??? case 1:w2=5;break;
??? case 2:w3=5;break;
??? case 3:w4=5;break;
??? case 4:w5=5;break;
??? case 5:w6=5;break;
?? }
?? sex++;
? }
?}
?if(h3==0)
? {
?? delay(1);
?? if(h3==0)
?? {
??? while(!h3);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=6;break;
??? case 1:w2=6;break;
??? case 2:w3=6;break;
??? case 3:w4=6;break;
??? case 4:w5=6;break;
??? case 5:w6=6;break;
?? }
?? sex++;
? }
?}
/*--------------------------------*/
??? P1=0x5f;
??? if(h1==0)
? {
?? delay(1);
?? if(h1==0)
?? {
??? while(!h1);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=7;break;
??? case 1:w2=7;break;
??? case 2:w3=7;break;
??? case 3:w4=7;break;
??? case 4:w5=7;break;
??? case 5:w6=7;break;
?? }
?? sex++;
? }
?}
??? if(h2==0)
? {
?? delay(1);
?? if(h2==0)
?? {
??? while(!h2);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=8;break;
??? case 1:w2=8;break;
??? case 2:w3=8;break;
??? case 3:w4=8;break;
??? case 4:w5=8;break;
??? case 5:w6=8;break;
?? }
?? sex++;
? }
?}
?if(h3==0)
? {
?? delay(1);
?? if(h3==0)
?? {
??? while(!h3);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=9;break;
??? case 1:w2=9;break;
??? case 2:w3=9;break;
??? case 3:w4=9;break;
??? case 4:w5=9;break;
??? case 5:w6=9;break;
?? }
?? sex++;
? }
?}
?? /*-----------------------------------*/
??? P1=0x3f;
??? if(h2==0)??//0鍵掃描
? {
?? delay(1);
?? if(h2==0)
?? {
??? while(!h2);
?? writen_com(0x80+0x45+sex);
?? writen_dat('*');
?? switch(sex)
?? {
??? case 0:w1=0;break;
??? case 1:w2=0;break;
??? case 2:w3=0;break;
??? case 3:w4=0;break;
??? case 4:w5=0;break;
??? case 5:w6=0;break;
?? }
?? sex++;
? }
?}
?if(h3==0)?? //#鍵掃描
? {
?? delay(1);
?? if(h3==0)
?? {
??? while(!h3);
??? while(!flge1)
??? cheak_mima();
? }
?}
?? }
}
/*--------------------------------------*/? //修改密碼
評論
查看更多