unsigned char getin[10];
void UARTInterrupt(void) interrupt 4
{
char aa;
if(RI)
{
RI = 0;
aa=SBUF;
P1=aa;
}
else
TI = 0;
}
void inituart()
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void SendOneByte(unsigned char c)
{
SBUF = c;
while(TI);
TI = 0;
}
void main() //发送端
{
char getch;
inituart(); // ----------------------波特率9600-----------------
while(1)
{
getch=P1;
SendOneByte(getch);
}
}
//-----------------以上是发送端---------------------
//-----------------一下是接收端端------------------
#include
char ch;
void UARTInterrupt(void) interrupt 4
{
char aa;
if(RI)
{
RI = 0;
aa=SBUF;
P1=aa;
}
else
TI = 0;
}
void inituart()
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
} // ----------------------波特率9600-----------------
void SendOneByte(unsigned char c)
{
SBUF = c;
while(TI);
TI = 0;
}
void main() //发送端
{
inituart()
while(1)
{
ch=SBUF;
P1=ch;
}
}
看看这个:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/725053edc5cec62d27979143.html