PIC12LF1572串口问题
时间:10-02
整理:3721RD
点击:
求助PIC12LF1572串口问题这里是我的初始化:
void UART_init()
{
TRISA4=1; //1 = PORTA pin configured as an input (tri-stated)
TRISA5=0; //0 = PORTA pin configured as an output
ANSA4=0; //0 = Digital I/O; RA4 is assigned to port or digital special function
RXDTSEL=1; //1 = RX/DT function is on RA5
TXCKSEL=1; //1 = TX/CK function is on RA4
SPEN=1; //1 = Serial port is enabled
CREN=1; //1 = Enables receiver
TXEN=1; //1 = Transmit is enabled
BRG16=0;
SPBRG=12; //Baud Rate is 9600
GIE=1; //1 = Enables all active interrupts
PEIE=1; //1 = Enables all active peripheral interrupts
RCIE=1; //1 = Enables the USART receive interrupt
TXIE=0; //0 = Disables the USART transmit interrupt
RCIF=0; //0 = Interrupt is not pending
}
在中断中
void interrupt isr(void)
{
uint8_t receive;
if(RCIE&&RCIF)
{
receive=RCREG;
RCIF=0;
while(!TRMT);
uart_sent(receive);
}
}
发送:
void uart_sent(uint8_t ch)
{
TXREG=ch;
while(1)
{
if(TXIF==1) break; //?
}
}
问题是发送可以成功,我串口工具可以看到我发送的数据,但是接收不成功,请大神!
void UART_init()
{
TRISA4=1; //1 = PORTA pin configured as an input (tri-stated)
TRISA5=0; //0 = PORTA pin configured as an output
ANSA4=0; //0 = Digital I/O; RA4 is assigned to port or digital special function
RXDTSEL=1; //1 = RX/DT function is on RA5
TXCKSEL=1; //1 = TX/CK function is on RA4
SPEN=1; //1 = Serial port is enabled
CREN=1; //1 = Enables receiver
TXEN=1; //1 = Transmit is enabled
BRG16=0;
SPBRG=12; //Baud Rate is 9600
GIE=1; //1 = Enables all active interrupts
PEIE=1; //1 = Enables all active peripheral interrupts
RCIE=1; //1 = Enables the USART receive interrupt
TXIE=0; //0 = Disables the USART transmit interrupt
RCIF=0; //0 = Interrupt is not pending
}
在中断中
void interrupt isr(void)
{
uint8_t receive;
if(RCIE&&RCIF)
{
receive=RCREG;
RCIF=0;
while(!TRMT);
uart_sent(receive);
}
}
发送:
void uart_sent(uint8_t ch)
{
TXREG=ch;
while(1)
{
if(TXIF==1) break; //?
}
}
问题是发送可以成功,我串口工具可以看到我发送的数据,但是接收不成功,请大神!
已退回2积分