发表于:2006/11/24 17:38:00
#0楼
为什么上位机和下位机的小灯都没有亮?
上位机程序:
[code]
#include <reg52.h>
#include <string.h>
#define uchar unsigned char
#define _RDY_ 0x06
#define _OK_ 0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
TMOD = 0x20;
TH1 = 250;
TL1 = 250;
TR1 = 1;
PCON = 0x80;
SCON = 0x50;
}
void main (void)
{
uchar LED;
initSerial();
EA = 0;
M_DE = 1; //置发送允许,接收禁止
M_RE = 1;
TI = 0;
SBUF = _RDY_;
while(!TI)
TI = 0;
while(tmp != _OK_)
{
RI = 0;
while(!RI);
tmp = SBUF;
RI = 0;
}
while(1)
{
LED = 0xfe;
P0 = LED;
}
}
[/code]
下位机程序:
[code]
#include <reg52.h>
#include <string.h>
#define uchar unsigned char
#define _RDY_ 0x06
#define _OK_ 0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
TMOD = 0x20;
TH1 = 250;
TL1 = 250;
TR1 = 1;
PCON = 0x80;
SCON = 0x50;
}
void main (void)
{
uchar LED;
initSerial();
EA = 0;
M_DE = 0; //置接收允许,发送禁止
M_RE = 0;
while(1)
{
while(tmp != _RDY_)
{
RI = 0;
while(!RI);
tmp = SBUF;
RI = 0;
}
TI = 0;
SBUF = _OK_;
while(!TI);
TI = 0;
while(1)
{
LED = 0xfe;
P0 = LED;
}
}
}
[/code]
上位机程序:
[code]
#include <reg52.h>
#include <string.h>
#define uchar unsigned char
#define _RDY_ 0x06
#define _OK_ 0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
TMOD = 0x20;
TH1 = 250;
TL1 = 250;
TR1 = 1;
PCON = 0x80;
SCON = 0x50;
}
void main (void)
{
uchar LED;
initSerial();
EA = 0;
M_DE = 1; //置发送允许,接收禁止
M_RE = 1;
TI = 0;
SBUF = _RDY_;
while(!TI)
TI = 0;
while(tmp != _OK_)
{
RI = 0;
while(!RI);
tmp = SBUF;
RI = 0;
}
while(1)
{
LED = 0xfe;
P0 = LED;
}
}
[/code]
下位机程序:
[code]
#include <reg52.h>
#include <string.h>
#define uchar unsigned char
#define _RDY_ 0x06
#define _OK_ 0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
TMOD = 0x20;
TH1 = 250;
TL1 = 250;
TR1 = 1;
PCON = 0x80;
SCON = 0x50;
}
void main (void)
{
uchar LED;
initSerial();
EA = 0;
M_DE = 0; //置接收允许,发送禁止
M_RE = 0;
while(1)
{
while(tmp != _RDY_)
{
RI = 0;
while(!RI);
tmp = SBUF;
RI = 0;
}
TI = 0;
SBUF = _OK_;
while(!TI);
TI = 0;
while(1)
{
LED = 0xfe;
P0 = LED;
}
}
}
[/code]