Thông báo

Collapse
No announcement yet.

hỏi về code C cho 89c2051 + 74hc595 điều khiển led ma trận 8x8

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

  • hỏi về code C cho 89c2051 + 74hc595 điều khiển led ma trận 8x8

    mình nối chân P3_3 với chân 11 của 595,chân P3_4 với chân 14, chân P3_5 với chân 12, mình quét bằng 595,mức 1,port 1 của 2051 mức 0,vì port 1 khi ở mức 1 thì áp các chân ko đều,cụ thể P1_0,P1_1 chỉ ra có hơn 2V nên ko muốn dùng port 1 làm mức 1,mình có thử viết code port 1 quét mức 0 nhưng ko chạy theo ý muốn

    sau đây là code mình viết,chạy đúng ý được nửa sau


    #include<AT892051.h>

    sbit SCK = P3^3;
    sbit DATA = P3^4;
    sbit SCL = P3^5;

    /************************************************** ********/


    unsigned char n,m,i,j;
    unsigned char quet[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80
    };

    unsigned char code c1[]={


    0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,
    0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
    0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,
    0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
    0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,
    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
    0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
    0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
    0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
    0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
    0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
    0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
    0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
    0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
    0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
    0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
    0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,
    0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
    0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,
    0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
    0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
    0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
    0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


    void delay(unsigned int ms)
    {
    for(c=0;c<ms;c++)
    {
    for(d=0;d<113;d++);
    {
    }
    }
    }


    void quet1(unsigned char x)
    {
    unsigned char y;
    for(y=0;y<8;y++)
    {

    DATA=x&(0x80>>1);


    SCK=0;
    SCK=1;
    }
    SCL=0;
    SCL=1;
    }




    void a1()
    {

    for(i=0;i<=300;++i)
    {

    for(j=0;j<32;++j)
    {

    for(m=1;m<=50;++m)
    {

    for(n=0;n<8;++n)
    {

    quet1(quet[n]);
    P1 = c1[n+k];
    delay(1);
    P1=0xff;
    }

    }

    k=k+8;
    if(k==32*8) k=0;
    }

    }


    }

    /************************************************** ********/

    /************************************************** ************/


    void main()
    {

    while(1)
    {


    a1();


    }
    }

    mong được mọi người chỉ bảo, cảm ơn nhiều

Về tác giả

Collapse

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

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

Collapse

Đang tải...
X