gnupic: PIC16F877 & USART


Previous by date: 28 Dec 2002 21:37:33 -0000 PIC16F877 & USART, Rick Mann
Next by date: 28 Dec 2002 21:37:33 -0000 Re: PIC16F877 & USART, Andreas Junge - DSLX
Previous in thread: 28 Dec 2002 21:37:33 -0000 PIC16F877 & USART, Rick Mann
Next in thread: 28 Dec 2002 21:37:33 -0000 Re: PIC16F877 & USART, Andreas Junge - DSLX

Subject: Re: PIC16F877 & USART
From: Edward Tiong ####@####.####
Date: 28 Dec 2002 21:37:33 -0000
Message-Id: <3E0E17A8.A7A152F0@shaw.ca>

Take a look at this code at
http://www.ee.ualberta.ca/~ee401/debug/debug877.asm  Actually, here is
the snipplet of code ...

; receives: nothing
; uses: W
; returns: nothing
;*******************************************************************
initializeUART		; Set up for hardware flow control

	banksel	BANK0		; Set to bank0
	bcf	PORTC,Tx_PIN	; Initial condition for the Tx line
	bcf	PORTC,Rx_PIN	; Initial condition for the Rx line
	bcf	PORTB,RTS_PIN	; Initial condition for the RTS line
	bsf	PORTB,CTS_PIN	; Initial condition for the CTS line

	banksel	BANK1		; Set to bank1
	bsf	TRISB,RTS_PIN	;  set RTS Pin to input 
	bcf	TRISB,CTS_PIN	;  set CTS Pin to output 
	bsf	TRISC,Tx_PIN	;  set Rx and Tx Pins to default as 
	bsf	TRISC,Rx_PIN	;  high impedance
	 
	bcf	PIE1,RCIE	; Disable uart interrupts
	bcf	PIE1,TXIE

				; Set baud Rate to one of the following
;	movlw	0xCF		; 300 baud 
;	movlw	0x67		; 2400 baud 
	movlw	0x19		; 9600 baud (see table in pic16f873.pdf)
;	movlw	0xC		; 19200 baud 
	movwf	SPBRG

	movlw	0x24		; Initialize Tx status and control register
	movwf	TXSTA

	banksel	BANK0		; Set to bank0
	movlw	0x90		; Initialize Rx status and control register
	movwf	RCSTA

	return

Or take a closer look at what the University of Alberta - Electrical and
Computer Engineering department is doing with the PIC16F873 and
PIC16F877. (http://www.ee.ualberta.ca/~ee041)  

Please keep in mind that the PIC code written on this site was done by
students for students.   

Hopefully this helps.


Rick Mann wrote:
> 
> Hi. I'm trying to get a PIC16F877 to work at 9600 baud. It works fine at
> 2400, with BRGH=0, but I can't seem to get reliable operation at 9600 with
> BRGH=1.
> 
> I thought I read somewhere that one shouldn't even try to use BRGH=1, but
> all of the examples I've seen on the Microchip website and Piclist.com seem
> to do it.
> 
> FWIW, it seemed to work better when the SPRG value was set to 26 instead of
> 25, the value everything says I should use.
> 
> I have a MAX232 from TI between the PIC and the PC. The handshaking lines
> are all hard-wired.
> 
> I try to send ascii '0' through '9' from my terminal program, and display
> those values on 8 LEDs. At 2400 baud, it works great. At 9600, I get
> incorrect (although consistently) values.
> 
> Any ideas? Thanks!
> 
> --
> Rick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####

Previous by date: 28 Dec 2002 21:37:33 -0000 PIC16F877 & USART, Rick Mann
Next by date: 28 Dec 2002 21:37:33 -0000 Re: PIC16F877 & USART, Andreas Junge - DSLX
Previous in thread: 28 Dec 2002 21:37:33 -0000 PIC16F877 & USART, Rick Mann
Next in thread: 28 Dec 2002 21:37:33 -0000 Re: PIC16F877 & USART, Andreas Junge - DSLX


Powered by ezmlm-browse 0.20.