#include "SM39R08A3.h"//"SM39R08A5.h"
#include "global.h"
#include "DrvConfig.h"
#include "intrins.h"
unsigned char RXBUF0=0;
unsigned char BUF=0;
bit read_flag=0,send_flag=0;
void InitUART(void)
{
CKCON = 0x00; //22.1184MHZ 1T时钟周期
  FCON=0x04; //定时器时钟频率 Fosc
AUX=0x00; // BRS = 0波特率产生器使用定时器1 TH1寄存器
TMOD=0x20;
S0CON=0x50; //8-bit UART
TH1=0xB8; //9600
TL1=TH1;
PCON=0x00; //波特率不加倍
EA=1; //开所有中断
ES=1; //开串口中断
TR1=1; //开启定时器1
TI=0;
}
void SendOneByte(unsigned char c)
{
send_flag=1;
SBUF = c;
while(send_flag)
{
// _nop_()
;
}
}
void WDT_LVC_Int()
{
TAKEY=0x55;
TAKEY=0xaa;
TAKEY=0x5a;
WDTC=0xf7;
LVC|=0x81;
IELVI=1;
}
void delay(void) //误差 -0.00904224537us
{
unsigned char a,b,c;
for(c=8;c>0;c--)
for(b=197;b>0;b--)
for(a=2;a>0;a--);
}
main()
{
WDT_LVC_Int();
InitUART();
while(1)
{
if(read_flag==1)
{
read_flag=0;
BUF=RXBUF0;
SendOneByte(BUF);
}
}
}
void UARTInterrupt(void) interrupt 4
{
if(RI==1)
{
RI = 0;
RXBUF0 = S0BUF;
delay();
read_flag=1;
}
else
{
TI = 0;
send_flag=0;
}
}
发送部分有什么问题??求解
|