stc12c5a60s2串口2使用独立波特率通讯
[复制链接]
#include
#include
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;
}
}
,串口调试,上电后,能够正常发出start。。。。,但是发送数据会丢失,求解