说明:开机启动就是上图这样的,密码正确显示P(pass),密码错误显示E(error)
#include "reg51.h"
#include "myheader.h"
#define uchar unsigned char
long int sleep_i=0;
int pwd[4]={0,1,2,3};
int i=0;
int buffer[4]={0};
void test()
{P17=0;
}
void judge(int buffer[4],int pwd[4])
{uchar pass=1;uchar i=0;for(i=0;i<4;i++){if(buffer[i]!=pwd[i])pass=0;}if(pass==1){P2=0XFF;P20=P21=P24=P25=P26=P27=0;sleep(5000);P2=0XFF;P27=0;}else {P2=0;P21=P22=1;sleep(5000);P2=0XFF;P27=0;}
}void main()
{uchar num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};while(1){P26=0; if(P3!=0XFF){sleep(1200);if(P30==0){buffer[i]=0;};if(P31==0){buffer[i]=1;}; if(P32==0){buffer[i]=2;};if(P33==0){buffer[i]=3;};while(P3!=0XFF);i++;if(i==4){i=0;judge(buffer,pwd);};}}}void sleep(long int a)
{for(sleep_i=0;sleep_i<a;sleep_i++){;}
}