Thông báo

Collapse
No announcement yet.

code mach trai tim loi

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

  • code mach trai tim loi

    Đây là đoạn code em tìm được, gửi lên đây mang mục đích vừa chia sẻ vừa tham khảo ý kiển: mạch sử dụng vdk 89c52 , điều khiển 32led. Tuy nhiên khi dịch sang file hex thì không được vì có một số lỗi, em thì còn ngu, nên bác nào cao thủ làm ơn sửa dùm em đoạn code. Em cảm ơn!
    #include<reg52.h>
    /*================================================= ==============*/

    /*=================== Khai bao bien toan cuc ====================*/
    sbit led1=P1^0;
    sbit led14=P3^5;
    sbit led15=P3^6;
    sbit led16=P3^7;
    sbit led17=P2^0;
    sbit led21=P2^4;
    sbit led22=P2^5;
    sbit led23=P2^6;
    sbit led27=P0^5;
    sbit led28=P0^4;
    sbit led29=P0^3;
    sbit led32=P0^0;
    unsigned int j,i,l,h,v,k;
    unsigned char Q[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; // ON 0-->7
    unsigned char U[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; // ON 7-->0
    unsigned char E[]={0xfc,0xf3,0xcf,0x3f}; // ON chay 2 port 0-->7
    unsigned char N[]={0x3f,0xcf,0xf3,0xfc}; // ON chay 2 port 7-->4
    unsigned char S[]={0xfe,0xfd,0xfa,0xf5,0xea,0xf5,0xaa,0x55}; // ON/OFF tien 0-->7
    unsigned char A[]={0x7f,0xbf,0x5f,0xaf,0x57,0xab,0x55,0xaa}; // ON/OFF tien 7-->0
    unsigned char M[]={0xfc,0xf3,0xcf,0x3f,0xfc,0xf3,0xcf,0x3f};
    unsigned char code na[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x7e,
    0xbe,0xde,0xee,0xf6,0xfa,0xfc,0x7c,0xbc,0xdc,0xec, 0xf4,0xf8,0x78,0xb8,
    0xd8,0xe8,0xf0,0x70,0xb0,0xd0,0xe0,0x60,0xa0,0xc0, 0x40,0x80,0x00};
    unsigned char O[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
    unsigned char W[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,
    0xbf,0x7f,0x7e,0x7d,0x7b,0x77,0x6f,0x5f,0x3f,0x3e,
    0x3d,0x3b,0x37,0x2f,0x1f,0x1e,0x1d,0x1b,0x17,0x0f,
    0x0e,0x0d,0x0b,0x07,0x06,0x05,0x03,0x02,0x01,0x00} ;
    unsigned char R[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
    unsigned char code ma[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
    /*================================================= ==============*/

    /*===================== Khai bao ham ============================*/
    void delay(long time){
    long n;
    for (n=0; n<time;n++) {
    } }
    /*================================================= ==============*/

    /*========================= Ham chinh ===========================*/
    void main (void){
    while (1){
    /*====== Trang thai 1 nhap nhay ======*/
    P0=P1=P2=P3=0x00;
    delay(40000);
    P0=P1=P2=P3=0xff;
    delay(2000);
    P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x000;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);

    //
    for(i=0;i<8;i++)
    {P1=U[i];
    P3=Q[i];
    delay(1000);
    }
    for(i=0;i<8;i++)
    {P0=P2=U[i];
    delay(1000);
    }

    for(i=0;i<8;i++)
    {P0=P2=255-U[i];
    delay(1000);
    }
    for(i=0;i<8;i++)
    {P1=255-U[i];
    P3=255-Q[i];
    delay(1000);
    }

    P0=P1=P2=P3=255;
    delay(1000);
    //
    // ON dan tu P),P2 den P1,P3
    for(i=0;i<8;i++)
    {P0=P2=U[i];
    delay(1000);}
    for(i=0;i<8;i++)
    {P3=U[i];
    P0=P2=255-U[i];
    P1=Q[i];
    delay(1000);}
    for(i=0;i<8;i++)
    {P3=255-U[i];
    P1=255-Q[i];
    delay(1000);}
    // chay ON dan
    for(l=0;l<37;l++){
    P1=P2=P3=W[l];
    P0=na[l];
    delay(1000);}

    for(l=0;l<37;l++){
    P1=P2=P3=255-W[l];
    P0=255-na[l];
    delay(1000);}

    //
    for(l=0;l<8;l++)
    {P1=P2=P3=U[l];
    P0=Q[l];
    delay(1000);}
    P0=P1=P2=P3=0x00;
    for(l=0;l<8;l++)
    {P1=P2=P3=255-U[l];
    P0=255-Q[l];
    delay(1000);}

    for(l=0;l<8;l++)
    {P1=P2=P3=Q[l];
    P0=U[l];
    delay(1000);}
    P0=P1=P2=P3=0x00;
    for(l=0;l<8;l++)
    {P1=P2=P3=255-Q[l];
    P0=255-U[l];
    delay(1000);}

    for(j=0;j<8;j++)
    {P0=P1=P2=Q[j];
    P3=U[j];
    delay(1000);}
    //


    for(l=0;l<8;l++){
    P1=P2=P3=255-Q[l];
    P0=255-U[l];
    delay(1000);}
    //chop tat
    for(k=0;k<8;k++)
    {P0=P1=P2=S[k];
    P3=A[k];
    delay(1000);}

    //chop tat tu P1-->P3-->P2-->P0
    P0=P1=P2=P3=0xff;
    P1=0xfe;
    delay(1000);
    P1=0xfd;
    delay(1000);
    P1=0xfa;
    delay(1000);
    P1=0xf5;
    delay(1000);
    P1=0xea;
    delay(1000);
    P1=0xd5;
    delay(1000);
    P1=0xaa;
    delay(1000);
    P1=0x55;
    delay(1000);
    P1=0xaa;
    P3=0xfe ;
    delay(1000);
    P1=0x55;
    P3=0xfd;
    delay(1000);
    P1=0xaa;
    P3=0xfa;
    delay(1000);
    P1=0x55;
    P3=0xf5 ;
    delay(1000);
    P1=0xaa;
    P3=0xea ;
    delay(1000);
    P1=0x55;
    P3=0xd5;
    delay(1000);
    P1=P3=0xaa;
    delay(1000);
    P1=P3=0x55;
    delay(1000);

    P1=P3=0xaa;
    P2=0xfe;
    delay(1000);
    P1=P3=0x55;
    P2=0xfd;
    delay(1000);
    P1=P3=0xaa;
    P2=0xfa;
    delay(1000);
    P1=P3=0x55;
    P2=0xf5;
    delay(1000);
    P1=P3=0xaa;
    P2=0xea;
    delay(1000);
    P1=P3=0x55;
    P2=0xd5;
    delay(1000);
    P1=P3=P2=0xaa;
    delay(1000);
    P1=P3=P2=0x55;
    delay(1000);
    P1=P2=P3=0xaa;
    P0=0x7f;
    delay(1000);
    P1=P2=P3=0x55;
    P0=0xbf;
    delay(1000);
    P1=P2=P3=0xaa;
    P0=0x5f;
    delay(1000);
    P1=P2=P3=0x55;
    P0=0xaf;
    delay(1000);
    P1=P2=P3=0xaa;
    P0=0x57;
    delay(1000);
    P1=P2=P3=0x55;
    P0=0xab;
    delay(1000);
    P0=P1=P3=P2=0x55;
    delay(1000);
    P0=P1=P2=P3=0xaa;
    delay(1000);

    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(5000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(6000);
    P0=P1=P2=P3=0xff;
    delay(1000);
    P0=P1=P2=P3=0x00;
    delay(7000);
    P0=P1=P2=P3=0xff;
    delay(3000);
    P0=P1=P2=P3=0x00;
    delay(8000);
    P0=P1=P2=P3=0xff;
    delay(3000);
    // chop tat // P0,P3 va P2,P1
    P0=0xfe;
    P3=0x7f;
    delay(3000);
    P0=0xfd;
    P3=0xbf;
    delay(3000);
    P0=0xfa;
    P3=0x5f;
    delay(3000);
    P0=0xf5;
    P3=0xaf;
    delay(3000);
    P0=0xea;
    P3=0x57;
    delay(3000);
    P0=0xd5;
    P3=0xab;
    delay(3000);
    P0=0xaa;
    P3=0x55;
    delay(3000);
    P0=0x55;
    P3=0xaa;
    delay(3000);
    P0=0xaa;
    P3=0x55;
    P1=P2=0x7f;
    delay(3000);
    P0=0x55;
    P3=0xaa;
    P1=P2=0xbf;
    delay(3000);
    P0=0xaa;
    P3=0x55;
    P1=P2=0x5f;
    delay(3000);
    P0=0x55;
    P3=0xaa;
    P1=P2=0xaf;
    delay(3000);
    P0=0xaa;
    P3=0x55;
    P1=P2=0x57;
    delay(3000);
    P0=0x55;
    P3=0xaa;
    P1=P2=0xab;
    delay(3000);
    P0=0xaa;
    P3=P1=P2=0x55;
    delay(3000);
    P0=0x55;
    P3=P1=P2=0xaa;
    delay(3000);
    // OFF dan tu P1,P3 den P0,P2
    for(h=0;h<8;h++)
    {P1=255-U[h];
    P3=255-Q[h];
    delay(2000);}
    for(l=0;l<8;l++)
    {P0=P2=255-Q[l];
    delay(2000);}
    //
    for(k=0;k<4;k++)
    {P1=P3=P2=E[k];
    P0=N[k];
    delay(2000);}


    for(k=0;k<4;k++)
    {P1=P3=P2=E[k];
    P0=N[k];
    delay(2000);}

    for(k=0;k<4;k++)
    {P1=P3=P2=E[k];
    P0=N[k];
    delay(2000);}

    for(l=0;l<4;l++)
    {P0=E[l];
    P3=P2=P1=N[l];
    delay(2000);}
    for(l=0;l<4;l++)
    {P0=E[l];
    P3=P2=P1=N[l];
    delay(2000);
    }for(l=0;l<4;l++)
    {P0=E[l];
    P3=P2=P1=N[l];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    for(i=0;i<8;i++){
    P1=P3=P2=U[i];
    P0=Q[i];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);

    for(i=0;i<8;i++){
    P1=P3=P2=Q[i];
    P0=U[i];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);

    for(h=0;h<8;h++){
    P1=U[h];
    P3=Q[h];
    delay(2000);}
    for(h=0;h<8;h++){
    P0=P2=Q[h];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);
    P0=P1=P2=P3=0xff;
    delay(1000);

    for(l=0;l<8;l++){
    P0=P2=U[l];
    delay(2000);}
    for(l=0;l<8;l++){
    P1=Q[l];
    P3=U[l];
    delay(2000);}

    P0=P1=P2=P3=0xff;
    delay(1000);
    /*=======*/
    P1=0xf8;
    delay(3000);
    P3=0xf8;
    delay(3000);
    led15=0;
    led16=0;
    led17=0;
    delay(3000);

    P2=0x8f;
    led21=led22=led23=led17=0;
    delay(3000);
    led27=led28=led29=0;
    delay(3000);

    P1=P2=P3=P0=0x00;
    delay(3000);
    P1=P2=P3=P0=0xff;
    delay(2000);
    P1=P2=P3=P0=0x00;
    delay(3000);
    P1=P2=P3=P0=0xff;
    delay(2000);
    P1=P2=P3=P0=0x00;
    delay(3000);
    P1=P2=P3=P0=0xff;
    delay(2000);
    P1=P2=P3=P0=0x00;
    delay(3000);
    P1=P2=P3=P0=0xff;
    delay(2000);


    for(j=0;j<8;j++){
    P0=P1=P2=P3=O[j];
    delay(2000); }
    for(j=0;j<8;j++){
    P0=P1=P2=P3=O[j];
    delay(2000); }
    for(j=0;j<8;j++){
    P0=P1=P2=P3=Q[j];
    delay(2000); }
    // nhap nhay
    P1=P3=P2=P0=0x00;
    delay(2000);
    P1=P3=P2=P0=0xff;
    delay(2000);
    P1=P3=P2=P0=0x00;
    delay(2000);
    P1=P3=P2=P0=0xff;
    delay(2000);
    P1=P3=P2=P0=0x00;
    delay(2000);
    P1=P3=P2=P0=0xff;
    delay(2000);
    P1=P3=P2=P0=0x00;
    delay(2000);
    P1=P3=P2=P0=0xff;
    delay(2000);

    P3=0x0f;
    P2=0xf0;
    led21=0;
    delay(2000);
    P3=P2=0x00;
    delay(2000);
    P1=P0=0x0f;
    delay(2000);
    P1=P0=0x00;
    delay(2000);
    P1=P2=P3=P0=0xff;
    delay(2000);

    P0=P1=P2=P3=0x00;
    delay(3000);
    P0=P1=P2=P3=0xff;
    delay(2000);
    P0=P1=P2=P3=0x000;
    delay(3000);
    P0=P1=P2=P3=0xff;
    delay(2000);


    P1=P0=0xf0;
    delay(4000);
    P1=P0=0x00;
    delay(4000);
    P3=0xf0;
    P2=0x0f;
    delay(4000);
    P1=P2=P3=P0=0x00;
    delay(4000);
    P1=P2=P3=P0=0xff;
    delay(2000);

    P3=0x0f;
    P2=0xf0;
    led21=0;
    delay(4000);
    P3=P2=0x00;
    delay(4000);
    P1=P0=0x0f;
    delay(4000);
    P1=P0=0x00;
    delay(4000);
    P1=P2=P3=P0=0xff;
    delay(2000);

    P1=P0=0xf0;
    delay(4000);
    P1=P0=0x00;
    delay(4000);
    P3=0xf0;
    P2=0x0f;
    delay(4000);
    P1=P2=P3=P0=0x00;
    delay(4000);
    P1=P2=P3=P0=0xff;
    delay(2000);

    P3=P1=0x00;
    led17=0;
    delay(4000);
    led17=1;
    P3=P1=0xff;
    delay(2000);
    P2=P0=0x00;
    led1=0;
    delay(2000);
    P2=P0=0xff;
    led1=1;
    delay(2000);
    /* sang duoi */
    for(j=0;j<8;j++){
    P1=Q[j];
    P0=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P2=Q[j];
    P3=U[j];
    delay(2000);}
    P1=P0=P2=P3=0xff;
    delay(1000);

    for(j=0;j<8;j++){
    P1=Q[j];
    P0=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    P2=U[j];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    delay(2000);
    for(j=0;j<8;j++){
    P2=Q[j];
    P3=U[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P0=U[j];
    P1=U[j];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);

    P0=P1=P2=P3=0x00;
    delay(3000);

    for(j=0;j<8;j++){
    P3=255-U[j];
    P2=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P1=255-U[j];
    P0=255-U[j];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(3000);
    P3=P2=P1=P0=0xff;
    delay(2000);

    for(h=0;h<8;h++){
    P1=Q[h];
    delay(2000);}
    for(h=0;h<8;h++){
    P3=Q[h];
    delay(2000);}
    led17=0;
    for(h=0;h<8;h++){
    P0=Q[h];
    delay(2000);}
    for(h=0;h<8;h++)
    {P2=U[h];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    delay(2000);

    // ON&OFF dan
    for(j=0;j<8;j++){
    P1=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P1=255-Q[j];
    P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=255-Q[j];
    P0=U[j];
    delay(2000);}

    for(j=0;j<8;j++){
    P1=Q[j];
    P2=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    P0=255-U[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P1=255-Q[j];
    P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=255-Q[j];
    P0=U[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P2=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P0=255-U[j];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    // On dan, OFF dan

    for(j=0;j<8;j++){
    P1=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P0=U[j];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(2000);
    for(j=0;j<8;j++){
    P1=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P2=255-Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P0=255-U[j];
    delay(2000);}

    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    P1=P3=P2=P0=0x00;
    delay(1000);
    P1=P2=P3=P0=0xff;
    delay(1000);
    /*=== Trang thai ===*/

    for(j=0;j<8;j++){
    P1=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P0=U[j];
    delay(2000);}

    P0=P1=P2=P3=0xff;

    for(j=0;j<8;j++){
    P1=P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    P0=U[j];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    led17=led1=0;
    delay(2000);
    for(j=0;j<8;j++){
    P3=U[j];
    P0=Q[j];
    delay(2000);}

    for(j=0;j<8;j++)
    {P1=P2=U[j];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    delay(1000);


    for(i=0;i<8;i++){
    P1=P3=P2=U[i];
    P0=Q[i];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);
    for(i=0;i<8;i++){
    P1=P3=P2=Q[i];
    P0=U[i];
    delay(2000);}
    P0=P1=P2=P3=0x00;
    delay(1000);
    for(i=0;i<8;i++){
    P1=O[i];
    P3=Q[i];
    P2=Q[i];
    delay(2000);}

    for(j=0;j<8;j++){
    P1=P2=Q[j];
    delay(2000);}
    for(j=0;j<8;j++){
    P3=Q[j];
    P0=U[j];
    delay(2000);}
    P0=P1=P2=P3=0xff;
    delay(3000);
    led17=led1=0;
    delay(2000);
    for(j=0;j<8;j++){
    P3=U[j];
    P0=Q[j];
    delay(2000);}

    P0=P1=P2=P3=0xff;
    for(j=0;j<8;j++){
    P1=P2=U[j];
    delay(2000);}

    P0=P1=P2=P3=0xff;
    delay(1000);
    }
    }
    /*=============================END================= =================*/

  • #2
    bài này là 1 trong những bài tiền đề của vdk, nó giống như dk 1 con led thôi, chỉ khác là xuất ra cả 32 chân, bạn đọc qua tài liệu là có thể tự test đc, chứ cái code này dài thế chả ai rỗi hơi đọc hết ngần ấy code đâu, ai cũng có việc cả, bạn chỉ nên nói thắc mắc chỗ cần thiết thôi
    Website chính thức đổi địa chỉ website thành
    Mời các bạn ghé thăm !!!

    Comment


    • #3
      file.hex của bạn đây: http://www.mediafire.com/file/y65erg...75/traitim.hex

      Comment


      • #4
        bacmats noi dung do.Bạn nên tự tìm hiểu.chổ nào không biết thì hỏi là tốt nhất

        Comment


        • #5
          Em cũng đã tìm hiểu và có đọc qua một số tài liệu viết code nhưng không có tài liệu nào viết cụ thể với lại sắp đến ngày cưới của chị, định làm tặng chị gái nhưng mà sợ không làm kịp nên phải hỏi. Hic ! cảm ơn các bác đã quan tâm

          Comment


          • #6
            up cái sơ đồ mạch nên cho a e tham khảo có phải k

            Comment


            • #7
              cái code dài dễ sợ. bạn nên hạn chế dùng mảng là tốt. dùng thuật toán đi.chứ cái code của bạn dài vậy ngồi ngắm đến lúc nào đây

              Comment

              Về tác giả

              Collapse

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

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

              Collapse

              Đang tải...
              X