Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution.

Reply
 
Tools
Old 5th July 2009, 04:20 PM   #1
Default Need help with PIC USART programming

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.



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



The question is... How do I program the PIC to send and receive data?
__________________
Dave Pusey.
PIC Programming Tutorials: http://www.mstracey.btinternet.co.uk...al/picmain.htm
Brilliant PIC Simulator: http://www.oshonsoft.com/pic.html
davepusey is offline  
Old 5th July 2009, 04:22 PM   #2
Default

Check my PIC RS232 tutorials, most use a software UART (so it can be used on any pin), but the last one shows how to use the hardware UART.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 5th July 2009, 05:20 PM   #3
Default

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.
__________________
Dave Pusey.
PIC Programming Tutorials: http://www.mstracey.btinternet.co.uk...al/picmain.htm
Brilliant PIC Simulator: http://www.oshonsoft.com/pic.html
davepusey is offline  
Old 5th July 2009, 05:45 PM   #4
Default

Quote:
Originally Posted by davepusey View Post
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.

Quote:

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 5th July 2009, 06:27 PM   #5
Default

Quote:
Originally Posted by Nigel Goodwin View Post
Yes, you can set the hardware UART to generate an interrupt when data is received
Do you have an example of this please?
__________________
Dave Pusey.
PIC Programming Tutorials: http://www.mstracey.btinternet.co.uk...al/picmain.htm
Brilliant PIC Simulator: http://www.oshonsoft.com/pic.html
davepusey is offline  
Old 5th July 2009, 06:59 PM   #6
Default

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'.
chuddleston is offline  
Reply

Tags
pic, programming, usart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
usart with pic neelam29 Micro Controllers 19 18th July 2009 09:39 AM
USART with PS/2 andonur Micro Controllers 1 11th March 2009 12:40 AM
Usart + Adc Overclocked Micro Controllers 5 28th January 2009 06:35 PM
PIC USART: Help Please mortuzahasan Micro Controllers 2 11th February 2007 07:28 PM
HELP!!! nothing going through my USART!!! Guyver Micro Controllers 8 6th May 2004 09:11 AM



All times are GMT. The time now is 08:28 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker