找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4418|回复: 1
打印 上一主题 下一主题
收起左侧

密码程序与计时程序的结合-基于51MCU-C语言

[复制链接]
跳转到指定楼层
楼主
ID:76556 发表于 2015-4-10 03:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
启动显示  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;
                                        }
                                }
                        }
                }
        }
}





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:76556 发表于 2015-4-10 03:03 | 只看该作者
很复杂的程序  用了三天时间 应该说是写了一天改了两天
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表