View previous topic :: View next topic |
Author |
Message |
che_chia
Joined: 09 May 2011 Posts: 6
|
Could I find any RS232 example code for PIC16F1947 ? |
Posted: Tue May 10, 2011 11:26 pm |
|
|
I'm trying to verify whether my pcb RS232 function is normal or not by HyperTerminal.
I can't do it very well for many until now. Where could I find this kind of example code?
Thanks a lot!!! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed May 11, 2011 6:21 am |
|
|
The code should be similar for any PIC16Fxxxx chip. On the other hand HyperTerminal is awful. Use SIOW that comes with CCS or Realterm or Terminal by Brady++ or any one of the other better terminal programs for the PC. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed May 11, 2011 7:11 am |
|
|
Please heed the advice not to use Hyperterminal. When new to RS232 the last thing you need is to deal with the quirks of Hyperterminal. Next remember that RS232 is asynchronous so a character can arrive and will arrive at anytime not just at the ends of lines of code or sections of your main code. The robust way is to write an interrupt driven circular buffer. Except for the simplest use you'll find you'll need a circular buffer anyway. This board has many questions about wayward RS232 code most of which would have been avoided by use of an interrupt driven circular buffer. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 11, 2011 12:49 pm |
|
|
Here is a sample program. When you type a character in a terminal
window on your PC, this program should receive and send it back to
the PC, where it will be displayed.
Code: |
#include <16F1947.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
//====================================
void main()
{
int8 c;
printf("Start \n\r");
while(1)
{
c = getc();
putc(c);
}
} |
|
|
|
|