PIC单片机串口不能连续收发

2025-04-27 00:58:52
推荐回答(2个)
回答1:

给你个例子,pic16f77 usart的驱动;
http://blog.ednchina.com/warden/236267/message.aspx
上面例子是用轮循方式做的,在很多地方有限制。

PIC的USART使用发送中断时要注意:Once the TXREG register transfers the data to the TSR register(occurs in one TCYCLE), the TXREG is empty and interrupt bit TXIF (PIR1<4>) is set。就是只要TXREG里没有数据就会置TXIF中断标志。

你可以这样实现:先把TX中断关了,把要发的数据放入一个定义好的TX_BUF[]中,然后再开TX中断,把TX_BUF发出,发完之后再关TX中断!

希望对你有点帮助。

if(RCIF==1)
{
v = RCREG;
rxstr[rx_count]=v;
PrintChar(rxstr[rx_count]);//PrintChar的原型是什么???
rx_count++;
if(rx_count >7)
testcomflag =1;
}
// RCIF=0; 去掉这两句,没必要+上去
// RCIE=1;

1。把最后两句去掉
2。你的PintChar原型是什么?

回答2:

我看我的博客。
我用的是51,你看看就明白了