能够发送,上电后,串口助手,能显示start,。,,,但是收发数据丢失求解
#include <stc12c5a60s2.h>
#include <intrins.h>
void GetString(unsigned char string[],unsigned char n);
unsigned char GetByte(void);
void Delay1000ms();
void Uar
tinit(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;
}
}
一周热门 更多>