STC单片机的请进帮帮看看我这程序
#include<reg52.h>
#define uchar unsigned char
//***************串口程序****************************//
sfr AUXR = 0x8e;
sfr BRT = 0x9c;
#define RELOAD_COUNT 0xFD //11.0592MHz,12T,SMOD=0,9600bps
//uchar Sendword; //发送的字符
void Uart_initial()
{
SCON = 0x50; //0101,0000 方式1:8位可变波特率
//TMOD = 0x21; //0011,0001 设置顶时器1为8位自动重装计数器
//TH1 = RELOAD_COUNT; //设置定时器1自动重装数
//TL1 = RELOAD_COUNT;
//TR1 = 1; //开定时器1
BRT = RELOAD_COUNT;
AUXR = 0x10; //T0x12,T1x12,UART_M0x6,BRTR,S2SMOD,BRTx12,EXTRAM,S1BRS
//详见STC12XX PDF AUXR设置介绍P49页
// BRTR = 1, S1BRS = 1,
ES = 1; //允许串口中断
EA = 1; //开总中断
}
void Uart_send (unsigned char uSendData)
{
//EA = 0;
ES = 0; //关串口中断
TI = 0; //清零串口发送完成中断请求标志
//SBUF = Sendword; //发送值
SBUF = uSendData;
while(TI==0) //等待发送
{
;
}
TI = 0; //清零串口发送完成中断请求标志
ES = 1; //允许串口中断
//EA = 1;
}
//******************主函数********************
unsigned char uSendData;
main()
{
Uart_initial();
while(1)
{
uSendData = 0x11;
Uart_send(uSendData);
DelayTimeNms(500);
}
} |