Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F4550 USART problems.

Status
Not open for further replies.

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:

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.
 
Hi,

You are using a 18F chip, so $-1 does not work as it would on a 16F chip, as the 18F instructions are in 2 or 4 bytes, so you must use $-2.

Using a Goto avoids any such migration problems.
 
Looks like Wp100 found your problem. Just change goto $-1 to goto loop.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top