1. THÔNG BÁO TUYỂN ADMIN DIỄN ĐÀN 2013
    Tìm kiếm nhà trọ - Ở ghép
    THÔNG BÁO BÁN ÁO SPKT.NET CHO THÀNH VIÊN DIỄN ĐÀN


    HÃY TÌM KIẾM Ở ĐÂY TRƯỚC KHI ĐẶT CÂU HỎI
    {xen:phrase loading}

Giúp cái này với các pro ơi! Đồ án HTN

Thảo luận trong 'ĐỒ ÁN' bắt đầu bởi lamlt04, 5 Tháng năm 2012.

  1. lamlt04 New Member

    Số bài viết: 2
    Đã được thích: 0
    Điểm thành tích: 0
    Không biết sai chỗ nào giúp mình với nó chạy loạn xạ cả lên

    #include <mega8.h>
    #include <delay.h>
    #define data_row PORTD
    #define SER PORTC.0
    #define SCLK PORTC.1
    #define LCLK PORTC.2
    #define G PORTC.3
    //int i, t, n, j;
    unsigned char i,j,k,h,n;
    int t;
    unsigned char led_code[]=
    {
    /*------------------------------------------------------------------------------
    ; If font display distortion, please check Fonts format of setup.
    ; Source file / text : LED MA TRAN 8x32 XIN CHAO CAC BAN!!!
    ; Width x Height (pixels) :261X8
    ; Font Format/Size : Monochrome LCD Fonts ,Vertical scan , Little endian order/261Byte
    ; Font make date : 11/20/2010 10:48:45 AM
    ------------------------------------------------------------------------------*/
    0x05,0x08,0x21,//Width pixels,Height pixels,Width bytes
    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,0x00,0x00,0x00,0x00,0x00,0x00,0x81,
    0xFF,0x81,0x80,0x80,0xC0,0x00,0x81,0xFF,0x89,0x9D,0x81,0xC3,0x00,0x81,0xFF,0x81,
    0x81,0x81,0x42,0x3C,0x00,0x00,0x00,0x00,0x81,0xFF,0x87,0x38,0xC0,0x38,0x87,0xFF,
    0x81,0x00,0x80,0xE0,0xBC,0x23,0xBC,0xE0,0x80,0x00,0x00,0x00,0x00,0x03,0x01,0x81,
    0xFF,0x81,0x01,0x03,0x00,0x81,0xFF,0x89,0x19,0x69,0x86,0x80,0x80,0xE0,0xBC,0x23,
    0xBC,0xE0,0x80,0x00,0x81,0xFF,0x84,0x18,0x21,0xFF,0x01,0x00,0x00,0x00,0x00,0x66,
    0x99,0x89,0x99,0x66,0x00,0x88,0xD8,0x20,0xD8,0x88,0x00,0x82,0x81,0x89,0x89,0x76,
    0x00,0x82,0xC1,0xA1,0x91,0xCE,0x00,0x00,0x00,0x00,0x81,0xC3,0xA5,0x18,0xA5,0xC3,
    0x81,0x00,0x81,0xFF,0x81,0x00,0x81,0xFF,0x84,0x18,0x21,0xFF,0x01,0x00,0x00,0x00,
    0x00,0x3C,0x42,0x81,0x81,0x81,0x43,0x00,0x81,0xFF,0x89,0x08,0x89,0xFF,0x81,0x00,
    0x80,0xE0,0xBC,0x23,0xBC,0xE0,0x80,0x00,0x3C,0x42,0x81,0x81,0x81,0x42,0x3C,0x00,
    0x00,0x00,0x00,0x3C,0x42,0x81,0x81,0x81,0x43,0x00,0x80,0xE0,0xBC,0x23,0xBC,0xE0,
    0x80,0x00,0x3C,0x42,0x81,0x81,0x81,0x43,0x00,0x00,0x00,0x00,0x81,0xFF,0x89,0x89,
    0x89,0x76,0x00,0x80,0xE0,0xBC,0x23,0xBC,0xE0,0x80,0x00,0x81,0xFF,0x84,0x18,0x21,
    0xFF,0x01,0x00,0x00,0xBF,0x00,0x00,0x00,0xBF,0x00,0x00,0x00,0xBF,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00
    };

    unsigned char led_code_2[]=
    {
    /*------------------------------------------------------------------------------
    ; If font display distortion, please check Fonts format of setup.
    ; Source file / text :ÐHCT
    ; Width x Height (pixels) :64X8
    ; Font Format/Size : Monochrome LCD Fonts ,Vertical scan , Little endian order/32Byte
    ; Font make date : 11/20/2010 9:41:35 AM
    ------------------------------------------------------------------------------*/
    //0x20,0x08,0x04,//Width pixels,Height pixels,Width bytes

    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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x89,0xFF,0x89,0x89,0x81,0x42,0x3C,0x00,0x81,0xFF,0x89,0x08,0x89,0xFF,0x81,
    0x00,0x7E,0x81,0x81,0x81,0x81,0x62,0x00,0x03,0x01,0x81,0xFF,0x81,0x01,0x03,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    };




    void shift_left(void)
    {
    for(t=0;t<=261;t++)
    {
    for(n=0;n<20;n++)
    {
    for(i=0;i<=32;i++)
    {
    data_row=0x00;
    //delay_us(10);
    SCLK=0;
    if(i==0) {SER=0;}
    else {SER=1;}
    SCLK=1;
    LCLK=0;
    LCLK=1;
    data_row=~led_code[i+t];
    delay_us(100);
    };
    };

    };

    };





    void shift_right(void)
    {
    for(t=102;t>=0;t--)
    {
    for(n=0;n<30;n++)
    {
    for(i=0;i<=32;i++)
    {
    data_row=0x00;
    //delay_us(100); // chong lem
    SCLK =0;
    if(i==0) {SER=0;}
    else {SER=1;}
    SCLK=1;
    LCLK=0;
    LCLK=1;
    data_row=~led_code_2[i+t];
    delay_us(100); // thoi gian delay
    };
    };

    };

    };



    void chose(unsigned char i1,unsigned char x1)
    {
    unsigned char b,c ;
    b=led_code_2[i1];
    switch(x1)
    {
    case 1: c=b&0x80; // and de lay 1 bit cao dau
    for(j=0;j<=6;j++)
    {
    c=c>>1; // xoay 7 lan ve dau
    }
    data_row=0; //chong lem

    break;
    case 2: c=b&0xc0; // and de lay 2 bit cao dau
    for(j=0;j<=5;j++)
    {
    c=c>>1; // xoay 6 lan ve dau
    }
    data_row=0; //chong lem

    break;
    case 3: c=b&0xe0;
    for(j=0;j<=4;j++) // and de lay 3 bit cao dau
    {
    c=c>>1; // xoay 5 lan ve dau
    }
    data_row=0; //chong lem

    break;
    case 4: c=b&0xf0; // and de lay 4 bit cao dau
    for(j=0;j<=3;j++)
    { // xoay 4 lan ve dau
    c=c>>1;
    }
    data_row=0; //chong lem

    break;
    case 5: c=b&0xf8; // and de lay 5 bit trong ma chu
    for(j=0;j<=2;j++)
    {
    c=c>>1; // xoay 3 lan ve dau
    }
    data_row=0; //chong lem

    break;
    case 6: c=b&0xfc; // and de lay 6 bit trong ma chu
    for(j=0;j<=1;j++)
    {
    c=c>>1; // xoay 2 lan ve dau
    }
    data_row=0; //chong lem

    break;
    case 7: c=b&0xfe; // and de lay 7 bit trong ma chu

    c=c>>1; // xoay 1 lan ve dau
    data_row=0; //chong lem

    break;
    case 8: c=b&0xff; // and de lay 8 bit trong ma chu
    data_row=0; //chong lem

    break;
    case 9: c=b;
    c=c<<1;
    data_row=0; //chong lem

    break;
    case 10: c=b;
    for(j=0;j<=1;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 11: c=b;
    for(j=0;j<=2;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 12: c=b;
    for(j=0;j<=3;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 13: c=b;
    for(j=0;j<=4;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 14: c=b;
    for(j=0;j<=5;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 15: c=b;
    for(j=0;j<=6;j++)
    {
    c=c<<1;
    }
    data_row=0; //chong lem

    break;
    case 16: c=b;
    for(j=0;j<=7;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 17: c=b;
    for(j=0;j<=8;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    } // het switch
    SCLK=1;
    SCLK=0;
    LCLK=1;
    LCLK=0;


    data_row=~c;

    delay_us(50);

    SER=1;

    }



    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    //XXXXXXXXXXX CHAY TU DUOI LEN
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void chose1(unsigned char i1,unsigned char x1)
    {
    unsigned char b,c ;
    b=led_code_2[i1];
    switch(x1)
    {
    case 1: c=b&0x01;
    for(j=0;j<=6;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 2: c=b&0x03;
    for(j=0;j<=5;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 3: c=b&0x07;
    for(j=0;j<=4;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 4: c=b&0x0f;
    for(j=0;j<=3;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 5: c=b&0x1f;
    for(j=0;j<=2;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 6: c=b&0x3f;
    for(j=0;j<=1;j++)
    {
    c=c<<1;
    }
    data_row=0;

    break;
    case 7: c=b&0xef;

    c=c<<1;
    data_row=0;

    break;
    case 8: c=b&0xff;
    data_row=0; //chong lem

    break;
    case 9: c=b;
    c=c>>1;
    data_row=0;

    break;
    case 10: c=b;
    for(j=0;j<=1;j++)
    {
    c=c>>1;
    }
    data_row=0;

    break;
    case 11: c=b;
    for(j=0;j<=2;j++)
    {
    c=c>>1;
    }
    data_row=0;

    break;
    case 12: c=b;
    for(j=0;j<=3;j++)
    {
    c=c>>1;
    }
    data_row=0;

    break;
    case 13: c=b;
    for(j=0;j<=4;j++)
    {
    c=c>>1;
    }
    data_row=0;

    break;
    case 14: c=b;
    for(j=0;j<=5;j++)
    {
    c=c>>1;
    }
    data_row=0; //chong lem

    break;
    case 15: c=b;
    for(j=0;j<=6;j++)
    {
    c=c>>1;
    }
    data_row=0; //chong lem

    break;
    case 16: c=b;
    for(j=0;j<=7;j++)
    {
    c=c>>1;
    }
    data_row=0; //chong lem

    break;
    case 17: c=b;
    for(j=0;j<=8;j++)
    {
    c=c>>1;
    }
    data_row=0; //chong lem

    break;
    } // het switch

    SCLK=1;
    SCLK=0;

    LCLK=1;
    LCLK=0;
    data_row=~c;
    delay_us(50);
    SER=1;
    }






    void chay_xuong(void)
    {
    // xxxxxxxx chay tu tren xuong xxxxxxxxxxx
    h=1;

    for(h=1;h<=17;h++)
    {
    for(k=0;k<=30;k++) // for thoi gian sang
    {
    SER=0;
    for(i=32;i<=64;i++)
    {


    chose(i,h);

    } //het for(2) quet 32 cot

    } //het for(1) thoi gian sang

    } // het for(h=1;h<=17;h++)

    }


    void chay_len(void)
    {
    // xxxxxxxxxxxxx chay tu duoi len xxxxxxxxxxxxxx
    h=1;
    for(h=1;h<=17;h++)
    {
    for(k=0;k<=30;k++)
    {
    SER=0;
    for(i=32;i<=64;i++)
    {

    chose1(i,h);

    } //het for(2)

    } //het for(1)
    // h++ ; // TANG H LEN CHON CASE KE TIEP
    }
    }






    void main(void)
    {
    PORTC=0x00;
    DDRC=0x7F;
    PORTD=0x00;
    DDRD=0xFF;


    TCCR0=0x00;
    TCNT0=0x00;

    TCCR1A=0x00;
    TCCR1B=0x00;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;

    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;

    MCUCR=0x00;

    TIMSK=0x00;

    ACSR=0x80;
    SFIOR=0x00;






    while (1)
    {

    for(j=0;j<=32;j++){
    data_row=0x00;
    SER=0;
    SCLK=1;
    LCLK=1;
    SCLK=0;
    LCLK=0;
    };
    chay_len();
    chay_xuong();
    shift_left();

    shift_right();

    SER=0;
    SCLK=0;
    delay_us(50);

    }
    }

Chia sẻ trang này