我正在使用PIC32MX350F128L.uart1是(TX)的PIN 22和(RX)的引脚20。我能够发送一个字符,但不能接收任何字符。下面是代码。
请查看代码并提出一些更改建议?
void init_uart();
void UART1PutChar(unsigned char Ch);
char SerialReceive_1();
void main()
{
char res;
OSCCON=0x00002200; //ask settings clock
ANSELBbits.ANSB3 = 0;
ANSELBbits.ANSB5 = 0;
TRISCbits.TRISC3 = 0;
TRISCbits.TRISC4 = 0;
PORTCbits.RC3 = 1;
PORTCbits.RC4 = 1;
TRISBbits.TRISB3 = 0; //in controler tx
TRISBbits.TRISB5 = 1; // in controller RX
U1RXR=0x08;
RPB3R=0x03;
init_uart() ;
UART1PutChar('T');
while(1)
{
res = SerialReceive_1();
UART1PutChar(res);
}
}
void init_uart()
{
U1MODEbits.ON =1;
U1BRG = 25;
U1STA=0x1400;
IFS1bits.U1RXIF = 0;
IFS1bits.U1TXIF = 0 ;
return;
}
void UART1PutChar(unsigned char Ch)
{
while(U1STAbits.UTXBF == 1);
U1TXREG=Ch;
return ;
}
char SerialReceive_1()
{
char buf1;
while(!U1STAbits.URXDA);
buf1 = U1RXREG;
return buf1;
}
此致