stc12c5a60s2双串口通讯,串口1已通,一下为串口2使用独立波特率

2019-07-15 16:15发布

能够发送,上电后,串口助手,能显示start,。,,,但是收发数据丢失求解
#include <stc12c5a60s2.h>
#include <intrins.h>
void GetString(unsigned char string[],unsigned char n);
unsigned char GetByte(void);
void Delay1000ms();
void Uartinit(void);
void SentString(unsigned char string[],unsigned char n);
unsigned char xdata string[20];
#define S2RI 0x01
#define S2TI 0x02
int main()
{
UartInit();
SentString("start.......A",20);
while(1)
{
  GetString(string,20);
  Delay1000ms();
  SentString(string,20);
}
}

void Delay1000ms()  [url=]//@11.0592MHz[/url]
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 43;
j = 6;
k = 203;
do
{
  do
  {
   while (--k);
  } while (--j);
} while (--i);
}

void UartInit(void)  
{
AUXR &= 0xF7;  
S2CON = 0x50;  
AUXR &= 0xFB;  
BRT = 0xFD;  
AUXR |= 0x10;
EA = 1;
IE2 = 0x01;
}
void SentString(unsigned char str[],unsigned char n)
{
unsigned char i = 0;
while(i < n)
{
  S2BUF = str;
  i++;
  while(!(S2CON & S2TI));
  if(str == 'A')  
  break;  
}
}
unsigned char GetByte(void)
{
unsigned char c;
while(!(S2CON & S2RI));
c = S2BUF;
return c;
}
void GetString(unsigned char str[],unsigned char n)
{
unsigned char i = 0;
while(i < n)
{
  str = GetByte();  
  if(str == 'A')
  {
   break;
  }
  i++;
}
}
void UART_2Interrupt(void) interrupt 8
{
if(S2CON & S2RI)
{
  S2CON &= ~S2RI;
}
if(S2CON & S2TI)
{
  S2CON &= ~S2TI;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。