开发者

Correct Way of using USART on PIC 16

I am trying to recieve 1 character using the USART feature on PIC 16.

Both the transmitter and receiver are both PIC 16s.

Can i check if the way to call the receive function is correct conceptually

char tmp;

CREN = 0;
CREN = 1;

while(!RCIF); 

if(OERR==1)
{
  tmp = RCREG;
  tmp = RCREG;
  CREN=0;
  DelayMs(5);
  CREN=1;
}
else
{
 tmp = RCREG;
}

CR开发者_C百科EN = 0;

Many thanks in advance!


You must first initiate the UART.

  1. Load into SPBRG register proper number depend on your baud rate and CPU clock frequency (check datasheet).
  2. Set BRGH bit in register TXSTA depend on desired baud rate generator (check datasheet).
  3. Set bits in RCSTA register depend on data length and so on (check datasheet). Enable CREN bit in RCSTA register.
  4. Wait on PIR1.RCIF == 1 bit which indicate that buffer receiver is full (only one byte).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜