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.

Need help with PIC USART programming

Status
Not open for further replies.

davepusey

Member
Hi

I've got my circuit wired up like this so far...

The red wire acts as a loopback (for testing) so that anything i send out the serial port on my computer, i get straight back again.

This is working perfectly.

**broken link removed**

The plan is to remove the red link, and connect the TTL level signals to the USART of a PIC16F627 like this...

**broken link removed**

The question is... How do I program the PIC to send and receive data?
 
Ok - a couple of questions...

1) What is the purpose of the test/loop in this code block?

Code:
XMIT_RS232  	btfss   PIR1,	TXIF 	      ;xmit buffer empty?
     		GOTO	XMIT_RS232            ;no, wait
     		MOVWF   TXREG		      ;now send
                RETURN

2) Is there a way to receive data via an interrupt?

I dont really want to keep polling the usart when it wont be used that often.
 
Ok - a couple of questions...

1) What is the purpose of the test/loop in this code block?

Code:
XMIT_RS232  	btfss   PIR1,	TXIF 	      ;xmit buffer empty?
     		GOTO	XMIT_RS232            ;no, wait
     		MOVWF   TXREG		      ;now send
                RETURN

As the comments say, it's waiting until the transmit buffer is empty - it's the standard way of using the UART - you don't want to overwrite the buffer while it's still been used.

2) Is there a way to receive data via an interrupt?

I dont really want to keep polling the usart when it wont be used that often.

Yes, you can set the hardware UART to generate an interrupt when data is received, or you can occasionally poll the interupt flag to see if data is received.
 
Fr. Tom McGahee

Check out the PICUART.zip example. Enable the UART interrupt and configure the TRIS register correctly for the RX and TX pins, then when a byte is received the code will automatically jump to ORG h'0004'.
 
Hi

I've got my circuit wired up like this so far...

The red wire acts as a loopback (for testing) so that anything i send out the serial port on my computer, i get straight back again.

This is working perfectly.

**broken link removed**

The plan is to remove the red link, and connect the TTL level signals to the USART of a PIC16F627 like this...

**broken link removed**

The question is... How do I program the PIC to send and receive data?
just to noticing

The RX and TX pin can be setted anywhere you want

it doesnt have to be on that pin :)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top