#include <reg51.h>
#include <string.h>
unsigned char ch;
bit read_flag= 0 ;
void init_serialcom( void ) //串口通信初始设定
//向串口发送一个字符
void send_char_com( unsigned char ch)
//串口接收中断函数
void serial () interrupt 4 using 3
{
}
main()
if (read_flag) //如果取数标志已置位,就将读到的数从串口发出
例子2
// 单片机串行口发送/接收程序,每接收到字节即发送出去
// 和微机相接后键入的字符回显示在屏幕上
// 可用此程序测试
//
#include <reg51.h>
#define XTAL 11059200
#define baudrate 9600
void main(void)
{
unsigned char c;
TMOD = 0x20;
TH1=(unsigned char)(256 - (XTAL / (32L * 12L * baudrate)));
TL1=(unsigned char)(256 - (XTAL / (32L * 12L * baudrate)));
SCON = 0x50;
PCON = 0x00;
TR1 = 1;
IE = 0x00;
while(1)
{
while(RI == 0);
RI = 0;
c = SBUF;
SBUF = c;
while(TI == 0);
TI = 0;
}
}