找回密码
 立即注册

QQ登录

只需一步,快速开始

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

求助 求分析

[复制链接]
跳转到指定楼层
楼主
ID:38204 发表于 2012-4-10 17:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

#include<reg51.h>
#include<1602.h>
#include<key.h>
#include<24c01.h>

#define uchar unsigned char
#define uint unsigned int
sbit LED1=P1^5;
sbit LED2=P1^6;
sbit INIT=P2^2;

uchar idata key[8]={0,0,0,0,0,0,0,0};  //初始化
uchar idata iic[8]={0,1,2,3,4,5,6,7};
void Delay5ms(uint t);
//**************************************************
void press(uchar *s)
{
  uchar dat;
  P3=0xf0;     //保存第一位密码
  while(P3==0xf0);
  dat=key_scan();
  if((dat!=0x0a)&&(dat!=0x0b))
  {   *s=dat;
   LCD_initial();
   LCD_set_position(0x40);  
   LCD_printc('*');      //输入密码显示*   
   LED1=0;
   Delay5ms(250);
   LED1=1;
   s++;    
   }
      
//**************************************************
    P3=0xf0;         //保存第二位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         { 
      *s=dat;
   LCD_printc('*');
   LED1=0;
         Delay5ms(250);
         LED1=1;
      s++;    
    }
    
//**************************************************
    P3=0xf0;         //保存第三位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         { 
      *s=dat;
   LCD_printc('*');
      LED1=0;
         Delay5ms(250);
         LED1=1;
   s++;    
    }
     
//**************************************************
    P3=0xf0;         //保存第四位密码
    while(P3==0xf0);      
    dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         {  
      *s=dat;
   LCD_printc('*');
   LED1=0;
         Delay5ms(250);
         LED1=1;
   s++;
    }
      
//**************************************************
    P3=0xf0;         //保存第五位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         {  
      *s=dat;
   LCD_printc('*');
   LED1=0;
         Delay5ms(250);
         LED1=1;
   s++;      
    }
     
//**************************************************
    P3=0xf0;         //保存第六位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         {  
        *s=dat;
     LCD_printc('*');
        LED1=0;
           Delay5ms(250);
           LED1=1;
     s++;          
       }
    
//**********************************************   
  P3=0xf0;         //保存第七位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         { 
       *s=dat;
     LCD_printc('*');
        LED1=0;
           Delay5ms(250);
           LED1=1;
       s++;
    }
     
   
//************************************************
    P3=0xf0;         //保存第八位密码
    while(P3==0xf0);      
       dat=key_scan();
    if((dat!=0x0a)&&(dat!=0x0b))
         { 
       *s=dat;
    LCD_printc('*');
    LED1=0;
          Delay5ms(250);
          LED1=1;
    }
//**************************************************
   do{
       P3=0xf0;       //键入Enter键盘继续执行下面语句,否则等待
       while(P3==0xf0);      
          dat=key_scan();
       }while(dat!=0x0b);
}
//*****************************************************
void Delay5ms(uint t)    //参数25延时5ms
{
 uint i,j,k;
 for(k=t;k>0;k--)
 for(i=25;i>0;i--)
 for(j=4;j>0;j--) ;


}


void main()
{
      uchar dat;
      uchar i=0,j=0,k;   
   uchar x=0;
   LED1=1;
   LED2=1;
   SOUND=0;
   INIT=1;    
 
  Designer();   //显示标题
     for(i=0;i<200;i++){Delay5ms(25);}
  Pass_init();
  for(i=0;i<250;i++)
  {   
   if(INIT==0)
   Delay5ms(25);
   if(INIT==0)
   {
   do{
   x=SendB(iic,0x50,8);
    }while(x!=1) ;
 
   x=0;
   break;
   }
 
   Delay5ms(25);
   }
  do{
   x=ReadB(iic,0x50,8);     //首先从IIC器件中读出密码以供下面输入密码
   }while(x!=1) ;
 
   x=0;
//**********************************若密码不正确,循环执行do{}while()********************************************
   do{
    
   
    LED1=1;
    System();                        //显示:"请输入密码"字幕 
    press(key);

 if((key[0]==iic[0])&&(key[1]==iic[1])&&(key[2]==iic[2])&&(key[3]==iic[3])&&(key[4]==iic[4])&&(key[5]==iic[5])&&(key[6]==iic[6])&&(key[7]==iic[7])) //密码比较,若密码正确责进入系统,若密码不正确则显示密码错误,重新输入密码
     {                            
   True();
   LED1=0;
   LED2=0;
  for(i=0;i<30;i++)
 {
       Sound_QQ(200,60);
   Delay5ms(100);
  }
  LED1=1;LED2=1;
  do
  {        
   P3=0xf0;       //键入1或2继续执行下面语句,否则等待
      while(P3==0xf0);      
         dat=key_scan();
        
  } while(dat!=1&&dat!=2);
 

 if(dat==1)             //开锁
  {
     LED1=0;
  Unlock();
        for(i=0;i<200;i++){Delay5ms(25);}           
     }
   if(dat==2)       //修改密码
 {
   
 do{
  Modify(); 
  press(key);
     Again();
     press(iic);
 if((key[0]==iic[0])&&(key[1]==iic[1])&&(key[2]==iic[2])&&(key[3]==iic[3])&&(key[4]==iic[4])&&(key[5]==iic[5])&&(key[6]==iic[6])&&(key[7]==iic[7]))
  {
    Succeed();    //修改密码成功
    for(i=0;i<100;i++){Delay5ms(25);}
    Delay5ms(25);
    x=SendB(iic,0x50,8);
    Delay5ms(25); 
       x=ReadB(iic,0x50,8);break;
     }
  else        //修改密码不成功,重新修改
  {
   Repeat();
   for(i=0;i<100;i++){Delay5ms(25);}
        }
   }while(1);  
    
     }
  
   }
 else            //密码不正确,重新输入密码
 {
  j++;
     if(j==3)
  {
  for(i=0;i<60;i++)
  {
  Sound_QQ(250,40);
  for(k=0;k<3;k++)
    
 {   LED1=~LED1;     
  LED2=~LED2;
  Delay5ms(25);
       
  }
    
  }
 j=0;
  }
 Error();
 for(i=0;i<50;i++)
   {
     Sound_QQ(250,40);   
  LED2=~LED2;
  Delay5ms(25);
   }
 for(i=0;i<100;i++){Delay5ms(35);}
   } 
}while(1);    
     
}

[此贴子已经被作者于2012-4-10 17:06:43编辑过]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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