Thông báo

Collapse
No announcement yet.

CẦN giúp đỡ vấn đề tạo mảng trong KEIL C

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • CẦN giúp đỡ vấn đề tạo mảng trong KEIL C

    các bác giúp dùm em với, em đau đầu với cái vụ này quá ạ, em dùng Keil C viết chương trình cho thằng 89C52, khai báo mảng kiểu gì cũng bị "DATA SEGMENT TOO LARGE" hết đó, như là:
    const unsigned char ...[]={...};
    unsigned char code ...[]={...};
    ...
    chán quá các bác ơi, các bác xem và ráng giúp dùm em xíu nha, em nghi thằng Keil C bị sao sao đó, các bác thử copy vào chương trình của mình xem có bị lỗi như em không nha ráng giúp em nha mấy bác
    Code:
    #include <REGX52.H>
    #include <stdio.h>
    #define DATA P2_0
    #define SCK P2_1
    #define SCL P2_2
    int j,i,w,a,b,c,z,jj,d,e,bb,f,g,h,aa,r,t,u,q,s,v,solea,sole1;
    int tdr,tdr1,tdr2,tdr3,tdr4,tdr5,tdr6,tdr7,tdr8,tdr9,tdr10,tdr11,tdr12,tdr13,tdr14,tdr15,tdr16,tdr17,tdr18,tdr19,tdr20,tdr21,tdr22,tdr23,tdr24,tdr25,tdr26,tdr27,tdr28,tdr29,tdr30,tdr31,tdr32,tdr33,tdr34,tdr35,tdr36,tdr37,tdr38,tdr39,tdr40,tdr41;
    void delay(unsigned int ms)
    {unsigned int n;
    for(n=0;n<ms;n++){for(bb=0;bb<125;bb++){;}}
    }
    void dich()
    {
    SCK=0;
    SCK=1;
    }
    void chot()
    {
    SCL=0;
    SCL=1;
    }
    void data595(unsigned char k)
    {
    unsigned char temp,y;
    for(y=0;y<8;y++)
    {
    temp=k;
    temp=temp&0x80;
    if(temp==0x80)
    DATA=1;
    else 
    DATA=0;
    dich();
    k*=2;
    }
    }
    const unsigned char hieuung[17]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0x00,0x80,0xC0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
    const unsigned char hieuung1[64]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f};
    const unsigned char chaysole[37]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x05,0x0a,0x15,0x2a,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x54,0xa8,0x50,0xa0,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    const unsigned char ngatquangnho[4]={0x11,0x33,0x77,0xff};
    const unsigned char trenduoira[9]={0x01,0x03,0x05,0x09,0x11,0x21,0x41,0x81,0x01};
    const unsigned char trenduoira1[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
    const unsigned char trenduoira2[7]={0x81,0x82,0x84,0x88,0x90,0xa0,0xc0};
    const unsigned char trenduoira3[6]={0xc1,0xc2,0xc4,0xc8,0xd0,0xe0};
    const unsigned char trenduoira4[5]={0xe1,0xe2,0xe4,0xe8,0xf0};
    const unsigned char trenduoira5[4]={0xf1,0xf2,0xf4,0xf8};
    const unsigned char trenduoira6[3]={0xf9,0xfa,0xfc};
    const unsigned char trenduoira7[2]={0xfd,0xfe};
    void trenduoiraI()
    {
    //dot 1
    for(tdr=0;tdr<9;tdr++)
    {data595(trenduoira[tdr]);data595(0x00);data595(0x01);data595(0x00);chot();delay(100);}
    for(tdr1;tdr1<9;tdr1++)
    {data595(0x01);data595(trenduoira1[tdr1]);data595(0x01);data595(0x00);chot();delay(100);}
    for(tdr2=0;tdr2<9;tdr2++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr2]);data595(0x00);chot();delay(100);}
    for(tdr3=0;tdr3<8;tdr3++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira1[tdr3]);chot();delay(100);}
    //dot 2
    for(tdr4=0;tdr4<9;tdr4++)
    {data595(trenduoira[tdr4]);data595(0x00);data595(0x01);data595(0x80);chot();delay(100);}
    for(tdr5=0;tdr5<9;tdr5++)
    {data595(0x01);data595(trenduoira1[tdr5]);data595(0x01);data595(0x80);chot();delay(100);}
    for(tdr6=0;tdr6<9;tdr6++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr6]);data595(0x80);chot();delay(100);}
    for(tdr7=0;tdr7<7;tdr7++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira2[tdr7]);chot();delay(100);}
    //dot 3
    for(tdr8=0;tdr8<9;tdr8++)
    {data595(trenduoira[tdr8]);data595(0x00);data595(0x01);data595(0xc0);chot();delay(100);}
    for(tdr9=0;tdr9<9;tdr9++)
    {data595(0x01);data595(trenduoira1[tdr9]);data595(0x01);data595(0xc0);chot();delay(100);}
    for(tdr10=0;tdr10<9;tdr10++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr10]);data595(0xc0);chot();delay(100);}
    for(tdr11=0;tdr11<6;tdr11++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira3[tdr11]);chot();delay(100);}
    //dot 4
    for(tdr12=0;tdr12<9;tdr12++)
    {data595(trenduoira[tdr12]);data595(0x00);data595(0x01);data595(0xe0);chot();delay(100);}
    for(tdr13=0;tdr13<9;tdr13++)
    {data595(0x01);data595(trenduoira1[tdr13]);data595(0x01);data595(0xe0);chot();delay(100);}
    for(tdr14=0;tdr14<9;tdr14++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr14]);data595(0xe0);chot();delay(100);}
    for(tdr15=0;tdr15<5;tdr15++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira4[tdr15]);chot();delay(100);}
    //dot 5
    for(tdr16=0;tdr16<9;tdr16++)
    {data595(trenduoira[tdr16]);data595(0x00);data595(0x01);data595(0xf0);chot();delay(100);}
    for(tdr17=0;tdr17<9;tdr17++)
    {data595(0x01);data595(trenduoira1[tdr17]);data595(0x01);data595(0xf0);chot();delay(100);}
    for(tdr18=0;tdr18<9;tdr18++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr18]);data595(0xf0);chot();delay(100);}
    for(tdr19=0;tdr19<4;tdr19++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira5[tdr19]);chot();delay(100);}
    //dot 6
    for(tdr20=0;tdr20<9;tdr20++)
    {data595(trenduoira[tdr20]);data595(0x00);data595(0x01);data595(0xf8);chot();delay(100);}
    for(tdr21=0;tdr21<9;tdr21++)
    {data595(0x01);data595(trenduoira1[tdr21]);data595(0x01);data595(0xf8);chot();delay(100);}
    for(tdr22=0;tdr22<9;tdr22++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr22]);data595(0xf8);chot();delay(100);}
    for(tdr23=0;tdr23<3;tdr23++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira6[tdr23]);chot();delay(100);}
    //dot 7
    for(tdr24=0;tdr24<9;tdr24++)
    {data595(trenduoira[tdr24]);data595(0x00);data595(0x01);data595(0xfc);chot();delay(100);}
    for(tdr25=0;tdr25<9;tdr25++)
    {data595(0x01);data595(trenduoira1[tdr25]);data595(0x01);data595(0xfc);chot();delay(100);}
    for(tdr26=0;tdr26<9;tdr26++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr26]);data595(0xfc);chot();delay(100);}
    for(tdr27=0;tdr27<2;tdr27++)
    {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira7[tdr27]);chot();delay(100);}
    //dot 8
    for(tdr28=0;tdr28<9;tdr28++)
    {data595(trenduoira[tdr28]);data595(0x00);data595(0x01);data595(0xfe);chot();delay(100);}
    for(tdr29=0;tdr29<9;tdr29++)
    {data595(0x01);data595(trenduoira1[tdr29]);data595(0x01);data595(0xfe);chot();delay(100);}
    for(tdr30=0;tdr30<9;tdr30++)
    {data595(0x01);data595(0x00);data595(trenduoira[tdr30]);data595(0xfe);chot();delay(100);}
    {data595(0x01);data595(0x00);data595(0x01);data595(0xff);chot();delay(100);}
    }
    void chaytheocum()
    {
    for(s=0;s<4;s++)
    {data595(hieuung1[s+24]);data595(hieuung1[s]);data595(hieuung1[s]);data595(hieuung1[s]);chot();delay(100);}
    
    for(q=0;q<28;q++)
    {data595(hieuung1[q+28]);data595(hieuung1[q+20]);data595(hieuung1[q+12]);data595(hieuung1[q+4]);chot();delay(100);}
    
    }
    
    void traifull()
    {
    for(w=0;w<8;w++)
    {
    data595(hieuung[w]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
    }
    for(a=0;a<8;a++)
    {
    data595(hieuung[7]);data595(hieuung[a]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
    }
    for(b=0;b<8;b++)
    {
    data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[b]);data595(hieuung[8]);chot();delay(100);
    }
    for(c=0;c<8;c++)
    {
    data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[c]);chot();delay(100);
    }
    }
    void trai_ngat_quang()
    {
    for(d=0;d<8;d++)
    {
    data595(hieuung[d]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
    }
    for(e=0;e<8;e++)
    {
    data595(hieuung[e]);data595(hieuung[e]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
    }
    for(f=0;f<8;f++)
    {
    data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[8]);chot();delay(100);
    }
    for(g=0;g<8;g++)
    {
    data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);chot();delay(100);
    }
    for(aa=0;aa<4;aa++)
    {
    data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);chot();delay(200);
    }
    }
    void deu2benfull()
    {
    for(h=0;h<8;h++)
    {
    data595(hieuung[h]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[h+8]);chot();delay(100);
    }
    for(r=0;r<8;r++)
    {
    data595(hieuung[7]);data595(hieuung[r]);data595(hieuung[r+8]);data595(hieuung[7]);chot();delay(100);
    }
    data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
    }
    void sole()
    {
    for(solea=0;solea<29;solea++)
    {
    data595(chaysole[solea+8]);data595(chaysole[solea]);chot();delay(100);
    }
    for(sole1=36;sole1>7;sole1--)
    {
    data595(chaysole[sole1]);data595(chaysole[sole1-8]);chot();delay(100);
    }
    }
    void main()
    {
    SCK=1;
    SCL=1;
    while(1)
    {
    trenduoiraI();
    deu2benfull();
    trai_ngat_quang();
    chaytheocum();
    traifull();
    sole();
    for(jj=0;jj<10;jj++)
    {
    data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
    data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
    }}}

  • #2
    Cái biến kiểu integer của bạn lắm thế kia thì hỏi sao nó kô báo lỗi.
    , , ,

    Comment


    • #3
      Nguyên văn bởi phanbanhut Xem bài viết
      các bác giúp dùm em với, em đau đầu với cái vụ này quá ạ, em dùng Keil C viết chương trình cho thằng 89C52, khai báo mảng kiểu gì cũng bị "DATA SEGMENT TOO LARGE" hết đó, như là:
      const unsigned char ...[]={...};
      unsigned char code ...[]={...};
      ...
      chán quá các bác ơi, các bác xem và ráng giúp dùm em xíu nha, em nghi thằng Keil C bị sao sao đó, các bác thử copy vào chương trình của mình xem có bị lỗi như em không nha ráng giúp em nha mấy bác
      Code:
      #include <REGX52.H>
      #include <stdio.h>
      #define DATA P2_0
      #define SCK P2_1
      #define SCL P2_2
      int j,i,w,a,b,c,z,jj,d,e,bb,f,g,h,aa,r,t,u,q,s,v,solea,sole1;
      int tdr,tdr1,tdr2,tdr3,tdr4,tdr5,tdr6,tdr7,tdr8,tdr9,tdr10,tdr11,tdr12,tdr13,tdr14,tdr15,tdr16,tdr17,tdr18,tdr19,tdr20,tdr21,tdr22,tdr23,tdr24,tdr25,tdr26,tdr27,tdr28,tdr29,tdr30,tdr31,tdr32,tdr33,tdr34,tdr35,tdr36,tdr37,tdr38,tdr39,tdr40,tdr41;
      void delay(unsigned int ms)
      {unsigned int n;
      for(n=0;n<ms;n++){for(bb=0;bb<125;bb++){;}}
      }
      void dich()
      {
      SCK=0;
      SCK=1;
      }
      void chot()
      {
      SCL=0;
      SCL=1;
      }
      void data595(unsigned char k)
      {
      unsigned char temp,y;
      for(y=0;y<8;y++)
      {
      temp=k;
      temp=temp&0x80;
      if(temp==0x80)
      DATA=1;
      else 
      DATA=0;
      dich();
      k*=2;
      }
      }
      const unsigned char hieuung[17]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0x00,0x80,0xC0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
      const unsigned char hieuung1[64]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f};
      const unsigned char chaysole[37]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x05,0x0a,0x15,0x2a,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x54,0xa8,0x50,0xa0,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
      const unsigned char ngatquangnho[4]={0x11,0x33,0x77,0xff};
      const unsigned char trenduoira[9]={0x01,0x03,0x05,0x09,0x11,0x21,0x41,0x81,0x01};
      const unsigned char trenduoira1[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
      const unsigned char trenduoira2[7]={0x81,0x82,0x84,0x88,0x90,0xa0,0xc0};
      const unsigned char trenduoira3[6]={0xc1,0xc2,0xc4,0xc8,0xd0,0xe0};
      const unsigned char trenduoira4[5]={0xe1,0xe2,0xe4,0xe8,0xf0};
      const unsigned char trenduoira5[4]={0xf1,0xf2,0xf4,0xf8};
      const unsigned char trenduoira6[3]={0xf9,0xfa,0xfc};
      const unsigned char trenduoira7[2]={0xfd,0xfe};
      void trenduoiraI()
      {
      //dot 1
      for(tdr=0;tdr<9;tdr++)
      {data595(trenduoira[tdr]);data595(0x00);data595(0x01);data595(0x00);chot();delay(100);}
      for(tdr1;tdr1<9;tdr1++)
      {data595(0x01);data595(trenduoira1[tdr1]);data595(0x01);data595(0x00);chot();delay(100);}
      for(tdr2=0;tdr2<9;tdr2++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr2]);data595(0x00);chot();delay(100);}
      for(tdr3=0;tdr3<8;tdr3++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira1[tdr3]);chot();delay(100);}
      //dot 2
      for(tdr4=0;tdr4<9;tdr4++)
      {data595(trenduoira[tdr4]);data595(0x00);data595(0x01);data595(0x80);chot();delay(100);}
      for(tdr5=0;tdr5<9;tdr5++)
      {data595(0x01);data595(trenduoira1[tdr5]);data595(0x01);data595(0x80);chot();delay(100);}
      for(tdr6=0;tdr6<9;tdr6++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr6]);data595(0x80);chot();delay(100);}
      for(tdr7=0;tdr7<7;tdr7++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira2[tdr7]);chot();delay(100);}
      //dot 3
      for(tdr8=0;tdr8<9;tdr8++)
      {data595(trenduoira[tdr8]);data595(0x00);data595(0x01);data595(0xc0);chot();delay(100);}
      for(tdr9=0;tdr9<9;tdr9++)
      {data595(0x01);data595(trenduoira1[tdr9]);data595(0x01);data595(0xc0);chot();delay(100);}
      for(tdr10=0;tdr10<9;tdr10++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr10]);data595(0xc0);chot();delay(100);}
      for(tdr11=0;tdr11<6;tdr11++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira3[tdr11]);chot();delay(100);}
      //dot 4
      for(tdr12=0;tdr12<9;tdr12++)
      {data595(trenduoira[tdr12]);data595(0x00);data595(0x01);data595(0xe0);chot();delay(100);}
      for(tdr13=0;tdr13<9;tdr13++)
      {data595(0x01);data595(trenduoira1[tdr13]);data595(0x01);data595(0xe0);chot();delay(100);}
      for(tdr14=0;tdr14<9;tdr14++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr14]);data595(0xe0);chot();delay(100);}
      for(tdr15=0;tdr15<5;tdr15++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira4[tdr15]);chot();delay(100);}
      //dot 5
      for(tdr16=0;tdr16<9;tdr16++)
      {data595(trenduoira[tdr16]);data595(0x00);data595(0x01);data595(0xf0);chot();delay(100);}
      for(tdr17=0;tdr17<9;tdr17++)
      {data595(0x01);data595(trenduoira1[tdr17]);data595(0x01);data595(0xf0);chot();delay(100);}
      for(tdr18=0;tdr18<9;tdr18++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr18]);data595(0xf0);chot();delay(100);}
      for(tdr19=0;tdr19<4;tdr19++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira5[tdr19]);chot();delay(100);}
      //dot 6
      for(tdr20=0;tdr20<9;tdr20++)
      {data595(trenduoira[tdr20]);data595(0x00);data595(0x01);data595(0xf8);chot();delay(100);}
      for(tdr21=0;tdr21<9;tdr21++)
      {data595(0x01);data595(trenduoira1[tdr21]);data595(0x01);data595(0xf8);chot();delay(100);}
      for(tdr22=0;tdr22<9;tdr22++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr22]);data595(0xf8);chot();delay(100);}
      for(tdr23=0;tdr23<3;tdr23++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira6[tdr23]);chot();delay(100);}
      //dot 7
      for(tdr24=0;tdr24<9;tdr24++)
      {data595(trenduoira[tdr24]);data595(0x00);data595(0x01);data595(0xfc);chot();delay(100);}
      for(tdr25=0;tdr25<9;tdr25++)
      {data595(0x01);data595(trenduoira1[tdr25]);data595(0x01);data595(0xfc);chot();delay(100);}
      for(tdr26=0;tdr26<9;tdr26++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr26]);data595(0xfc);chot();delay(100);}
      for(tdr27=0;tdr27<2;tdr27++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira7[tdr27]);chot();delay(100);}
      //dot 8
      for(tdr28=0;tdr28<9;tdr28++)
      {data595(trenduoira[tdr28]);data595(0x00);data595(0x01);data595(0xfe);chot();delay(100);}
      for(tdr29=0;tdr29<9;tdr29++)
      {data595(0x01);data595(trenduoira1[tdr29]);data595(0x01);data595(0xfe);chot();delay(100);}
      for(tdr30=0;tdr30<9;tdr30++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr30]);data595(0xfe);chot();delay(100);}
      {data595(0x01);data595(0x00);data595(0x01);data595(0xff);chot();delay(100);}
      }
      void chaytheocum()
      {
      for(s=0;s<4;s++)
      {data595(hieuung1[s+24]);data595(hieuung1[s]);data595(hieuung1[s]);data595(hieuung1[s]);chot();delay(100);}
      
      for(q=0;q<28;q++)
      {data595(hieuung1[q+28]);data595(hieuung1[q+20]);data595(hieuung1[q+12]);data595(hieuung1[q+4]);chot();delay(100);}
      
      }
      
      void traifull()
      {
      for(w=0;w<8;w++)
      {
      data595(hieuung[w]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(a=0;a<8;a++)
      {
      data595(hieuung[7]);data595(hieuung[a]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(b=0;b<8;b++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[b]);data595(hieuung[8]);chot();delay(100);
      }
      for(c=0;c<8;c++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[c]);chot();delay(100);
      }
      }
      void trai_ngat_quang()
      {
      for(d=0;d<8;d++)
      {
      data595(hieuung[d]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(e=0;e<8;e++)
      {
      data595(hieuung[e]);data595(hieuung[e]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(f=0;f<8;f++)
      {
      data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[8]);chot();delay(100);
      }
      for(g=0;g<8;g++)
      {
      data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);chot();delay(100);
      }
      for(aa=0;aa<4;aa++)
      {
      data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);chot();delay(200);
      }
      }
      void deu2benfull()
      {
      for(h=0;h<8;h++)
      {
      data595(hieuung[h]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[h+8]);chot();delay(100);
      }
      for(r=0;r<8;r++)
      {
      data595(hieuung[7]);data595(hieuung[r]);data595(hieuung[r+8]);data595(hieuung[7]);chot();delay(100);
      }
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
      }
      void sole()
      {
      for(solea=0;solea<29;solea++)
      {
      data595(chaysole[solea+8]);data595(chaysole[solea]);chot();delay(100);
      }
      for(sole1=36;sole1>7;sole1--)
      {
      data595(chaysole[sole1]);data595(chaysole[sole1-8]);chot();delay(100);
      }
      }
      void main()
      {
      SCK=1;
      SCL=1;
      while(1)
      {
      trenduoiraI();
      deu2benfull();
      trai_ngat_quang();
      chaytheocum();
      traifull();
      sole();
      for(jj=0;jj<10;jj++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
      data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }}}
      dịch thử xem sao:
      Code:
      #include <REGX52.H>
      #include <stdio.h>
      #define DATA P2_0
      #define SCK P2_1
      #define SCL P2_2
      unsigned char j,i,w,a,b,c,z,jj,d,e,bb,f,g,h,aa,r,t,u,q,s,v,solea,sole1;
      unsigned char tdr,tdr1,tdr2,tdr3,tdr4,tdr5,tdr6,tdr7,tdr8,tdr9,tdr10,tdr11,tdr12,tdr13,tdr14,tdr15,tdr16,tdr17,tdr18,tdr19,tdr20,tdr21,tdr22,tdr23,tdr24,tdr25,tdr26,tdr27,tdr28,tdr29,tdr30,tdr31,tdr32,tdr33,tdr34,tdr35,tdr36,tdr37,tdr38,tdr39,tdr40,tdr41;
      void delay(unsigned int ms)
      {unsigned int n;
      for(n=0;n<ms;n++){for(bb=0;bb<125;bb++){;}}
      }
      void dich()
      {
      SCK=0;
      SCK=1;
      }
      void chot()
      {
      SCL=0;
      SCL=1;
      }
      void data595(unsigned char k)
      {
      unsigned char temp,y;
      for(y=0;y<8;y++)
      {
      temp=k;
      temp=temp&0x80;
      if(temp==0x80)
      DATA=1;
      else 
      DATA=0;
      dich();
      k*=2;
      }
      }
      code unsigned char hieuung[17]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0x00,0x80,0xC0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
      code unsigned char hieuung1[64]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f};
      code unsigned char chaysole[37]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x05,0x0a,0x15,0x2a,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x54,0xa8,0x50,0xa0,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
      code unsigned char ngatquangnho[4]={0x11,0x33,0x77,0xff};
      code unsigned char trenduoira[9]={0x01,0x03,0x05,0x09,0x11,0x21,0x41,0x81,0x01};
      code unsigned char trenduoira1[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
      code unsigned char trenduoira2[7]={0x81,0x82,0x84,0x88,0x90,0xa0,0xc0};
      code unsigned char trenduoira3[6]={0xc1,0xc2,0xc4,0xc8,0xd0,0xe0};
      code unsigned char trenduoira4[5]={0xe1,0xe2,0xe4,0xe8,0xf0};
      code unsigned char trenduoira5[4]={0xf1,0xf2,0xf4,0xf8};
      code unsigned char trenduoira6[3]={0xf9,0xfa,0xfc};
      code unsigned char trenduoira7[2]={0xfd,0xfe};
      void trenduoiraI()
      {
      //dot 1
      for(tdr=0;tdr<9;tdr++)
      {data595(trenduoira[tdr]);data595(0x00);data595(0x01);data595(0x00);chot();delay(100);}
      for(tdr1;tdr1<9;tdr1++)
      {data595(0x01);data595(trenduoira1[tdr1]);data595(0x01);data595(0x00);chot();delay(100);}
      for(tdr2=0;tdr2<9;tdr2++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr2]);data595(0x00);chot();delay(100);}
      for(tdr3=0;tdr3<8;tdr3++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira1[tdr3]);chot();delay(100);}
      //dot 2
      for(tdr4=0;tdr4<9;tdr4++)
      {data595(trenduoira[tdr4]);data595(0x00);data595(0x01);data595(0x80);chot();delay(100);}
      for(tdr5=0;tdr5<9;tdr5++)
      {data595(0x01);data595(trenduoira1[tdr5]);data595(0x01);data595(0x80);chot();delay(100);}
      for(tdr6=0;tdr6<9;tdr6++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr6]);data595(0x80);chot();delay(100);}
      for(tdr7=0;tdr7<7;tdr7++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira2[tdr7]);chot();delay(100);}
      //dot 3
      for(tdr8=0;tdr8<9;tdr8++)
      {data595(trenduoira[tdr8]);data595(0x00);data595(0x01);data595(0xc0);chot();delay(100);}
      for(tdr9=0;tdr9<9;tdr9++)
      {data595(0x01);data595(trenduoira1[tdr9]);data595(0x01);data595(0xc0);chot();delay(100);}
      for(tdr10=0;tdr10<9;tdr10++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr10]);data595(0xc0);chot();delay(100);}
      for(tdr11=0;tdr11<6;tdr11++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira3[tdr11]);chot();delay(100);}
      //dot 4
      for(tdr12=0;tdr12<9;tdr12++)
      {data595(trenduoira[tdr12]);data595(0x00);data595(0x01);data595(0xe0);chot();delay(100);}
      for(tdr13=0;tdr13<9;tdr13++)
      {data595(0x01);data595(trenduoira1[tdr13]);data595(0x01);data595(0xe0);chot();delay(100);}
      for(tdr14=0;tdr14<9;tdr14++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr14]);data595(0xe0);chot();delay(100);}
      for(tdr15=0;tdr15<5;tdr15++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira4[tdr15]);chot();delay(100);}
      //dot 5
      for(tdr16=0;tdr16<9;tdr16++)
      {data595(trenduoira[tdr16]);data595(0x00);data595(0x01);data595(0xf0);chot();delay(100);}
      for(tdr17=0;tdr17<9;tdr17++)
      {data595(0x01);data595(trenduoira1[tdr17]);data595(0x01);data595(0xf0);chot();delay(100);}
      for(tdr18=0;tdr18<9;tdr18++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr18]);data595(0xf0);chot();delay(100);}
      for(tdr19=0;tdr19<4;tdr19++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira5[tdr19]);chot();delay(100);}
      //dot 6
      for(tdr20=0;tdr20<9;tdr20++)
      {data595(trenduoira[tdr20]);data595(0x00);data595(0x01);data595(0xf8);chot();delay(100);}
      for(tdr21=0;tdr21<9;tdr21++)
      {data595(0x01);data595(trenduoira1[tdr21]);data595(0x01);data595(0xf8);chot();delay(100);}
      for(tdr22=0;tdr22<9;tdr22++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr22]);data595(0xf8);chot();delay(100);}
      for(tdr23=0;tdr23<3;tdr23++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira6[tdr23]);chot();delay(100);}
      //dot 7
      for(tdr24=0;tdr24<9;tdr24++)
      {data595(trenduoira[tdr24]);data595(0x00);data595(0x01);data595(0xfc);chot();delay(100);}
      for(tdr25=0;tdr25<9;tdr25++)
      {data595(0x01);data595(trenduoira1[tdr25]);data595(0x01);data595(0xfc);chot();delay(100);}
      for(tdr26=0;tdr26<9;tdr26++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr26]);data595(0xfc);chot();delay(100);}
      for(tdr27=0;tdr27<2;tdr27++)
      {data595(0x01);data595(0x00);data595(0x01);data595(trenduoira7[tdr27]);chot();delay(100);}
      //dot 8
      for(tdr28=0;tdr28<9;tdr28++)
      {data595(trenduoira[tdr28]);data595(0x00);data595(0x01);data595(0xfe);chot();delay(100);}
      for(tdr29=0;tdr29<9;tdr29++)
      {data595(0x01);data595(trenduoira1[tdr29]);data595(0x01);data595(0xfe);chot();delay(100);}
      for(tdr30=0;tdr30<9;tdr30++)
      {data595(0x01);data595(0x00);data595(trenduoira[tdr30]);data595(0xfe);chot();delay(100);}
      {data595(0x01);data595(0x00);data595(0x01);data595(0xff);chot();delay(100);}
      }
      void chaytheocum()
      {
      for(s=0;s<4;s++)
      {data595(hieuung1[s+24]);data595(hieuung1[s]);data595(hieuung1[s]);data595(hieuung1[s]);chot();delay(100);}
      
      for(q=0;q<28;q++)
      {data595(hieuung1[q+28]);data595(hieuung1[q+20]);data595(hieuung1[q+12]);data595(hieuung1[q+4]);chot();delay(100);}
      
      }
      
      void traifull()
      {
      for(w=0;w<8;w++)
      {
      data595(hieuung[w]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(a=0;a<8;a++)
      {
      data595(hieuung[7]);data595(hieuung[a]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(b=0;b<8;b++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[b]);data595(hieuung[8]);chot();delay(100);
      }
      for(c=0;c<8;c++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[c]);chot();delay(100);
      }
      }
      void trai_ngat_quang()
      {
      for(d=0;d<8;d++)
      {
      data595(hieuung[d]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(e=0;e<8;e++)
      {
      data595(hieuung[e]);data595(hieuung[e]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }
      for(f=0;f<8;f++)
      {
      data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[f]);data595(hieuung[8]);chot();delay(100);
      }
      for(g=0;g<8;g++)
      {
      data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);data595(hieuung[g]);chot();delay(100);
      }
      for(aa=0;aa<4;aa++)
      {
      data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);data595(ngatquangnho[aa]);chot();delay(200);
      }
      }
      void deu2benfull()
      {
      for(h=0;h<8;h++)
      {
      data595(hieuung[h]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[h+8]);chot();delay(100);
      }
      for(r=0;r<8;r++)
      {
      data595(hieuung[7]);data595(hieuung[r]);data595(hieuung[r+8]);data595(hieuung[7]);chot();delay(100);
      }
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
      }
      void sole()
      {
      for(solea=0;solea<29;solea++)
      {
      data595(chaysole[solea+8]);data595(chaysole[solea]);chot();delay(100);
      }
      for(sole1=36;sole1>7;sole1--)
      {
      data595(chaysole[sole1]);data595(chaysole[sole1-8]);chot();delay(100);
      }
      }
      void main()
      {
      SCK=1;
      SCL=1;
      while(1)
      {
      trenduoiraI();
      deu2benfull();
      trai_ngat_quang();
      chaytheocum();
      traifull();
      sole();
      for(jj=0;jj<10;jj++)
      {
      data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);data595(hieuung[7]);chot();delay(100);
      data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);data595(hieuung[8]);chot();delay(100);
      }}}
      |

      Comment


      • #4
        CŨng có thể Keil C của bạn chưa *****, mình cũng làm nhưng với mảng 2 chiều ! Máy báo tương tự như bạn , ***** xong thì hết !!

        Comment


        • #5
          HƠn nữa mình thấy bạn sử dụng quá nhiều biến đếm trong khi hoàn toàn ta có thể tận dụng lại ! Ví dụ như hai vòng for độc lập thì có thể xài một biến đếm i là quá đủ rồi !!

          Comment


          • #6
            Nguyên văn bởi AKA_QUAN Xem bài viết
            HƠn nữa mình thấy bạn sử dụng quá nhiều biến đếm trong khi hoàn toàn ta có thể tận dụng lại ! Ví dụ như hai vòng for độc lập thì có thể xài một biến đếm i là quá đủ rồi !!
            đa tạ bác

            Comment

            Về tác giả

            Collapse

            phanbanhut Tìm hiểu thêm về phanbanhut

            Bài viết mới nhất

            Collapse

            Đang tải...
            X