| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 282 人关注过本帖
标题:求助~我的8不见了,谁能帮我整好啊~~
只看楼主 加入收藏
qunqun3012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-10-12
结帖率:50%
收藏
已结贴  问题点数:1 回复次数:2 
求助~我的8不见了,谁能帮我整好啊~~
是一个实现数值比较的程序,当1和8同时触发的时候例如12378,显示3,不考虑全部触发的情况(12345678),两端如果不同时触发时,显示最大的数,例如1257,显示7。现在的问题是我的8不见了,第一种情况的判断也就不成立,我改了下判断条件当1和7同时触发时(12367)显示3,这个是正确的结果,1到7单独触发一个数字也能正确显示,8不显示。   帮帮忙,为什么8没了~~~~



#include <AT89X52.H>
#include <stdio.h>

sbit K0=P1^0;
sbit K1=P1^1;
sbit K2=P1^2;
sbit K3=P1^3;
sbit K4=P1^4;
sbit K5=P1^5;
sbit K6=P1^6;
sbit K7=P1^7;

unsigned int length[7]={0};

unsigned int n,i,click=0;
unsigned char s0,s1,s2,s3,s4,s5,s6,s7;
unsigned char start_data=0;


void timer0_ISR (void) interrupt 1
{
//unsigned char i;
click++;
if(click == 200)
    {
    click = 0;
           if(start_data==1)
              {
                  if(length[0]==1&&length[7]==8)
                    {
                      for(i=0;i<=6;i++)
                     {
                       if((length[i+1]-length[i])!=1)
                           {
                              printf("#%d",length[i]);
                              for(n=0;n<=7;n++)
                               {
                                  length[n]=0;
                               }
                              start_data=0;
                              break;
                           }
                     }
                    }
                  
                  
                  else   
                   {     
                     for(i=7;i>=1;i--)
                     {
                        if(length[i]>length[i-1])
                           {
                              printf("#%d",length[i]);
                              for(n=0;n<=7;n++)
                               {
                                  length[n]=0;
                               }
                              start_data=0;
                              break;
                              }
                         if(length[1]<length[0])
                          {
                              printf("#1");
                              for(n=0;n<=7;n++)
                               {
                                  length[n]=0;
                               }
                              start_data=0;
                              break;
                          }                     
                     }
                   }
              }
    }
TH0 = 0x3C;
TL0 = 0xAF;
}   


 
void main(void)
{
   

   
    SCON = 0x50; //&acute;&reg;&iquest;&Uacute;·&frac12;&Ecirc;&frac12;1,&Ocirc;&Ecirc;&ETH;í&frac12;&Oacute;&Ecirc;&Otilde;
    TMOD = 0x20; //&para;¨&Ecirc;±&AElig;÷1&para;¨&Ecirc;±·&frac12;&Ecirc;&frac12;2
    TCON = 0x40; //&Eacute;è&para;¨&Ecirc;±&AElig;÷1&iquest;&ordf;&Ecirc;&frac14;&frac14;&AElig;&Ecirc;&yacute;
    TH1 = 0xfd;    //11.0592MHz 9600&sup2;¨&Igrave;&Oslash;&Acirc;&Ecirc;
    TL1 = 0xfd;
    TH0 = 0x3C;
    TL0 = 0xAF;
    TI = 1;
    TR0 = 1;
    TR1 = 1; //&AElig;&ocirc;&para;&macr;&para;¨&Ecirc;±&AElig;÷
    EA = 1;
    ET0=1;

    while(1)
    {


      if(!K0)
        {
           for(n=0;n<1000;n++);            
                  for(;s0<=1;s0++)
               {
                    length[0]=1;
                      start_data=1;
               }
         }   
           else if(K0)
         {                  
               for(n=0;n<1000;n++);   
               s0=1;
         }                 
      
      if(!K1)
         {
            for(n=0;n<1000;n++);
                  for(;s1<=1;s1++)
               {
                    length[1]=2;
                      start_data=1;   
               }
         }   
           else if(K1)
         {                  
               for(n=0;n<1000;n++);   
               s1=1;
         }
         
       if(!K2)
         {
            for(n=0;n<1000;n++);                  
                  for(;s2<=1;s2++)
               {
                    length[2]=3;
                      start_data=1;   
               }
         }   
           else if(K2)
         {            
               for(n=0;n<1000;n++);   
               s2=1;
         }            

       if(!K3)
         {
            for(n=0;n<1000;n++);            
                  for(;s3<=1;s3++)
               {
                    length[3]=4;
                      start_data=1;
               }
         }   
           else if(K3)
         {            
               for(n=0;n<1000;n++);   
               s3=1;
         }
        
       if(!K4)
         {
            for(n=0;n<1000;n++);               
               for(;s4<=1;s4++)
               {
                    length[4]=5;
                      start_data=1;
               }
         }   
           else if(K4)
         {
            
               for(n=0;n<1000;n++);   
               s4=1;
         }         

       if(!K5)
         {
            for(n=0;n<1000;n++);               
               for(;s5<=1;s5++)
               {
                    length[5]=6;
                      start_data=1;
               }
         }   
           else if(K5)
         {            
               for(n=0;n<1000;n++);   
               s5=1;
         }            

        if(!K6)
         {
            for(n=0;n<1000;n++);   
               for(;s6<=1;s6++)
               {
                    length[6]=7;
                      start_data=1;                    
               }
         }   
           else if(K6)
         {
               for(n=0;n<1000;n++);   
               s6=1;
         }   

       if(!K7)
         {
            for(n=0;n<1000;n++);            
               for(;s7<=1;s7++)
               {
                    length[7]=8;
                      start_data=1;            
               }
         }   
           else if(K7)
         {   
               for(n=0;n<1000;n++);   
               s7=1;
         }      
     }   
}

2010-11-05 16:21
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:0 
我靠,太长了吧.还有个你自己编的外部文件呢?

经验积累中............
2010-11-05 16:49
qunqun3012
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-10-12
收藏
得分:0 
找到为什么了,错误太低级了,NND,数组定义小了一位,没有外部文件
2010-11-05 16:51
快速回复:求助~我的8不见了,谁能帮我整好啊~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040012 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved