• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

做led控制器碰到个问题

大家好,我是刚进入led控制器行业,以前做的都是硬件多,现在公司要做led控制器,我参考别人板子做了个主控制,后面是再加驱动板子.软件调试时候,仿真p2,p0口都看到有电平信号出来了,可我烧进51后,再测试接口电平,就一直高电平,不知道怎么回事.是不是我软件不行,高手请帮看下软件到底对不对?通过给245信号,再经过595放大驱动led
谢谢
做了好多天了,老调试不来,很希望能得到高手指点下
全部回复(9)
正序查看
倒序查看
2008-07-08 00:05
不知道怎么回事,老上传不了
这么把程序发上去好了

#include
#include ///////调用绝对地址访问函数////
#include ///////
#define uchar unsigned char
#define uint  unsigned int////内部函数/////
#define hao 0xc0
sbit    oe   =P2^7;
sbit    rck  =P2^6;
sbit    sck  =P2^5;
sbit    datar=P2^4;

sbit    wog  =P3^5;
sbit    led  =P0^7;
sbit    s23   =P0^5;
sbit    s22   =P0^4;
sbit    s21   =P0^3;
sbit    s24   =P0^6;
sbit    SDA  =P2^1;
sbit    SCL  =P2^0;//////用到两个字节,第一个字节用来放模式,第2个字节用来放速度///不用也算了////////
bit input=0;
bit power=1;
uchar waita,timea,hui,liang,timeb;
uchar color,color1,mode,speed,speed1;
uchar s220,s221,s230,s231,s210,s211,s240,s241,mode; //key parmerter
bit addr,ishui,istype,istime,iscolor;
uchar huidu,speeddu,colordu,address,type;
uchar  code  spd[]={8,15,30,60,120,240,240};
uchar  code  spd1[]={2,5,13,19,28,45,90};
#define AddWr 0xa0 /*器件地址选择及写标志*/
#define AddRd 0xa1 /*器件地址选择及读标志*/
////////////////////////////////////////////////
void mDelay(uchar j)
{ uint i;
for(;j>0;j--)
{
for(i=0;i<125;i++)
{;}
}
}
/*发送起始条件*/
void Start(void)        /*起始条件*/
{
        SDA=1;
        SCL=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SDA=0;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
}
void Stop(void) /*停止条件*/
{
        SDA=0;
        SCL=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SDA=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
}
void Ack(void)  /*应答位*/
{
        SDA=0;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SCL=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SCL=0;
}
void  NoAck(void)       /*反向应答位*/
{
        SDA=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SCL=1;
        _nop_ ();
        _nop_ ();
        _nop_ ();
        _nop_ ();
        SCL=0;
}
void Send(uchar Data)   /*发送数据子程序,Data为要求发送的数据*/
{
        uchar BitCounter=8;       /*位数控制*/
        uchar temp;     /*中间变量控制*/
        do
        {
           temp=Data;
           SCL=0;
           _nop_ ();
           _nop_ ();
           _nop_ ();
           _nop_ ();
           if((temp&0x80)==0x80)/* 如果最高位是1*///////
                SDA=1;
           else
                SDA=0;
           SCL=1;//////////////////////发送准备结束
           temp=Data<<1;        /*RLC*///////下一个字节
           Data=temp;
           BitCounter--;////////////
        }while(BitCounter);
         SCL=0;//////结束发送/////
}
uchar Read(void) /*读一个字节的数据,并返回该字节值*/
{
        uchar temp=0;
        uchar temp1=0;
        uchar BitCounter=8;
        SDA=1;
        do{
          SCL=0;
          _nop_ ();
          _nop_ ();
          _nop_ ();
          _nop_ ();
          SCL=1;
          _nop_ ();
          _nop_ ();
          _nop_ ();
          _nop_ ();
          if(SDA)       /*如果Sda=1;*/
                temp=temp|0x01;  /*temp的最低位置1*/
          else
                temp=temp&0xfe;  /*否则temp的最低位清0*/
          if(BitCounter-1)
          {   temp1=temp<<1;
              temp=temp1;
          }
          BitCounter--;
        }while(BitCounter);
        return(temp);
}
void WrToROM(uchar Data[],uchar Address,uchar Num)///////////////写数据到ROM中
{
     uchar i=0;
     uchar *PData;/////指针类
     PData=Data;
     Start();        
     Send(0xa0);   /////发送
     Ack();/////应答
     Send(Address);  //////发送数据地址
     Ack();
     for(i=0;i     {
        Send(*(PData+i));
        Ack();
     }
     Stop();
}
void  RdFromROM(uchar Data[],uchar Address,uchar Num)////////从ROM中读取
{
     uchar i=0;
     uchar *PData;
     PData=Data;
     for(i=0;i     {
        Start();
        Send(0xa0);///////////先写后读
        Ack();
        Send(Address+i);
        Ack();
        Start();
        Send(0xa1);
        Ack();
        *(PData+i)=Read();
        SCL=0;
        NoAck();
        Stop();
   }
}
//////////////////////////////////////
void   yanse0()
{
switch(color)
{
   case   0:
              datar=0;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
   case   1:
              datar=1;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
   case   2:
              datar=1;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
  case   3:
              datar=0;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
  case   4:
              datar=0;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
   case   5:
              datar=1;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
   case   6:
              datar=0;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;
              datar=0;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
  case   7:
              datar=1;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;
              datar=1;
              sck=0;
              sck=1;

              sck=0;
              sck=1;
              break;
   default:
              break;
   }
}
////////////////////////////////////////////////
void comm() interrupt 4 using 3
{
if(RI)
{
    RI=0;
    if(addr==0)
   {
    if((address==SBUF)|(SBUF==0XFF))
     {
      istype=1;
      ishui=0;
      istime=0;
      addr=1;
     }
   }
   else if(istype)//////接收模式数据
   {
    istype=0;
    ishui=1;
    type=SBUF;
   }
   else if(ishui) //////接收灰度数据
   {
    ishui=0;
    istime=1;
    huidu=SBUF;
   }
   else if(istime)///////接收时间数据
   {
    istime=0;
    speeddu=SBUF;
addr=0;
    led=1;
input=1;
   }
}
else TI=0;
}
////////////////////////////////////////////////
void time0() interrupt 1 using 1
{
  timea++;
  /////////////scan key board begin//////////////
  if((s23==0)&(s230==0)&(s231==0))
  {
    s230=1;
  }
  else if((s23==0)&(s230==1)&(s231==0))
  {
    s230=0;
    s231=1;
  }
  else if((s23==1)&(s230==0)&(s231==1))
  {
   s231=0;
   mode=0;
   input=1;
   }
   //////////////key s22/////////////////////////////
  if((s22==0)&(s220==0)&(s221==0))
  {
    s220=1;
  }
  else if((s22==0)&(s220==1)&(s221==0))
  {
    s220=0;
    s221=1;
  }
  else if((s22==1)&(s220==0)&(s221==1))
  {
   s221=0;
   mode=1;
   input=1;
   }
if((s21==0)&(s210==0)&(s211==0))
  {
    s210=1;
  }
  else if((s21==0)&(s210==1)&(s211==0))
  {
    s210=0;
    s211=1;
  }
  else if((s21==1)&(s210==0)&(s211==1))
  {
   s211=0;
   mode=2;
   input=1;
   }
////////////////////////////////////////
if((s24==0)&(s240==0)&(s241==0))
  {
    s240=1;
  }
  else if((s24==0)&(s240==1)&(s241==0))
  {
    s240=0;
    s241=1;
  }
  else if((s24==1)&(s240==0)&(s241==1))
  {
   s241=0;
   mode=3;
   input=1;
   }
   /////////////scan key board end/////////////////////////
  if(timea>50)
   {
    waita++;
    timeb++;
    if(timeb>100)
    {
    timeb=0;
    led=~led;
    }
    timea=0;
   }
  liang--;
  if(liang>hui)  oe=1;
  else oe=0;
  if(liang==0)  liang=50;

  TH0  = 0Xfd; //5MS
  TL0  = 0x00;
}
/////////////////////////////
main()
{
  uchar a,b,c;
  TMOD=0x20;  //
  ET0 = 1;     // 允许定时器0中断
  ES=1;         //默认允许串口中断
  SCON=0X50;    //
  PCON=0X80;    //
  TH0 =0Xc0;    //5MS
  TL0 =0x00;    //定时0设定初值
  TH1=0Xfb;
  TR0 = 1;      //开定时器1
  TR1 =1 ;      //开定时器1
  IT0=1;        //外部中断0为脉冲触发方式(下降沿)
  EX0=1;        //禁 止外部中断0;
  WrToROM( );
  RdFromROM();  ////读取该分控的地址
  ////address=0x04;
  IP  =0X10;    //串行口为高优先级中断
  EA  = 1;      //开总中断
  input=0;
  color=1;
  type=0;
  speed=50;     //分控预先设置的默认速度
  color=2;      //分控预先设置的颜色
  hui=50;       //分控预先设置的灰度数
  addr=0;        ////默认的分控是拒绝接受任何数据的
///////////////////////////////////////////////
  for(;;)
   {
  ll:
       input=0;
   //type++;
       switch(type)
      {
        case 0://////0~~6为6种单色
         hui=huidu;
         speed=speeddu;
color=0;
for(a=0;a<4;a++)
{
         yanse0();
             }
rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;

             break;
  case 1:
         hui=huidu;
         speed=speeddu;
color=1;
for(a=0;a<4;a++)
{
     yanse0();
}
rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 2:
         hui=huidu;
         speed=speeddu;
         color=2;
for(a=0;a<4;a++)
{
     yanse0();
}
rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 3:
     hui=huidu;
         speed=speeddu;
         color=3;
for(a=0;a<4;a++)
{
         yanse0();
}
rck=0;
             rck=1;
         do{
         if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 4:
     hui=huidu;
         speed=speeddu;
         color=4;
for(a=0;a<4;a++)
{
     yanse0();
}
rck=0;
             rck=1;
     do{
         if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 5:
     hui=huidu;
         speed=speeddu;
         color=5;
for(a=0;a<4;a++)
{
     yanse0();
}
rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 6:
     hui=huidu;
         speed=speeddu;
         color=6;
for(a=0;a<4;a++)
{
         yanse0();
}
rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
   case 7:
     hui=huidu;
         speed=speeddu;
         color=7;
for(a=0;a<4;a++)
{
         yanse0();
}
             rck=0;
             rck=1;
     do{
           if(input==1)  goto ll;
           }
         while(waita             waita=0;
             break;
  case 8://渐变
         speed=speeddu;
for(a=0;a<7;a++)
{
  color=a;
              for(b=0;b<4;b++)
  {
          yanse0();
  }
              rck=0;
              rck=1;
  for(c=0;c<50;c++)
  {
   hui=c;
       do{
             if(input==1)  goto ll;
            }
           while(waita               waita=0;
               if(input==1)  goto ll;
  }
  for(c=50;c>0;c--)
  {
   hui=c;
       do{
             if(input==1)  goto ll;
            }
           while(waita               waita=0;
  }
         if(input==1)  goto ll;
}
break;
  default:
         break;
      }

}
}
0
回复
2008-07-08 00:12
@zhongyuqiang
不知道怎么回事,老上传不了这么把程序发上去好了#include#include///////调用绝对地址访问函数////#include///////#defineucharunsignedchar#defineuint  unsignedint////内部函数/////#definehao0xc0sbit    oe  =P2^7;sbit    rck  =P2^6;sbit    sck  =P2^5;sbit    datar=P2^4;sbit    wog  =P3^5;sbit    led  =P0^7;sbit    s23  =P0^5;sbit    s22  =P0^4;sbit    s21  =P0^3;sbit    s24  =P0^6;sbit    SDA  =P2^1;sbit    SCL  =P2^0;//////用到两个字节,第一个字节用来放模式,第2个字节用来放速度///不用也算了////////bitinput=0;bitpower=1;ucharwaita,timea,hui,liang,timeb;ucharcolor,color1,mode,speed,speed1;uchars220,s221,s230,s231,s210,s211,s240,s241,mode;//keyparmerterbitaddr,ishui,istype,istime,iscolor;ucharhuidu,speeddu,colordu,address,type;uchar  code  spd[]={8,15,30,60,120,240,240};uchar  code  spd1[]={2,5,13,19,28,45,90};#defineAddWr0xa0/*器件地址选择及写标志*/#defineAddRd0xa1/*器件地址选择及读标志*/////////////////////////////////////////////////voidmDelay(ucharj){uinti;for(;j>0;j--){for(i=0;i
希望大家见凉
0
回复
2008-07-08 00:15
@zhongyuqiang
希望大家见凉
0
回复
2008-07-08 00:17
@zhongyuqiang
2646981215447325.rar
0
回复
2008-07-08 22:23
怎么没高手解释下呢?自己顶下
0
回复
2008-07-08 22:32
硬件电路正确?仿真的时候,很多必须连接的线都不用连上的……
0
回复
2008-07-17 21:04
51系列单片机有一个还是两个口是OC门的,需要上拉电阻,具体你看一下资料
0
回复
2008-07-22 17:56
你应该是用51的单片机,我很熟悉,有需要联系下拉,QQ:395728911
呵呵
0
回复
2008-07-25 11:41
@zhongyuqiang
2646981215447454.rar
搞那么复杂,用SONIX的就行了啊,指令又不多.
0
回复