打印

为什么我用单片机驱动数码管最后一为总是暗亮

[复制链接]
4163|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mengguan235|  楼主 | 2011-8-20 16:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
位选是用74HC138驱动,段选是用的74HC573驱动的,每次显示是不改亮的位也是暗亮,谁能帮我看看是怎么回事啊  ,硬件应该是没什么问题 ,用其他的程序没有这个现象,这段程序就是在显示正常的程序上改的  ,求高手帮忙给看看
/*************************************************************************************
*          多重过程报警显示处理子程序                         *     
*                                           *
**************************************************************************************/
void MUL_display(unsigned char one ,unsigned char two,unsigned char three,unsigned char four)
{
    if(Flag_set)    //Flag_set  设置标志位  
  {  
  
   LedOut[0]=Disp_alph[pos_alph];    //千位
     LedOut[1]=Disp_Tab[LedNumVal%1000/100];      //百位带小数点
     LedOut[2]=Disp_Tab[LedNumVal%100/10]&0x7f;   //十位
     LedOut[3]=Disp_Tab[LedNumVal%10];            //个位
   LedOut[4]=Disp_Tab[LedNumVal%10000/1000];    //千位
     LedOut[5]=Disp_Tab[LedNumVal%1000/100]&0x7f;
     LedOut[6]=Disp_Tab[LedNumVal%100/10];
     LedOut[7]=Disp_Tab[LedNumVal%10];
  }
  else
  {
      
  LedOut[0]=one;      //Disp_Tab[monitor_Number];  
    LedOut[1]=two;
    LedOut[2]=three;
    LedOut[3]=four;  
  LedOut[4]=Disp_Tab[11];    //千位
    LedOut[5]=Disp_Tab[D[run_sum]%1000/100];
    LedOut[6]=Disp_Tab[D[run_sum]%100/10];
    LedOut[7]=Disp_Tab[D[run_sum]%10];
  }
}

/*************************************************************************************
*          数码管显示处理                               *     
*                                           *
**************************************************************************************/
void Display()
{   
   unsigned int i;
  for( i=0; i<8; i++)
  {
   
   switch(i)      
      {     
   case 0:
   if ((pos == 1 )&Flag_Tim & (ADD&SUB))
   {LedOut[0] = 0xff;
   break;
   }
   else
   {LS138A=0; LS138B=0; LS138C=0;
    //L1 = 0;  L2 = 1;  L3 = 1; L4 = 1;
   break;
   }
         
       case 1:
   if ((pos == 2 )&Flag_Tim& (ADD&SUB))
   {LedOut[1] = 0xff;
   break;
   }
   else
   {LS138A=1; LS138B=0; LS138C=0;
    //L1 = 1;  L2 = 0;  L3 = 1; L4 = 1;
   break;}
                 
       case 2:
   if ((pos == 3 )&Flag_Tim& (ADD&SUB))
   {LedOut[2] = 0xff;
   break;
   }
   else
   {LS138A=0; LS138B=1; LS138C=0;
    //L1 = 1;  L2 = 1;  L3 = 0; L4 = 1;
   break;}
       case 3:
   if ((pos == 4 )&Flag_Tim& (ADD&SUB))
   {LedOut[3] = 0xff;
   break;
   }
   else
   {LS138A=1; LS138B=1; LS138C=0;
    //L1 = 1;  L2 = 1;  L3 = 1; L4 = 0;
   break;}
   
   case 4:
   if ((pos == 1 )&Flag_Tim& (ADD&SUB))
   {LedOut[4] = 0xff;
   break;
   }
   else
   {LS138A=0; LS138B=0; LS138C=1;
    //L1 = 1;  L2 = 0;  L3 = 0; L4 = 0;
    break;}
   case 5:
   if ((pos == 2 )&Flag_Tim& (ADD&SUB))
   {LedOut[5] = 0xff;
   break;
   }
   else
   {LS138A=1; LS138B=0; LS138C=1;
   // L1 = 0;  L2 = 1;  L3 = 0; L4 = 0;
   break;}
   case 6:
   if ((pos == 3 )&Flag_Tim& (ADD&SUB))
   {LedOut[6] = 0xff;
   break;
   }
   else
   {LS138A=0; LS138B=1; LS138C=1;
    //L1 = 0;  L2 = 0;  L3 = 1; L4 = 0;
   break;}
   case 7:
   if ((pos == 4  )&Flag_Tim& (ADD&SUB))
   {  LedOut[7] = 0xff;
       break;
   }
   else
   {LS138A=1; LS138B=1; LS138C=1;
    //L1 = 0;  L2 = 0;  L3 = 0; L4 = 1;
   break; }   
   
      }
     P1 = LedOut[i];
   
  delay(5);
   }
     P1 = 0xff;
   
}
/*************************************************************************************
*          延时程序                           *     
*                      *
**************************************************************************************/
void delay(unsigned int i)
{
    char j;
    for(i; i > 0; i--)
        for(j = 200; j > 0; j--);
}

/*************************************
[ t1 (10ms)中断] 中断
*************************************/
void T1zd(void) interrupt 3      //3定时器1的中断号  1定时器0的中断号 0外部中断1 2外部中断2  4串口中断
{
  TH1 = 0xD8;    //12.000
  TL1 = 0xF0;
  Tick_10ms++;
  Tick1_10ms++;
  Tick2_10ms++;

  if (++user_T == 30)  
{Flag_Tim = ~Flag_Tim;
  user_T = 0;
  }
   if (++user_T1 == 30)
   {   

if (Flag_set)    //Flag_set  设置标志位     
{  
      if (pos == 1)  //  pos  光标位置
    {
      //val  参数设置变量
        if (!SUB &ADD )    val = (--temp)%3;
    if (!ADD &SUB )    val = (++temp)%3;
    }
      else  
    {
      if (!ADD & SUB & LedNumVal < 999)  val2++ ;
        if (!SUB & ADD & val2 > -1 )  val2-- ;
    }
  }
   user_T1 = 0;
}
}

相关帖子

沙发
红金龙吸味| | 2011-8-20 16:43 | 只看该作者
注意消影处理,在每次刷新送数据之前,关闭所有数码管。

使用特权

评论回复
板凳
mengguan235|  楼主 | 2011-8-20 16:50 | 只看该作者
谢谢楼上的了   现在没问题了    把P1=0XFF改成了P1=0X00,就行了    我把这个弄混了   呵呵

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

14

帖子

1

粉丝