stc12c5a60s2双串口通讯,串口1已通,一下为串口2使用独立波特率
时间:10-02
整理:3721RD
点击:
能够发送,上电后,串口助手,能显示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("startA",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;
}
}
#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("startA",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;
}
}
有没有人啊,人人人人求解
顶起,高手在哪里,大声告诉我!
在线急等,2天了啊,为什么受到的数据不完整,发送没问题