CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 communication problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ossyle



Joined: 03 Dec 2007
Posts: 1

View user's profile Send private message

RS232 communication problem
PostPosted: Mon Dec 03, 2007 7:01 am     Reply with quote

Hi.

I am trying to RS232 communication with 16F628-04/P UART but I didn't success. I did simple practice. For example I receive RS232 data with getch() function and write porta by leds. I simulate circuit with Proteus, its work. But I didn't work on breadbord. Please help for this.

Sorry about bad english.

Circuit



Program.c
Code:
#include "C:\Program Files\PICC\Projects\628yeni.h"

int deg;
void main()
{

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
while(1)
{
output_a(0);
deg=getc();
if(deg!="")
{
output_a(deg);
delay_ms(500);
}
}

}


Program.h
Code:
#include <16F628.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES PROTECT                  //Code protected from reads
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)



Thanks for help.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 11:00 am     Reply with quote

You should NOT connect an RS232 signal directly to a PIC pin. The RS232 signal voltage can swing as much as +15V to -15V which can seriously damage a PIC.

The best way is to use an RS232 driver chip like the MAX232. You can learn a lot by reading the MAX232 datasheet even if you don't use that chip.

For receiving only you can probably get away with a simple 10k resistor between the RS232 connector and the PIC, especially at moderate baud rates like 9600 baud.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Mon Dec 03, 2007 11:11 am     Reply with quote

Also, remember that unless an inverter is present, the 'invert' option is needed in the RS232 setup.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group