#include "Regx52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define MCLK 11059200L // MCLK frequency in Hz
#define BAUDRATE 19200 // Baud rate of UART in bps
unsigned char RevBuf; //接收缓存变量
/*-----------sfr init------------*/
void SerialInit(void)
{
EA = 0;
SCON = 0x50; // SCON0: mode 1, 8-bit UART, enable RX
PCON |= 0x80; // SMOD00 = 1
TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = -(MCLK/BAUDRATE/12/16); // set Timer1 reload value for baudrate
TL1 = -(MCLK/BAUDRATE/12/16); // set Timer1 reload value for baudrate
TR1 = 1; // start Timer1
// ES = 1; // enable UART0 interrupts
EA = 1;
}
/*
//Receive Char "串口中断方式接收数据"
//功能:接收到数据之后再发送出去
void UART_INTR_SVC(void) interrupt 4 using 3
{
if(RI==1)
{
RI=0;
RevBuf=SBUF;
SBUF=RevBuf;
}
else
TI=0;
}*/
void main(void)
{
uchar data m; //定义循环变量
SerialInit(); //初始化串口
for(m=0;m<8;m++)
{
SBUF = m+0x30;
while(TI!=1);
TI=0;//向PC发送ASCII:01234567
}
for(;;)
{
while(RI!=1);
RI=0;
RevBuf=SBUF;//查询方式接收数据
SBUF=RevBuf;//原数据返回
while(TI!=1);
TI=0;
}
}