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.
- Load into SPBRG register proper number depend on your baud rate and CPU clock frequency (check datasheet).
- Set BRGH bit in register TXSTA depend on desired baud rate generator (check datasheet).
- Set bits in RCSTA register depend on data length and so on (check datasheet). Enable CREN bit in RCSTA register.
- Wait on PIR1.RCIF == 1 bit which indicate that buffer receiver is full (only one byte).
精彩评论