Vizier87
Active Member
Hello guys,
I've been using PIC18F4550 which is connected to a PC via RS232 with a USART 8-bit configuration. For transmission of 8-bit data with a baud rate of 2400 bps is good, but I've been having problems in receiving data from a PC because the programming keep polling the RCIF where when data is received, RCIF=1, but the problem is that RCIF never gets to be 1.
Here is the code:
Sometimes the data received is not accurate.
Please give some advice.
Thanks.
I've been using PIC18F4550 which is connected to a PC via RS232 with a USART 8-bit configuration. For transmission of 8-bit data with a baud rate of 2400 bps is good, but I've been having problems in receiving data from a PC because the programming keep polling the RCIF where when data is received, RCIF=1, but the problem is that RCIF never gets to be 1.
Here is the code:
Code:
Main:
setf count
clrf TRISB
movlw b'10000000'
movwf TRISC
movlw 0x00
movwf TRISD
;initialize uart
movlw b'01001010'
movwf BAUDCON
movlw 0x22
movwf SPBRG
movlw 0x08
movwf SPBRGH
;2400 baudrate
bcf TXSTA , SYNC
bsf RCSTA , SPEN
bsf RCSTA , CREN
loop btfss PIR1 , RCIF
goto $-1
btfsc RCSTA , FERR
goto clearf
btfsc RCSTA , OERR
goto clearo
movf RCREG , W
movwf PORTB
;clrf PORTB
goto loop
clearf bcf RCSTA , CREN ; clear framming error
bsf PORTB , 7
goto loop
clearo bcf RCSTA , CREN ; clear overrun error
bsf PORTB , 6
goto loop
Sometimes the data received is not accurate.
Please give some advice.
Thanks.