|
|
View previous topic :: View next topic |
Author |
Message |
Ossyle
Joined: 03 Dec 2007 Posts: 1
|
RS232 communication problem |
Posted: Mon Dec 03, 2007 7:01 am |
|
|
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
|
|
Posted: Mon Dec 03, 2007 11:00 am |
|
|
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
|
|
Posted: Mon Dec 03, 2007 11:11 am |
|
|
Also, remember that unless an inverter is present, the 'invert' option is needed in the RS232 setup.
Best Wishes |
|
|
|
|
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
|