导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→C51编程:天啦,我的程序怎么会这样,各位大虾帮帮忙看一下吧

* 2061: C51编程:天啦,我的程序怎么会这样,各位大虾帮帮忙看一下吧,指条明路给小弟!

   东海飘萍客 
东海飘萍客发表的帖子 

 C51编程:天啦,我的程序怎么会这样,各位大虾帮帮忙看一下吧,指条明路给小弟!
#include <reg51.h>  #include <intrins.h>  #include <string.h>
sbit     SDA=P1^5;sbit     SCL=P1^4;sbit     p06=P0^6;sbit     p05=P0^5;
sbit     p04=P0^4;sbit     p03=P0^3;sbit     p02=P0^2;sbit     p01=P0^1;
sbit     p00=P0^0;sbit     bell=P2^5;
sbit     led_yellow=P2^2;sbit     led_red=P2^1;
unsigned char    mode;
void delay(unsigned int delay_time);           //延时delay_timeMS
void RW24C01(unsigned char Address,unsigned char *p,unsigned char size,bit 
control);
void bellx(unsigned char bell_count);
void delay_us(unsigned int delay_time);
bit  Input_Keyboard(unsigned char *p2);
//bit compare_key(bit manage);
bit Modify(bit manage);
bit Input_Ic(unsigned char *p);
void main(void)
{
bit flag;
bellx(1);
flag=Modify(1);
if(flag)
{led_red=0;led_yellow=0;}
else{led_red=1;led_yellow=1;}
while(1);}
bit Input_Ic(unsigned char *p)
{return 0;}
/*bit compare_key(bit manage)         //如果有管理员,则manage为1,主要是进行密码
判别。
{unsigned char temp1,temp2;
 unsigned char Ram_Key[12];
 unsigned char Input_Key[12];
 unsigned char *p;
 if(manage) {
    RW24C01(0x01,Ram_Key,0x08,1);
    manage=Input_Keyboard(Input_Key);
    if(!manage) return 0;
    temp1=strncmp(Ram_Key,Input_Key,8);
    if(!(temp1==0)) return 0;
    return 1;}
 temp1=0x10;
 while(1){if(temp1>=0x60) return 0;
   RW24C01(temp1,&temp2,1,1);
    if(!(temp2==mode)){
      temp1+=0x10;continue;}
   switch(mode){
        case 1:manage=Input_Ic(Input_Key);
                            if(!manage) return 0;
                     temp1++; RW24C01(temp1,Ram_Key,4,1);
               manage=strncmp(Input_Key,Ram_Key,4);
               if(!(manage==0))
                                    {temp1+=0x0f;break;}
                            else  return 1;
      case 2:manage=Input_Ic(Input_Key);
             if(!manage) return 0;
      p=Input_Key; p+=4;
      manage=Input_Keyboard(p);
     if(!manage) return 0;
            RW24C01(temp1,Ram_Key,12,1);
      manage=strcmp(Input_Key,Ram_Key);
      if(!(manage==0))
         {temp1+=0x0f;break;}
             else  return 1;
     case 0:RW24C01(temp1,Ram_Key,8,1);
            manage=Input_Keyboard(Input_Key);
            if(!manage) return 0;
            manage=strncmp(Input_Key,Ram_Key,8);
     if(!(manage==0)){temp1+=0x0f;break;}
             else  return 1;
        }}
 return 0;}*/
//修改设置
bit Modify(bit manage)
{unsigned char temp1,temp2,temp3,temp4,temp5;
unsigned char *p;
unsigned char Input_Key[12];
unsigned char reimport[12];
bit  error;
error=0;
if(manage)                        //判断是否有管理员设置,如有,则改设置须先输入
{  manage=Input_Keyboard(Input_Key);
   if(!manage)  return 0;   
   if(!(Input_Key[0]==0xc0))              //如果不须修改管理密码,进入下面的设置
         {temp2=3;                               //最多可修改三次
       while(temp2>0)
       {manage=Input_Keyboard(Input_Key);      //键盘输入新的管理密码
          if(!manage) 
    {temp2--;error=1;continue;                  }
                  bellx(1);
    manage=Input_Keyboard(reimport);      //再输入一次,以便确认
          if(!manage) {temp2--;error=1;
    continue;                  //键盘输入发生错误,退出
 }
manage=strncmp(Input_Key,reimport,8);//两次密码进行比较,若相等,则进行修改
          if(manage==0)    {for(temp3=5;temp3>0;temp3--)
    {RW24C01(0x01,Input_Key,0x08,0);  //将密码写进内存,再取出进行比较。
          RW24C01(0x01,reimport,0x08,1);
          manage=strncmp(Input_Key,reimport,8);
    if(manage==0)     return 1;
    error=1;}
    if(error==1)   return 0;}
         temp2--;error=1;}
        if(error==1)   return 0;           }      }
manage=Input_Keyboard(Input_Key);          //输入修改第几组,在1-5之间,如不在,
if(!manage) return 0;                           //则退出
temp1=Input_Key[0];
temp1>>=4;
temp1&=0x0f;
if(temp1==0x0c) return 1;                //不须修改则退出
if((temp1<6)&&(temp1>0))              //确定写进内存的地址
    temp1*=0x10;
    else return 0;                             
manage=Input_Keyboard(Input_Key);               //进行模式的修改,若在0-2则为合
法的,可写入
temp2=Input_Key[0];
temp2>>=4;
temp2&=0x0f;
if(temp2==0x0c) return 1;                //不须修改则退出
if((temp2<3)&&(temp2>=0))
    {
    error=0;
    RW24C01(temp1,&temp3,0x01,1);
    delay(100);
   for(temp4=5;temp4>0;temp4--)
        {
        RW24C01(temp1,&temp2,0x01,0);  //将密码写进内存,再取出进行
比较。
        delay(100);
      RW24C01(temp1,&temp5,0x01,1);
      if(temp5==temp2) 
    {error=0;break;}
       error=1;}
    if(error)  return 0;
    temp1++;                                     //确定写内存的首地址
   switch(temp2)                                  //进行密码的修改
    {case 0:temp2=3;
             while(temp2>0)
            {manage=Input_Keyboard(Input_Key);           //单一键盘模式 
           if(!manage) return 0;
            manage=Input_Keyboard(reimport);           //再输入一次密码 
           if(!manage) return 0;
     manage=strncmp(Input_Key,reimport,8);//两次密码进行比较,若相等,则进行修改
           if(manage==0){for(temp4=5;temp4>0;temp4--)
    {RW24C01(temp1,Input_Key,0x08,0);  //将密码写进内存,再取出进行比较。
                          delay(100);
            RW24C01(temp1,reimport,0x08,1);
           manage=strncmp(Input_Key,reimport,8);
    if(manage==0)   return 1;
    error=1;}
    if(error==1)   return 0;}
    temp2--;}
    temp1--;
for(temp4=5;temp4>0;temp4--)
   {RW24C01(temp1,&temp3,0x01,0);        //密码修改不成功,返回修改前的状
    RW24C01(temp1,&temp2,0x01,1);
           if(temp2==temp3) return 0;}
            return 0;                                  //退出
case 1:temp2=3;
       while(temp2>0)
      {manage=Input_Ic(Input_Key);
       if(!manage) return 0;
      manage=Input_Ic(reimport);
      if(!manage) return 0;
manage=strncmp(Input_Key,reimport,8);//两次密码进行比较,若相等,则进行修改
    if(manage==0){
        for(temp4=5;temp4>0;temp4--)
{RW24C01(temp1,Input_Key,0x04,0);  //将密码写进内存,再取出进行比较。
RW24C01(temp1,reimport,0x04,1);
      manage=strncmp(Input_Key,reimport,4);
if(manage==0) return 1;                
    error=1;}
if(error==1)   return 0;}
    temp2--;}
    temp1--;
 for(temp4=5;temp4>0;temp4--)
 {RW24C01(temp1,&temp3,0x01,0);        //密码修改不成功,返回修改前的状
    RW24C01(temp1,&temp2,0x01,1);
       if(temp2==temp3) return 0;}
             return 0;                                  //退出
case 2:temp2=3;
        while(temp2>0){    
        manage=Input_Ic(Input_Key);
       if(!manage) return 0;
    p=Input_Key;p+=4;
          manage=Input_Keyboard(Input_Key);
          if(!manage) return 0;
    manage=Input_Ic(reimport);
    if(!manage) return 0;
    p=reimport;p+=4;
          manage=Input_Keyboard(reimport);
          if(!manage) return 0;
    manage=strncmp(Input_Key,reimport,12);//两次密码进行比较,若相等,则进行修改
          if(manage==0){for(temp4=5;temp4>0;temp4--)
    {RW24C01(temp1,Input_Key,0x12,0);  //将密码写进内存,再取出进行比较。
           RW24C01(temp1,reimport,0x12,1);
            manage=strcmp(Input_Key,reimport);
    if(manage==0) return 1;
    error=1;}
    if(error==1)   return 0;}
    temp2--;}
     temp1--;
for(temp4=5;temp4>0;temp4--)
{RW24C01(temp1,&temp3,0x01,0);        //密码修改不成功,返回修改前的状
    RW24C01(temp1,&temp2,0x01,1);
                if(temp2==temp3) return 0;}
            return 0;                                  }
   }
else return 0;                               //企图写入非法的模式,退出
}
void bellx(unsigned char bell_count)
{unsigned int count1;
do{for(count1=0x019b;count1>0;count1--)
  {bell=0;delay_us(55);bell=1;delay_us(55);}
   delay(80);bell_count--;}
while(bell_count>0);
return ;}
我上面有两个函数有冲突,是Modify()和compare_key().当他们同时存在时,哪怕没有执行
他们,程序都工作不正常,具体表现为bellx()函数工作不正常 (这是一个蜂鸣器的函
数),我只叫他叫一声,可是他却叫个不停。如果在Modify()和compare_key()中注释掉一
个之后,工作正常,可是我想他们同时存在,不知各位大虾有何高见,解决小弟这个难
题!!上面有些子程序我已验证是正确的,并且由于空间的原因,没有贴上。

发表时间:2001年10月23日10:54:00

  
回复该帖

本主题共有 2 帖,分页:>>>>>该主题的所有内容[2]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  2063.[详细]帮忙分析一下了,具体的内容你可以不要看啊,就是当Modify()和compare_key()函数同..
摘要:......(无内容)
- [东海飘萍客][1985次] 2001年10月23日

[上一篇帖子]:硬件:我用PCB布了一块版,干扰极大,高频信号经过一些元件过来后,完全失真,电路没问题,不知各位大虾
[下一篇帖子]:哈哈,我也深有同感,你是干什么的,有联系方式吗??