Thông báo

Collapse
No announcement yet.

bài tập lớn mạng rs485 các bác giúp giùm với

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

  • bài tập lớn mạng rs485 các bác giúp giùm với

    em đang làm 1 mạng rs485 gồm 1 master và 2 slave ,master có giao tiếp máy tính. master và slave sử dụng 89c51, mỗi slave sẽ điều khiển 12 cảm biến hồng ngoại(em thay bằng nút bấm trong proteus. nhưng khi test nó chạy tùm lum hết mong các bác coi giúp em cái mạch xem đúng chưa ? với phần code em cũng xin post lên mong các bác chỉ giúp với

    đây là file proteus:http://www.mediafire.com/download/59...ong8051.pdsprj
    code master:
    #include <AT89x51.h>
    #include <string.h>

    void address(unsigned char a);
    void sendchuoi(unsigned char *a);
    void send(unsigned char a);
    unsigned char temp;

    void address(unsigned char a) ////gui dia chi////
    {
    P3_2=1;
    TB8=1;
    SBUF=a;
    while(TI==0){}
    TI=0;
    P3_2=0;
    }
    void send(unsigned char a) ////gui du lieu////
    {
    P3_2=1;
    TB8=0;
    SBUF=a;
    while(TI==0){}
    TI=0;
    P3_2=0;
    }
    void sendchuoi(unsigned char *a)
    {
    int i,n;
    n=strlen(a);
    for(i=0;i<n;i++)
    {
    send(a[i]);
    }
    }
    void nhan(void) interrupt 4 ////ngat nhan////
    {
    if(RI==1);
    {
    temp=SBUF;
    RI=0;
    }
    }

    void main(void)
    {
    TMOD=0x20; //timer1 che do 2
    TH1=0xFD; // toc do 9600
    SCON=0xD0; //che do 3 cho phep nhan
    TR1=1; //khoi dong Timer1
    IE=0x90; //cho phép ngat truyen thong
    P3_2=0;
    ////PC///// Dang Nhap////
    if(temp == 0)
    {address(1);
    send('a');}
    if(temp == 1)
    {address(1);
    send('b');}
    if(temp == 2)
    {address(1);
    send('c');}
    if(temp == 3)
    {address(1);
    send('d');}
    if(temp == 4)
    {address(1);
    send('e');}
    if(temp == 5)
    {address(1);
    send('f');}
    if(temp == 6)
    {address(1);
    send('g');}
    if(temp == 7)
    {address(1);
    send('h');}
    if(temp == 8)
    {address(1);
    send('i');}
    if(temp == 9)
    {address(1);
    send('j');}
    if(temp == 10)
    {address(1);
    send('k');}
    if(temp == 11)
    {address(1);
    send('l');}
    /////2//////
    if(temp == 12)
    {address(2);
    send('a');}
    if(temp == 13)
    {address(2);
    send('b');}
    if(temp == 14)
    {address(2);
    send('c');}
    if(temp == 15)
    {address(2);
    send('d');}
    if(temp == 16)
    {address(2);
    send('e');}
    if(temp == 17)
    {address(2);
    send('f');}
    if(temp == 18)
    {address(2);
    send('g');}
    if(temp == 19)
    {address(2);
    send('h');}
    if(temp == 20)
    {address(2);
    send('i');}
    if(temp == 21)
    {address(2);
    send('j');}
    if(temp == 22)
    {address(2);
    send('k');}
    if(temp == 23)
    {address(2);
    send('l');}

    ///PC///Dang Xuat////
    if(temp == 24)
    {address(1);
    send('m');}
    if(temp == 25)
    {address(1);
    send('n');}
    if(temp == 26)
    {address(1);
    send('o');}
    if(temp == 27)
    {address(1);
    send('p');}
    if(temp == 28)
    {address(1);
    send('q');}
    if(temp == 29)
    {address(1);
    send('r');}
    if(temp == 30)
    {address(1);
    send('s');}
    if(temp == 31)
    {address(1);
    send('t');}
    if(temp == 32)
    {address(1);
    send('u');}
    if(temp == 33)
    {address(1);
    send('v');}
    if(temp == 34)
    {address(1);
    send('w');}
    if(temp == 35)
    {address(1);
    send('x');}
    ////2////
    if(temp == 36)
    {address(2);
    send('m');}
    if(temp == 37)
    {address(2);
    send('n');}
    if(temp == 38)
    {address(2);
    send('o');}
    if(temp == 39)
    {address(2);
    send('p');}
    if(temp == 40)
    {address(2);
    send('q');}
    if(temp == 41)
    {address(2);
    send('r');}
    if(temp == 42)
    {address(2);
    send('s');}
    if(temp == 43)
    {address(2);
    send('t');}
    if(temp == 44)
    {address(2);
    send('u');}
    if(temp == 45)
    {address(2);
    send('v');}
    if(temp == 46)
    {address(2);
    send('w');}
    if(temp == 47)
    {address(2);
    send('x');}

    /////tin hieu tu slave 1/////
    if(temp == 48) ////tin hieu tu slave khi button bi bam
    {sendchuoi("phong 1 trai phep");}
    if(temp == 49)
    {sendchuoi("phong 2 trai phep");}
    if(temp == 50)
    {sendchuoi("phong 3 trai phep");}
    if(temp == 51)
    {sendchuoi("phong 4 trai phep");}
    if(temp == 52)
    {sendchuoi("phong 5 trai phep");}
    if(temp == 53)
    {sendchuoi("phong 6 trai phep");}
    if(temp == 54)
    {sendchuoi("phong 7 trai phep");}
    if(temp == 55)
    {sendchuoi("phong 8 trai phep");}
    if(temp == 56)
    {sendchuoi("phong 9 trai phep");}
    if(temp == 57)
    {sendchuoi("phong 10 trai phep");}
    if(temp == 58)
    {sendchuoi("phong 11 trai phep");}
    if(temp == 59)
    {sendchuoi("phong 12 trai phep");}

    /////tin hieu tu slave 2/////
    if(temp == 60)
    {sendchuoi("phong 13 trai phep");}
    if(temp == 61)
    {sendchuoi("phong 14 trai phep");}
    if(temp == 62)
    {sendchuoi("phong 15 trai phep");}
    if(temp == 63)
    {sendchuoi("phong 16 trai phep");}
    if(temp == 64)
    {sendchuoi("phong 17 trai phep");}
    if(temp == 65)
    {sendchuoi("phong 18 trai phep");}
    if(temp == 66)
    {sendchuoi("phong 19 trai phep");}
    if(temp == 67)
    {sendchuoi("phong 20 trai phep");}
    if(temp == 68)
    {sendchuoi("phong 21 trai phep");}
    if(temp == 69)
    {sendchuoi("phong 22 trai phep");}
    if(temp == 70)
    {sendchuoi("phong 23 trai phep");}
    if(temp == 71)
    {sendchuoi("phong 24 trai phep");}
    }
    Last edited by riseofdark; 13-08-2014, 01:07.

  • #2
    code slave 1 và 2 em chỉ thay địa chỉ thui
    code:
    #include <AT89x51.h>
    #include <string.h>

    void sendchuoi(unsigned char *a);
    void send(unsigned char a);
    unsigned char temp,ind;
    volatile unsigned char my_address=1;

    void send(unsigned char a) ////gui du lieu////
    {
    P3_2=1;
    TB8=0;
    SBUF=a;
    while(TI==0){}
    TI=0;
    P3_2=0;
    }

    void nhan(void) interrupt 4 ////ngat nhan////
    {
    if(RI==1);
    {
    temp=SBUF;
    RI=0;
    if (RB8==1)
    {
    if(my_address=temp)
    {
    SM2=0;
    }
    }
    else{ SM2=1;}
    }
    }

    void main(void)
    {
    TMOD=0x20; //timer1 che do 2
    TH1=0xFD; // toc do 9600
    SCON=0xF0; //che do 3 cho phep nhan,SM2=1
    TR1=1; //khoi dong Timer1
    IE=0x90; //cho phép ngat truyen thong
    P3_2=0;
    P1=0xAA;
    P2=0xAA;
    P0=0xAA;

    while(1)
    {
    if(P0_1 == 0)
    {
    while(!P0_1);
    send(48);} ///tin hieu tuong ung khi master nhan duoc se truyen 1 chuoi "phong 1 trai phep"
    if(P0_3 == 0)
    {
    while(!P0_3);
    send(49);}
    if(P0_5 == 0)
    {
    while(!P0_5);
    send(50);}
    if(P0_7 == 0)
    {
    while(!P0_7);
    send(51);}
    if(P1_1 == 0)
    {
    while(!P1_1);
    send(52);}
    if(P1_3 == 0)
    {
    while(!P1_3);
    send(53);}
    if(P1_5 == 0)
    {
    while(!P1_5);
    send(54);}
    if(P1_7 == 0)
    {
    while(!P1_7);
    send(55);}
    if(P2_1 == 0)
    {
    while(!P2_1);
    send(56);}
    if(P2_3 == 0)
    {
    while(!P2_3);
    send(57);}
    if(P2_5 == 0)
    {
    while(!P2_5);
    send(58);}
    if(P2_7 == 0)
    {
    while(!P2_7);
    send(59);}
    ///////NHAN//////
    if(temp=='a') ////tin hieu tu master de ngat button 1
    {P0_0=1;}
    if(temp=='b')
    {P0_2=1;}
    if(temp=='c')
    {P0_4=1;}
    if(temp=='d')
    {P0_6=1;}
    if(temp=='e')
    {P1_0=1;}
    if(temp=='f')
    {P1_2=1;}
    if(temp=='g')
    {P1_4=1;}
    if(temp=='h')
    {P1_6=1;}
    if(temp=='i')
    {P2_0=1;}
    if(temp=='j')
    {P2_2=1;}
    if(temp=='k')
    {P2_4=1;}
    if(temp=='l')
    {P2_6=1;}
    //////RESET//////
    if(temp=='m') /////tin hieu tu master de mo lai button 1
    {P0_0=0;}
    if(temp=='n')
    {P0_2=0;}
    if(temp=='o')
    {P0_4=0;}
    if(temp=='p')
    {P0_6=0;}
    if(temp=='q')
    {P1_0=0;}
    if(temp=='r')
    {P1_2=0;}
    if(temp=='s')
    {P1_4=0;}
    if(temp=='t')
    {P1_6=0;}
    if(temp=='u')
    {P2_0=0;}
    if(temp=='v')
    {P2_2=0;}
    if(temp=='w')
    {P2_4=0;}
    if(temp=='x')
    {P2_6=0;}
    }
    }

    Comment

    Về tác giả

    Collapse

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

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

    Collapse

    • bqviet
      Trả lời cho Đấu tắt điện cho máy tính bảng
      bởi bqviet
      Bqv cáo lỗi vì chưa đủ khả năng diễn giải để người đọc hiểu. Người làm kỹ thuật sâu đôi khi như thế đó. Về việc nạp pin không vào dù cell mới, khả năng cái mạch quản lý đó đã hỏng - cũng chính là nguyên nhân đám cell cũ hỏng từ đầu.
      06-12-2025, 17:17
    • nguyendinhvan
      Trả lời cho Xin hỏi về mạch thu FM/AM trong catsette
      bởi nguyendinhvan
      Theo tôi, nó chỉ là cái Tuy- ê - nơ, hoặc là khối Trung Văn Tần, nó một phần trong cái Da đì ô thôi. Vì có thấy một chỗ có ba chân hàn, giiống như chân Cờ rít sờ tăng 455 ki nô hẹc. Còn khối Tuy ê nơ thì không nhìn thây cái Di ốt Va di cáp...
      05-12-2025, 19:59
    • afrendly
      Trả lời cho Đấu tắt điện cho máy tính bảng
      bởi afrendly
      Có vẻ ngoài hiểu biết của mình rồi. Cuối cùng mình quyết định tìm mua 2 pin trên Shopee, giá 200K thay vào. Tuy nhận pin được 1%, sạc mãi không vào nhưng cũng mở được máy lên. Vậy cũng tạm. Cảm ơn bạn đã hỗ trợ nhé....
      04-12-2025, 01:27
    • nick22
      Trả lời cho Máy điện châm ?
      bởi nick22
      Đúng như bạn nói, máy điện châm hiện nay trên thị trường đã khá đa dạng về mẫu mã, chức năng và giá thành.
      01-12-2025, 13:23
    Đang tải...
    X