PIC16F690用串口与电脑通信不上
答案:1 悬赏:20 手机版
解决时间 2021-02-14 10:59
- 提问者网友:聂風
- 2021-02-13 16:03
PIC16F690用串口与电脑通信不上
最佳答案
- 五星知识达人网友:迟山
- 2021-02-13 17:22
void Usart_Init(void)
{
TRISC5 = 1; //RX/RC5
TRISC4 = 1; //TX/RC4
TXSTA = 0x00;
RCSTA = 0x00;
BRG16 = 1;
SPBRGH = 0x03; //波特率9600/32MHz,误差0.04%
SPBRGL = 0x40;
TXSTA = 0x24;
RCSTA = 0xB0;
PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1;
}
void UartSendChar(uint8 _char)
{
TXREG = _char;
while(!TXSTAbits.TRMT);
}
void interrupt SysIsr(void)
{
static uint8 rxData;
//串口中断处理
if(PIR1bits.RCIF)
{
PIR1bits.RCIF = 0;
rxData = RCREG;
UartSendChar(rxData);
}
}
{
TRISC5 = 1; //RX/RC5
TRISC4 = 1; //TX/RC4
TXSTA = 0x00;
RCSTA = 0x00;
BRG16 = 1;
SPBRGH = 0x03; //波特率9600/32MHz,误差0.04%
SPBRGL = 0x40;
TXSTA = 0x24;
RCSTA = 0xB0;
PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1;
}
void UartSendChar(uint8 _char)
{
TXREG = _char;
while(!TXSTAbits.TRMT);
}
void interrupt SysIsr(void)
{
static uint8 rxData;
//串口中断处理
if(PIR1bits.RCIF)
{
PIR1bits.RCIF = 0;
rxData = RCREG;
UartSendChar(rxData);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯