|
啟動顯示 1602液晶示第一行顯示you win!第二行顯示I Iove 51MCU!
設定的密碼61513
輸入密碼時 1602液晶第一行顯示*號 (每按下一次鍵盤*號增加一個)
第一次密碼輸入錯誤后 1602液晶示第一行顯示Error!第二行顯示Call 13808197643
第二次密碼輸入錯誤后 程序自鎖只有重新啟動51單片機
密碼輸入正確后 1602液晶示第一行顯示My Name is第二行顯示Xue Yu Hao 之后延時一會兒(這里我沒有測試過到底延時多少秒)就進入計時程序秒記一次,可以計時1小時) 按下key6計時停止,







{,,,,,C語言程序如下,,,,,,,}
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code xian1[]="you win!";
uchar code xian2[]="I Iove 51MCU!";
uchar code good1[]="My Name is";
uchar code good2[]="Xue Yu Hao";
uchar code cuowu1[]="Error!";
uchar code cuowu2[]="Call 13808197643";
uchar code mimi[]="*";
uchar code shizhongdd[]="into the clock";
uchar code maohao[]=":";
uchar code ling[]="00";
uchar code shu0[]="0";
uchar code shu1[]="1";
uchar code shu2[]="2";
uchar code shu3[]="3";
uchar code shu4[]="4";
uchar code shu5[]="5";
uchar code shu6[]="6";
uchar code shu7[]="7";
uchar code shu8[]="8";
uchar code shu9[]="9";
uchar cc,mima0,mima1,mima2,mima3,mima4,mima5,mima6,mima7,mima1zy,num1,num2,num3,dsd1,dsd2,dsd3,fen1,fen2,fen3,fen4;
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
sbit key0=P0^0;
sbit key1=P0^1;
sbit key2=P0^2;
sbit key3=P0^3;
sbit key4=P0^4;
sbit key5=P0^5;
sbit key6=P0^6;
sbit key7=P0^7;
void timer(uint s)
{
uint x,c;
for(x=s;x>0;x--)
for(c=110;c>0;c--);
}
void zhiling(uchar p)
{
rs=0;
rw=0;
P2=p;
timer(5);
e=1;
timer(5);
e=0;
}
void shuju(uchar y)
{
rs=1;
rw=0;
P2=y;
timer(5);
e=1;
timer(5);
e=0;
}
void init()
{
zhiling(0x38);
zhiling(0x0c);
zhiling(0x06);
zhiling(0x01);
}
void jianpan()
{
if(key0==0)
{
timer(5);
if(key0==0)
{
mima0=1;
num1++;
while(!key0);
}
}
if(key1==0)
{
timer(5);
if(key1==0)
{
mima1=1;
num1++;
mima1zy++;
while(!key1);
}
}
if(key2==0)
{
timer(5);
if(key2==0)
{
mima2=1;
num1++;
while(!key2);
}
}
if(key3==0)
{
timer(5);
if(key3==0)
{
mima3=1;
num1++;
while(!key3);
}
}
if(key4==0)
{
timer(5);
if(key4==0)
{
mima4=1;
num1++;
while(!key4);
}
}
if(key5==0)
{
timer(5);
if(key5==0)
{
mima5=1;
num1++;
while(!key5);
}
}
if(key6==0)
{
timer(5);
if(key6==0)
{
mima6=1;
num1++;
while(!key6);
}
}
if(key7==0)
{
timer(5);
if(key0==0)
{
mima7=1;
num1++;
while(!key0);
}
}
}
void xianshide()
{
init();
zhiling(0x80);
for(cc=0;cc<10;cc++)
{
shuju(good1[cc]);
timer(5);
}
zhiling(0x80+0x43);
for(cc=0;cc<10;cc++)
{
shuju(good2[cc]);
timer(5);
}
}
void cuowude()
{
num1=0;
init();
zhiling(0x80+0x05);
if(num3==0)
{
for(cc=0;cc<5;cc++)
{
shuju(cuowu1[cc]);
timer(5);
}
zhiling(0x80+0x40);
for(cc=0;cc<16;cc++)
{
shuju(cuowu2[cc]);
timer(5);
}
num3=1;
}
}
void mimide()
{
if(num1==1)
{
init();
zhiling(0x80);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==2)
{
zhiling(0x80+0x01);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==3)
{
zhiling(0x80+0x02);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==4)
{
zhiling(0x80+0x03);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==5)
{
zhiling(0x80+0x04);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==6)
{
zhiling(0x80+0x05);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
if(num1==7)
{
zhiling(0x80+0x06);
for(cc=0;cc<1;cc++)
{
shuju(mimi[cc]);
timer(5);
}
}
}
void gaibian()
{
EA=0;
while(1)
{
jianpan();
if(mima0==1)
{
zhiling(0x0f);
zhiling(0x80+0x46);
dsd2++;
mima0=0;
}
if(mima0==0)
{
zhiling(0x0c);
}
}
}
void laozhong()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
init();
zhiling(0x80);
for(cc=0;cc<14;cc++)
{
shuju(shizhongdd[cc]);
timer(5);
}
zhiling(0x80+0x44);
for(cc=0;cc<1;cc++)
{
shuju(maohao[cc]);
timer(5);
}
zhiling(0x80+0x42);
for(cc=0;cc<2;cc++)
{
shuju(ling[cc]);
timer(5);
}
while(1)
{
if(dsd2==0)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu0[cc]);
timer(5);
}
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu0[cc]);
timer(5);
}
}
if(dsd2==1)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu1[cc]);
timer(5);
}
}
if(dsd2==2)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu2[cc]);
timer(5);
}
}
if(dsd2==3)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu3[cc]);
timer(5);
}
}
if(dsd2==4)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu4[cc]);
timer(5);
}
}
if(dsd2==5)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu5[cc]);
timer(5);
}
}
if(dsd2==6)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu6[cc]);
timer(5);
}
}
if(dsd2==7)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu7[cc]);
timer(5);
}
}
if(dsd2==8)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu8[cc]);
timer(5);
}
}
if(dsd2==9)
{
zhiling(0x80+0x46);
for(cc=0;cc<1;cc++)
{
shuju(shu9[cc]);
timer(5);
}
}
if(dsd3==0)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu0[cc]);
timer(5);
}
}
if(dsd3==1)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu1[cc]);
timer(5);
}
}
if(dsd3==2)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu2[cc]);
timer(5);
}
}
if(dsd3==3)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu3[cc]);
timer(5);
}
}
if(dsd3==4)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu4[cc]);
timer(5);
}
}
if(dsd3==5)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu5[cc]);
timer(5);
}
}
if(dsd3==6)
{
zhiling(0x80+0x45);
for(cc=0;cc<1;cc++)
{
shuju(shu6[cc]);
timer(5);
}
}
if(fen1==0)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu0[cc]);
timer(5);
}
}
if(fen1==1)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu1[cc]);
timer(5);
}
}
if(fen1==2)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu2[cc]);
timer(5);
}
}
if(fen1==3)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu3[cc]);
timer(5);
}
}
if(fen1==4)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu4[cc]);
timer(5);
}
}
if(fen1==5)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu5[cc]);
timer(5);
}
}
if(fen1==6)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu6[cc]);
timer(5);
}
}
if(fen1==7)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu7[cc]);
timer(5);
}
}
if(fen1==8)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu8[cc]);
timer(5);
}
}
if(fen1==9)
{
zhiling(0x80+0x43);
for(cc=0;cc<1;cc++)
{
shuju(shu9[cc]);
timer(5);
}
}
if(fen2==0)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu0[cc]);
timer(5);
}
}
if(fen2==1)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu1[cc]);
timer(5);
}
}
if(fen2==2)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu2[cc]);
timer(5);
}
}
if(fen2==3)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu3[cc]);
timer(5);
}
}
if(fen2==4)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu4[cc]);
timer(5);
}
}
if(fen2==5)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu5[cc]);
timer(5);
}
}
if(fen2==6)
{
zhiling(0x80+0x42);
for(cc=0;cc<1;cc++)
{
shuju(shu6[cc]);
timer(5);
}
}
mima6=0;
if(key6==0)
{
timer(5);
if(key6==0)
{
mima6=1;
num1++;
while(!key6);
}
}
while(mima6==1)
{
gaibian();
}
}
}
void zhuchengxu()
{
num1=0;
while(1)
{
jianpan();
while(mima6==1&num1==1)
{
mimide();
jianpan();
mima1zy=0;
while(mima1==1&num1==2)
{
mimide();
jianpan();
while(mima5==1&num1==3)
{
mimide();
jianpan();
while(mima1==1&num1==4&mima1zy==1)
{
mimide();
jianpan();
while(mima3==1&num1==5)
{mimide();
xianshide();
mima3=0;
num2=2;
timer(2000);
timer(2000);
timer(2000);
mima6=0;
laozhong();
}
}
}
}
}
mimide();
if(num1==7)
{
if(num2!=2)
{
if(num3==0)
{
cuowude();
num1=0;
mima6=0;
mima1=0;
mima5=0;
mima3=0;
}
}
}
}
}
void main()
{
init();
zhiling(0x80);
for(cc=0;cc<8;cc++)
{
shuju(xian1[cc]);
timer(5);
}
zhiling(0x80+0x42);
for(cc=0;cc<13;cc++)
{
shuju(xian2[cc]);
timer(5);
}
while(1)
{
zhuchengxu();
}
}
void dsq0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
dsd1++;
if(dsd1==20) /////////////////////////這里did1==1是錯誤的因改為dsd1==20
{
dsd1=0;
dsd2++;
if(dsd2==10)
{
dsd2=0;
dsd3++;
if(dsd3==6)
{
dsd3=0;
fen1++;
if(fen1==10)
{
fen1=0;
fen2++;
if(fen2==6)
{
fen2=0;
}
}
}
}
}
}
|
|