View previous topic :: View next topic |
Author |
Message |
arys
Joined: 09 Mar 2007 Posts: 31
|
comm port setup problem |
Posted: Thu Jan 10, 2008 10:30 pm |
|
|
Hi,
I have 2 comm ports which one of it I want to use for communicate with PIC. So, how to set up this port?
thanks |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Fri Jan 11, 2008 2:26 am |
|
|
I've tried max232 IO with hyperterminal and it is work.
but when i connect max232 IO to PIC16f873. It doesnt work.
Nobody knows? Plsss..here my simple code (the simplest .. )
Code: | #define (_PCH_)
#include <16f873.h>
#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7, bits=8)
void main()
{
while (true)
{
if (getc()=='1')
output_high (PIN_B7);
}
} |
|
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 11, 2008 1:32 pm |
|
|
Add the NOLVP fuse. Without it, the PIC will lockup if the PGM pin
(pin B3 on the 16F873) goes high. Do this in all your programs.
Quote: | #fuses XT,NOWDT,NOPROTECT,NOLVP |
Also add the ERRORS parameter as shown below. Without it, the
hardware UART's receiver can lock-up if it receives more than two
characters and you don't read at least one of them with getc().
Do this in all your programs.
Quote: |
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7, bits=8, ERRORS) |
|
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Sun Jan 13, 2008 6:08 pm |
|
|
hi guys..it's works. thanks to all. |
|
|
arys
Joined: 09 Mar 2007 Posts: 31
|
|
Posted: Mon Jan 14, 2008 2:11 am |
|
|
Hi..it comeout with new problem. I changed the code to lightup the LED through Visual basic, it doesnt work. But when I use hyperterminal, it works. What's wrong with VB? Hope someone help me. Here I attach the code Code: | #define (_PCH_)
#include <16f873.h>
#use delay (clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=2400,xmit=pin_c6, rcv=pin_c7, bits=8, ERRORS)
void main(void)
{
char c;
while(1)
{
c = getc();
if (c=='1'){
output_high(PIN_B5);
delay_us(400);
output_low(PIN_B5);
delay_us(1600);
putc(c); }
}
} |
|
|
|
mir_as82
Joined: 05 Nov 2007 Posts: 3
|
can you give your vb codes?? |
Posted: Mon Jan 14, 2008 3:36 am |
|
|
firstly check your baudrate,databits,flow control...and other quantities about serial connection.
PIC side and VB side must have same settings about serialport. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 14, 2008 8:40 am |
|
|
Two small remarks.
Why do you define this value? This looks like a compiler internal setting and shouldn't be there. Besides, the PIC16F873 is to be compiled with PCM, not PCH.
This is a very short time for blinking a LED. You can actually see this 0.0004 second pulse??? Or did you mean to use delay_ms() instead? |
|
|
|