- #include
- #include
- #include
- #include
- void lcd_init();
- void lcd_wcmd(unsigned char cmd); //???????,?????
- void delay(unsigned int); //???????,?????
- void lcd_pos(unsigned char pos);
- void lcd_wdat(unsigned char dat);
- void Password_importation(void);
- ***it rst=P2^5;
- ***it sclk=P2^6;
- ***it io=P2^7;
- ***it rs= P2^2;
- ***it rw = P2^1;
- ***it ep = P2^0;
- ***it REL=P2^4;//????, 0???
- ***it beep=P2^3; //?? 0???
- ***it doorcontact=P3^7;//?? 0????
- #define uchar unsigned char
- #define uint unsigned int
- int face,face1,face2,face3,face4,face5,face6;
- /******************************?????*********************************/
- unsigned char code dis0[] = {"xihuadaxue!"};
- unsigned char code dis00[] = {"lvjiawei"};
- unsigned char code dis000[] = {"INPUT AGAIN!"};
- unsigned char code dis0000[] = {"WARNING!!!"};
- unsigned char code dis00000[] = {"CONTINUE........."};
- unsigned char code diskeep[] = {"FRENDS"};
- unsigned char code distouch[] = {"KEEP TOUCH!"};
- unsigned char code dis1[] = {"WELCOME!"};
- unsigned char code dis2[] = {"LVJIAWEI :>"};
- unsigned char code dis3[] = {"PLEASE "};
- unsigned char code dis4[] = {"INPUT CODE:"};
- unsigned char code dis5[] = {"THE CODE :"};
- unsigned char code dis6[] = {"________"};
- unsigned char code dis7[] = {"THE CODE1 :"};
- unsigned char code dis8[] = {"* "};
- unsigned char code dis9[] = {"THE CODE2:"};
- unsigned char code dis10[] = {"** "};
- unsigned char code dis11[] = {"THE CODE3:"};
- unsigned char code dis12[] = {"*** "};
- unsigned char code dis13[] = {"THE CODE4:"};
- unsigned char code dis14[] = {"**** "};
- unsigned char code dis15[] = {"THE CODE5:"};
- unsigned char code dis16[] = {"***** "};
- unsigned char code dis17[] = {"THE CODE6:"};
- unsigned char code dis18[] = {"******"};
- unsigned char code dis50[] = {" PLEASE WAIT! "};
- unsigned char code dis51[] = {" WAIT PLEASE !"};
- unsigned char code dis52[] = {"SORRY! "};
- unsigned char code dis53[] = {"CODE ERROR!"};
- unsigned char code dis54[] = {" RIGHT CODE"};
- unsigned char code dis55[] = {"U ARE WELCOME !"};
- unsigned char code dis56[] = {" CODE ERROR"};
- unsigned char code dis57[] = {"THREETIMES!!!"};
- unsigned char tab_time[];
- unsigned char tab_1302[];
- unsigned char tab_ymdw[];
- unsigned char numface=0;
- unsigned char numface1=0;
- unsigned char numface2=0;
- unsigned char numface3=0;
- unsigned char code turepassword[6] ={6,6,6,6,6,6};//????
- unsigned char key_data=0;
- unsigned char password[]={0,0,0,0,0,0};
- unsigned char errortimes=0;
- uchar Number=0;
- int num;
- // ? ? ?:????//
- void delay1ms(int z) //???1ms ? delay(1000)?1000???
- {
- int x,y;
- for(x=z;x>0;x--)
- {
- for(y=110;y>0;y--);
- }
- }
- void opendoor(void)
- {
- delay1ms(10);
- REL=0;
- }
- void closedoor(void)
- {
- delay1ms(10);
- REL=1;
- }
- void cancel(void)
- {
- delay1ms(100) ;
- lcd_wcmd(0x01); //??
- face1=0; //???????????
- face2=0; // ???????????
- face3=0; // ???????????
- face4=0; // ???????????
- face5=0; // ???????????
- face6=0; // ???????????
- }
- void keeptouch(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(diskeep[i] != '\0')
- {
- lcd_wdat(diskeep[i]);//????
- i++;
- }
- lcd_pos(0x44);// ??????
- i = 0;
- while(distouch[i] != '\0')
- {
- lcd_wdat(distouch[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- }
- void welcome(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis1[i] != '\0')
- {
- lcd_wdat(dis1[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis2[i] != '\0')
- {
- lcd_wdat(dis2[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- }
- void loading(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis0[i] != '\0')
- {
- lcd_wdat(dis0[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis00[i] != '\0')
- {
- lcd_wdat(dis00[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- delay1ms(4000);
- return;
- }
- void inputagain(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis3[i] != '\0')
- {
- lcd_wdat(dis3[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis000[i] != '\0')
- {
- lcd_wdat(dis000[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- delay(2000);
- return;
- }
- void error3times(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis56[i] != '\0')
- {
- lcd_wdat(dis56[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis57[i] != '\0')
- {
- lcd_wdat(dis57[i]);// ????
- i++;
- }
- delay1ms(500); //???0.5ms
- }
- void password_OK(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis54[i] != '\0')
- {
- lcd_wdat(dis54[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis55[i] != '\0')
- {
- lcd_wdat(dis55[i]);// ????
- i++;
- }
- delay1ms(1000); //???1ms
- loading();
- }
- void pass_error(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis52[i] != '\0')
- {
- lcd_wdat(dis52[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis53[i] != '\0')
- {
- lcd_wdat(dis53[i]);// ????
- i++;
- }
- beep=0;
- delay1ms(500);
- beep=1;
- inputagain();
- }
- void pass_over(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay1ms(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis50[i] != '\0')
- {
- lcd_wdat(dis50[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis51[i] != '\0')
- {
- lcd_wdat(dis51[i]);// ????
- i++;
- }
- delay1ms(2000); //???2ms
- }
- void Pass_face6(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis17[i] != '\0')
- {
- lcd_wdat(dis17[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis18[i] != '\0')
- {
- lcd_wdat(dis18[i]);// ????
- i++;
- }
- face6=1;//???6???????
- while(P1!=0x0f);
- }
- void Pass_face5(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis15[i] != '\0')
- {
- lcd_wdat(dis15[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis16[i] != '\0')
- {
- lcd_wdat(dis16[i]);// ????
- i++;
- }
- face5=1;//???5???????
- while(P1!=0x0f);
- }
- void Pass_face4(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis13[i] != '\0')
- {
- lcd_wdat(dis13[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis14[i] != '\0')
- {
- lcd_wdat(dis14[i]);// ????
- i++;
- }
- face4=1;// ???4???????
- while(P1!=0x0f);
- }
- void Pass_face3(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis11[i] != '\0')
- {
- lcd_wdat(dis11[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis12[i] != '\0')
- {
- lcd_wdat(dis12[i]);// ????
- i++;
- }
- face3=1;//???3???????
- while(P1!=0x0f);
- }
- void Pass_face2(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis9[i] != '\0')
- {
- lcd_wdat(dis9[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis10[i] != '\0')
- {
- lcd_wdat(dis10[i]);// ????
- i++;
- }
- face2=1;//???2???????
- while(P1!=0x0f);
- }
- void Pass_face1(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis7[i] != '\0')
- {
- lcd_wdat(dis7[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis8[i] != '\0')
- {
- lcd_wdat(dis8[i]);// ????
- i++;
- }
- while(P1!=0x0f);
- face1=1;//???1???????
- }
- void codeinput(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis3[i] != '\0')
- {
- lcd_wdat(dis3[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis4[i] != '\0')
- {
- lcd_wdat(dis4[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- }
- uchar keyscan(void)
- {
- uchar keycode=0xff;
- uchar keycode1,keycode2;
- P1 =0xf0;
- if(P1 !=0xf0)
- {
- delay(100);
- if(P1 !=0xf0)
- {
- keycode1=P1;
- P1=0x0f;
- keycode2=P1;
- keycode=keycode2 | keycode1;
- switch(keycode)
- { case 0xff:keycode=00;break;
- case 0xee:keycode=0;break;
- case 0xde:keycode=1;break;
- case 0xbe:keycode=2;break;
- case 0x7e:keycode=3;break;
- case 0xed:keycode=4;break;
- case 0xdd:keycode=5;break;
- case 0xbd:keycode=6;break;
- case 0x7d:keycode=7;break;
- case 0xeb:keycode=8;break;
- case 0xdb:keycode=9;break;
- case 0xbb:keycode=10;break;
- case 0x7b:keycode=11;break;
- case 0xe7:keycode=12;break;
- case 0xd7:keycode=13;break;
- case 0xb7:keycode=14;break;
- case 0x77:keycode=15;break;
- }
- }
- }
- return keycode; //????
- }
- void warning(void)
- {
- while(1)
- { beep=0;
- delay1ms(500);
- beep=1;
- delay1ms(500);
- beep=0;
- }
- }
- void warningshow(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis56[i] != '\0')
- {
- lcd_wdat(dis56[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis0000[i] != '\0')
- {
- lcd_wdat(dis0000[i]);// ????
- i++;
- }
- face=1; //??0??????
- while(P1!=0x0f);
- }
- void warningshow1(void)
- {
- unsigned char i;
- lcd_init();// ???LCD
- delay(10);
- lcd_pos(0x01);//??????
- i = 0;
- while(dis00000[i] != '\0')
- {
- lcd_wdat(dis00000[i]);//????
- i++;
- }
- lcd_pos(0x42);// ??????
- i = 0;
- while(dis0000[i] != '\0')
- {
- lcd_wdat(dis0000[i]);// ????
- i++;
- }
- face=1; //??0??????
- warning(); while(P1!=0x0f);
- }
- void passwordcomparison(void) //??????
- {
- uchar Number=0;
- while((password[Number]==turepassword[Number])&(Number<6)) // ????
- {
- Number++; // ????1
- }
- if(Number>=6) // ????
- {
- password_OK(); // ????????????
- REL=0;
- delay1ms(10000); //10???????
- REL=1; // ?????,0???
- beep=1; //????,1????
- Number=0;
- }
- else
- {
- pass_error();//??“???????”
- errortimes++;
- if(errortimes==3)
- {
- error3times();
- REL=1 ; //?????,1???
- warning(); //????1?
- warningshow();
- errortimes=0;
- }
- }
- }
- //???//
- void main(void)
- {
- unsigned char k;
- ds1302_init();
- ds1302(); //?????? ????
- {
- while(1)
- {
- if(doorcontact==0&&REL==1)
- {
- warningshow1();
- }
- else if(face6==1)
- {
- pass_over(); //6?????????
- passwordcomparison(); //????
- face6=0;
- }
- else
- {
- k = keyscan();
- if((k>=0 && k<=9)&&(face==1)) //????? 1
- {
- key_data=k;
- password[0]=key_data;
- key_data=0;
- face=2;
- Pass_face1();
- }
- else if((k>=0 && k<=9)&&(face==2)&&(face1==1)) //?????
- {
- key_data=k;
- password[1]=key_data;
- key_data=0;
- face1=2;
- Pass_face2();
- }
- else if((k>=0 && k<=9)&&(face==2)&&(face1==2)&&(face2==1)) //???3?
- {
- key_data=k;
- password[2]=key_data;
- key_data=0;
- face2=2;
- Pass_face3();
- }
- else if((k>=0 && k<=9)&&(face==2)&&(face1==2)&&(face2==2)&&(face3==1)) //???4?
- {
- key_data=k;
- password[3]=key_data;
- key_data=0;
- face3=2;
- Pass_face4();
- }
- else if((k>0&&k<9)&&(face==2)&&(face1==2)&&(face2==2)&&(face3==2)&&(face4==1)) //???5?
- {
- key_data=k;
- password[4]=key_data;
- key_data=0;
- face4=2;
- Pass_face5();
- }
- else if((k>=0&&k<=9)&&(face==2)&&(face1==2)&&(face2==2)&&(face3==2)&&(face4==2)&&(face5==1)) //???6? 6
- {
- key_data=k;
- password[5]=key_data;
- key_data=0;
- face5=2;
- Pass_face6();
- }
- else if(k==15) //??????
- {
- codeinput(); //codeinput????
- }
- else if(k==14) //????
- {
- welcome(); //welcom????
- }
- else if(k==13) //????
- {
- welcome();
- opendoor(); //opendoor????
- }
- else if(k==12) //????
- { keeptouch();
- closedoor(); //close????
- }
- else if(k==11) //????
- {
- cancel(); //cancel????
- }
- else if(k==10) //????
- {
- warningshow1();
- }
- }
- }
- }
- }
复制代码
|