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.

Using hardware USART in PIC16F876A

Status
Not open for further replies.
Code:
	BSF STATUS,RP0
	MOVLW 0x06 ;All port A as digital
	MOVWF ADCON1
	MOVLW 0x00 ;All port A as output
	MOVWF TRISA
	MOVLW 0x25 ;SSPEN bit set, SPI Slave selected
	MOVWF SSPCON
	BCF TRISC,5 ;Setting PORTC in/out as required
	BSF TRISC,3
	BSF TRISC,4
	BCF STATUS,RP0
loop:	CALL cpy
	BTFSC 0x20,0
	COMF PORTA
	GOTO loop
cpy:	BSF STATUS,RP0
	MOVF SSPSTAT,0
	BCF STATUS,RP0
	MOVWF 0x20
	RETURN
	END

Well, that's my filthy, awful code. There's an LED on a PORTA pin, so I just COMF the whole register whenever the BF flag is set. The only point to this program is just to see if it'll work with a serial interface like a PC, it waits around for a single character to be sent, and the LED turns on. Not as easy as it sounds, hahah.
Anyone have some experience with serial interfacing with this chip?
 
To receive from the PC you need to set it up as Asynchronous. Check out Nigel's tutorial 7.7 for details.

Mike.
 
Okaaaaay, I went through the tutorial and I made this code from it
Code:
init:	BSF STATUs,RP0
	MOVLW b'11000000'
	MOVWF TRISC
	MOVLW 0x06
	MOVWF ADCON1
	MOVLW d'129'
	MOVWF SPBRG
	MOVLW b'00100100'
	MOVWF TXSTA
	BCF STATUS, RP0
	MOVLW b'10010000'
	MOVWF RCSTA
	MOVLW d'54'
loop:	BTFSS PIR1,TXIF
	GOTO loop
	MOVWF TXREG
	GOTO loop
	END

And the simulator works internally, but it never makes it to the output pins (Even on the real eval board)
 
Status
Not open for further replies.

Latest threads

Back
Top