试了串口2用不了。。。。。。。有大神能贴个程序吗!
void UartInit(void) //115200bps@11.0592MHz
{
AUXR &= 0xF7; //??????
S2CON = 0x50; //8???,?????
AUXR |= 0x04; //???????????Fosc,?1T
BRT = 0xFD; //?????????????
AUXR |= 0x10; //??????????
}
void UART_Put_Char(uchar txd)
{
S2BUF = txd;
while(!TI); //·¢ËͽáÊøʱ TI = 1; µÈ´ýTI = 0£»¿ªÊ¼·¢ËÍÊý¾Ý
TI=0;
}
void UART_Put_String(uchar* Pst,uint Length)
{
uint i;
for(i = 0; i < Length; i++)
{
S2BUF = Pst[i];
while(!TI); //·¢ËͽáÊøʱ TI = 1; µÈ´ýTI = 0£»¿ªÊ¼·¢ËÍÊý¾Ý
TI=0;
}
}
uchar UART_Get_char()
{
while(!RI); //S2RI = 1;½ÓÊÕ½áÊø
RI=0;
return(S2BUF);
}
void UART_Get_String(unsigned char *Pst,unsigned char Length)
{
unsigned char i;
for(i=0;i<Length;i++)
{
Pst[i] = UART_Get_char();
}
}
|