Thông báo

Collapse
No announcement yet.

xin giúp đỡ Led matrix với máy tính

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

  • xin giúp đỡ Led matrix với máy tính

    Em làm mạch led matrix 8x32, điều khiển bằng máy tính nhưng không truyền được lên xuống,
    - Trên mô phỏng thì truyền và nhận được, dùng Hyper Teminal tạo cổng COM ảo COM1 kết nối với COM2, truyền qua chân 11, 12, 13, 14 cua Max232, test thử truyền bật tắt Led và truyền ký tự ,
    - Làm mạch thật thì tín hiệu truyền ra Rx và Tx vẫn có, nhưng không truyền được lên Hyper Teminal của máy tính, mạch kết nối mặc định là COM1, thạch anh sử dụng cho mạch thật và mô phỏng là 11.0592,

    (Các anh ai đã làm về nó giúp em với, lúc đầu em dùng thạch anh 12Mhz thì không có tín hiệu ra trên Tx và Rx , thay thành 11.0592 mới có , nhưng không lên được máy tính)
    code dùng Keil C ,
    ( Sơ đồ nguyên lý và mạch mô phỏng kèm theo bên dưới đây)
    Sơ đồ nguyên lý:
    File mô phỏng và code code_do an_chay OK.zip


    code như dưới đây:

    #include <REGX52.H>
    #include <string.h>
    #include <intrins.h>

    /* BANG MA FONT LED MATRIX (Max ASCII) */
    unsigned char code Ma_font[97][6]={
    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//SPACE 0
    0xFF,0xFF,0xA0,0xFF,0xFF,0xFF,//! 1
    0xFF,0xFF,0xF8,0xF4,0xFF,0xFF,//' 2
    0xEB,0x80,0xEB,0x80,0xEB,0xFF,//# 3
    0xDB,0xD5,0x80,0xD5,0xED,0xFF,//$ 4
    0xD8,0xEA,0x94,0xAB,0x8D,0xFF,//% 5
    0xC9,0xB6,0xA9,0xDF,0xAF,0xFF,//& 6
    0xFF,0xFF,0xF8,0xF4,0xFF,0xFF,//' 7
    0xFF,0xE3,0xDD,0xBE,0xFF,0xFF,//( 8
    0xFF,0xBE,0xDD,0xE3,0xFF,0xFF,//) 9
    0xD5,0xE3,0x80,0xE3,0xD5,0xFF,//* 10
    0xF7,0xF7,0xC1,0xF7,0xF7,0xFF,//+ 11
    0xFF,0xA7,0xC7,0xFF,0xFF,0xFF,//, 12
    0xF7,0xF7,0xF7,0xF7,0xF7,0xFF,//- 13
    0xFF,0x9F,0x9F,0xFF,0xFF,0xFF,//x 14
    0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,// / 15
    0xC1,0xAE,0xB6,0xBA,0xC1,0xFF,//0 16
    0xFF,0xBD,0x80,0xBF,0xFF,0xFF,//1 17
    0x8D,0xB6,0xB6,0xB6,0xB9,0xFF,//2 18
    0xDD,0xBE,0xB6,0xB6,0xC9,0xFF,//3 19
    0xE7,0xEB,0xED,0x80,0xEF,0xFF,//4 20
    0xD8,0xBA,0xBA,0xBA,0xC6,0xFF,//5 21
    0xC3,0xB5,0xB6,0xB6,0xCF,0xFF,//6 22
    0xFE,0x8E,0xF6,0xFA,0xFC,0xFF,//7 23
    0xC9,0xB6,0xB6,0xB6,0xC9,0xFF,//8 24
    0xF9,0xB6,0xB6,0xD6,0xE1,0xFF,//9 25
    0xFF,0xC9,0xC9,0xFF,0xFF,0xFF,//: 26
    0xFF,0xA4,0xC4,0xFF,0xFF,0xFF,//// 27
    0xF7,0xEB,0xDD,0xBE,0xFF,0xFF,//< 28
    0xEB,0xEB,0xEB,0xEB,0xEB,0xFF,//= 29
    0xFF,0xBE,0xDD,0xEB,0xF7,0xFF,//> 30
    0xFD,0xFE,0xAE,0xF6,0xF9,0xFF,//? 31
    0xCD,0xB6,0x8E,0xBE,0xC1,0xFF,//@ 32
    0x83,0xF5,0xF6,0xF5,0x83,0xFF,//A 33
    0xBE,0x80,0xB6,0xB6,0xC9,0xFF,//B 34
    0xC1,0xBE,0xBE,0xBE,0xDD,0xFF,//C 35
    0xBE,0x80,0xBE,0xBE,0xC1,0xFF,//D 36
    0x80,0xB6,0xB6,0xB6,0xBE,0xFF,//E 37
    0x80,0xF6,0xF6,0xFE,0xFE,0xFF,//F 38
    0xC1,0xBE,0xB6,0xB6,0xC5,0xFF,//G 39
    0x80,0xF7,0xF7,0xF7,0x80,0xFF,//H 40
    0xFF,0xBE,0x80,0xBE,0xFF,0xFF,//I 41
    0xDF,0xBF,0xBE,0xC0,0xFE,0xFF,//J 42
    0x80,0xF7,0xEB,0xDD,0xBE,0xFF,//K 43
    0x80,0xBF,0xBF,0xBF,0xFF,0xFF,//L 44
    0x80,0xFD,0xF3,0xFD,0x80,0xFF,//M 45
    0x80,0xFD,0xFB,0xF7,0x80,0xFF,//N 46
    0xC1,0xBE,0xBE,0xBE,0xC1,0xFF,//O 47
    0x80,0xF6,0xF6,0xF6,0xF9,0xFF,//P 48
    0xC1,0xBE,0xAE,0xDE,0xA1,0xFF,//Q 49
    0x80,0xF6,0xE6,0xD6,0xB9,0xFF,//R 50
    0xD9,0xB6,0xB6,0xB6,0xCD,0xFF,//S 51
    0xFE,0xFE,0x80,0xFE,0xFE,0xFF,//T 52
    0xC0,0xBF,0xBF,0xBF,0xC0,0xFF,//U 53
    0xE0,0xDF,0xBF,0xDF,0xE0,0xFF,//V 54
    0xC0,0xBF,0xCF,0xBF,0xC0,0xFF,//W 55
    0x9C,0xEB,0xF7,0xEB,0x9C,0xFF,//X 56
    0xFC,0xFB,0x87,0xFB,0xFC,0xFF,//Y 57
    0x9E,0xAE,0xB6,0xBA,0xBC,0xFF,//Z 58
    0xFF,0x80,0xBE,0xBE,0xFF,0xFF,//[ 59
    0xFD,0xFB,0xF7,0xEF,0xDF,0xFF,//\ 60
    0xFF,0xBE,0xBE,0x80,0xFF,0xFF,//] 61
    0xFB,0xFD,0xFE,0xFD,0xFB,0xFF,//^ 92
    0x7F,0x7F,0x7F,0x7F,0x7F,0xFF,//_ 63
    0xFF,0xFF,0xF8,0xF4,0xFF,0xFF,//' 64
    0xDF,0xAB,0xAB,0xAB,0xC7,0xFF,//a 65
    0x80,0xC7,0xBB,0xBB,0xC7,0xFF,//b 66
    0xFF,0xC7,0xBB,0xBB,0xBB,0xFF,//c 67
    0xC7,0xBB,0xBB,0xC7,0x80,0xFF,//d 68
    0xC7,0xAB,0xAB,0xAB,0xF7,0xFF,//e 69
    0xF7,0x81,0xF6,0xF6,0xFD,0xFF,//f 70
    0xF7,0xAB,0xAB,0xAB,0xC3,0xFF,//g 71
    0x80,0xF7,0xFB,0xFB,0x87,0xFF,//h 72
    0xFF,0xBB,0x82,0xBF,0xFF,0xFF,//i 73
    0xDF,0xBF,0xBB,0xC2,0xFF,0xFF,//j 74
    //0xFF,0x80,0xEF,0xD7,0xBB,0xFF,
    0x80,0xF3,0xED,0xDE,0xBF,0xFF, //k 75
    0xFF,0xBE,0x80,0xBF,0xFF,0xFF,//l 76
    0x83,0xFB,0x87,0xFB,0x87,0xFF,//m 77
    0x83,0xF7,0xFB,0xFB,0x87,0xFF,//n 78
    0xC7,0xBB,0xBB,0xBB,0xC7,0xFF,//o 79
    0x83,0xEB,0xEB,0xEB,0xF7,0xFF,//p 80
    0xF7,0xEB,0xEB,0xEB,0x83,0xFF,//q 81
    0x83,0xF7,0xFB,0xFB,0xF7,0xFF,//r 82
    0xB7,0xAB,0xAB,0xAB,0xDB,0xFF,//s 83
    0xFF,0xFB,0xC0,0xBB,0xBB,0xFF,//t 84
    0xC3,0xBF,0xBF,0xDF,0x83,0xFF,//u 85
    0xE3,0xDF,0xBF,0xDF,0xE3,0xFF,//v 86
    0xC3,0xBF,0xCF,0xBF,0xC3,0xFF,//w 87
    0xBB,0xD7,0xEF,0xD7,0xBB,0xFF,//x 88
    0xF3,0xAF,0xAF,0xAF,0xC3,0xFF,//y 89
    0xBB,0x9B,0xAB,0xB3,0xBB,0xFF,//z 90
    0xFB,0xE1,0xE0,0xE1,0xFB,0xFF,//^ 62
    0xE3,0xE3,0xC1,0xE3,0xF7,0xFF,//-> 93
    0xF7,0xE3,0xC1,0xE3,0xE3,0xFF,//<- 94
    0xEF,0xC3,0x83,0xC3,0xEF,0xFF,// 95
    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF//BLANK CHAR 96
    };
    char hang[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

    sbit DATA_Colum = P2^0; //595 quet cot
    sbit SCK_Colum = P2^1;
    sbit RCK_Colum = P2^2;

    sbit DATA_Row = P2^3; //595 quet du lieu
    sbit SCK_Row = P2^4;
    sbit RCK_Row = P2^5;

    unsigned char *String = "Nong Van Truong";
    unsigned int Tic=0,Pos=0;
    unsigned int Lengstr,Trans_busy;
    unsigned char Data_hang,Temp;

    #define Width 6

    Delay(unsigned int N)
    {
    int i,j;
    for(i=0;i<N;i++)
    for(j=0;j<50;j++);
    }

    void Convert_Row(unsigned char Data_out)
    {
    unsigned char i,Temp;
    for(i=0;i<8;i++)
    {
    Temp = Data_out&0x80;
    if(Temp==0x80)
    DATA_Row = 1;
    else
    DATA_Row = 0;
    Data_out<<=1;
    SCK_Row = 1;
    SCK_Row = 0;
    }
    RCK_Row=1;
    RCK_Row=0;
    }

    void Dich_hien_thi(){ // Dich chuoi ky tu sang trai
    Tic++; // toc do chay anh huong den nhieu khi hien thi ra led
    if(Tic==6)
    {
    Tic=0;
    Pos++;
    if(Pos>Lengstr)
    Pos=0;
    }
    }

    void Dich_trai()
    {
    int j;
    DATA_Colum=1;
    Lengstr=strlen(String)*6 ;
    for(j=Pos;j<32+Pos;j++)
    {
    Data_hang=Ma_font[String[(j%Lengstr)/Width]-32][j%Width];
    Convert_Row(Data_hang);
    SCK_Colum=1; SCK_Colum=0;
    RCK_Colum=1; RCK_Colum=0;
    DATA_Colum=0;
    Delay(2);
    }
    Dich_hien_thi();
    }

    void Dich_phai()
    {
    int j;
    Lengstr=strlen(String)*6 ;
    DATA_Colum=1;
    for(j=32+Pos;j>Pos;j--)
    {
    Data_hang=Ma_font[String[(j%Lengstr)/Width]-32][j%Width];
    Convert_Row(Data_hang);
    SCK_Colum=1; SCK_Colum=0;
    RCK_Colum=1; RCK_Colum=0;
    DATA_Colum=0;
    Delay(2);
    }
    Dich_hien_thi();
    }

    void Receive_PC(){
    while(RI==0);
    Temp=SBUF; // Luu du lieu va bien c
    RI=0; // Xoa co RI, ket thuc nhan
    }

    void Send_fedback(char a)// Gui phan hoi
    {
    SBUF=a;
    while(TI==0){};
    TI=0;
    }
    void Send_PC(char *a){ // Gui chuoi ky tu
    int i,n;
    Trans_busy=1;
    n=strlen(a);
    for(i=0;i<n;i++)
    {
    Send_fedback(a[i]);
    }
    Trans_busy=0;
    }

    void Nhapnhay(){ // Dieu khien led don tren cong P1
    int i,x=0xff;
    P1=~x;
    for(i=0;i<5;i++){
    Delay(200);
    P1=x;
    Delay(200);
    }
    }

    void Sangdan(){ // Ham dieu khien led don tren cong P1
    int i,n;
    for(n=0;n<5;n++){
    for(i=1;i<=255;i<<=1){
    P1=i;
    Delay(500);
    }
    }// end n
    }

    void DK_led(){
    switch(Temp){
    case'a':
    P1=0x3d;
    Send_PC("\n Ban vua gui ky tu:");
    Send_fedback(Temp);
    Send_fedback(10);

    break;

    case'b':
    Send_PC("\n Bat cong P0:");
    Send_fedback(Temp);
    Send_fedback(10);
    P0=0xff; Delay(200);
    P0=~P0; Delay(200);
    break;

    case 'z':
    Send_PC("\n Bat den nhay:");
    Nhapnhay();
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case'x':
    Send_PC("\n Bat den sang dan:");
    Sangdan();
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case '0':
    P1=0;
    Send_PC("\n Bat den so:");
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case '1':
    P1=1;
    Send_PC("\n Bat den so:");
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case '2':
    P1=2;
    Send_PC("\n Bat den so:");
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case '3':
    P1=4;
    Send_PC("\n Bat den so:");
    Send_fedback(Temp);
    Send_fedback(10);
    break;

    case '4': P1=8; Send_PC("\n Bat den so:"); Send_fedback(Temp);Send_fedback(10);break;
    case '5': P1=16; Send_PC("\n Bat den so:"); Send_fedback(Temp); Send_fedback(10);break;
    case '6': P1=32; Send_PC("\n Bat den so:"); Send_fedback(Temp);Send_fedback(10); break;
    case '7': P1=64; Send_PC("\n Bat den so:"); Send_fedback(Temp); Send_fedback(10);break;
    case '8': P1=128; Send_PC("\n Bat den so:"); Send_fedback(Temp);Send_fedback(10); break;
    case '9': P1=255; Send_PC("\n Bat tat ca cac den:"); Send_fedback(Temp);Send_fedback(10); break;
    case 's': P1=01010101; Send_PC("\n Bat den so:"); Send_fedback(Temp);Send_fedback(10); break;
    case 'd': P1=10101010; Send_PC("\n Bat den so:"); Send_fedback(Temp);Send_fedback(10); break;

    default : Send_PC(" Turn off led: "); P1=0;Send_fedback(Temp); Send_fedback(10); break;
    }
    }


    void main(){
    SCON=0x52; // Mode1, enable Receive
    TMOD=0x20; // Timer1, mode 2
    TH1=0xFD; // Baud=9600,// Toc do Baud 11,0592*10^6/64=
    TR1=1; // Start timer1
    while(1)
    {

    while(RI==0)
    {
    Dich_trai();
    Send_PC("\n Dang chay chu");
    Send_fedback(10);
    }

    Receive_PC();
    DK_led();
    RI=0;


    }
    }

    Mô phỏng Proteus:
    code_do an_chay OK.zip
    Sơ đồ nguyên ly và hình ảnh mô phỏng
    hinhanh2.zip
    Last edited by truongbg1991; 25-12-2013, 20:44.

Về tác giả

Collapse

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

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

Collapse

Đang tải...
X