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");}
}
đâ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");}
}
Comment