|
|
View previous topic :: View next topic |
Author |
Message |
janet
Joined: 17 Feb 2004 Posts: 23
|
how to accept value from other pic? |
Posted: Sun Mar 21, 2004 7:39 am |
|
|
/*
sensor.c
*/
#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, BROWNOUT, NOLVP
// #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
// i exchange pin_c6 & c7 because 2 ports are connected directly
#use rs232(baud=9600,xmit=PIN_C7,rcv=PIN_C6)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
void main() {
while (1) {
printf("Hello World!");
}
}
/*
receiver.c
*/
#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, BROWNOUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, STREAM=RS_DEBUG)
#USE RS232(BAUD=9600, XMIT=PIN_B6, RCV=PIN_B7, STREAM=RS_DATA)
void main() {
while (1) {
fprintf(RS_DEBUG, "--%C", fgetc(RS_DATA));
}
}
I got 2 rs232 port on receiver. one is for debugging, one is for receiving data from sensor.
However, it only generates rubbish on the screen, but not "Hello World"
How to display data from other PIC via rs232?
cheers |
|
|
Guest
|
|
Posted: Sun Mar 21, 2004 2:13 pm |
|
|
Janet,
i've jyst strated doing this, but all i do is, printf on 1 pic and getch on the 2nd part, rx on c6 and tx on c7 |
|
|
Konrad
Joined: 15 Sep 2003 Posts: 34
|
|
Posted: Sun Mar 21, 2004 4:51 pm |
|
|
Do not swap C6 & C7. Theses are the hardware UART pins, and by swapping them the compiler reverts to the software UART which is by no means as good.
Use the hardware UART for any stream that needs an input.
The software UART is best for simple output (DEBUG).
Add the ERRORS directive to your #use rs232
Add a delay between the printf("hello world") function. |
|
|
[email protected] Guest
|
|
Posted: Sun Mar 21, 2004 5:33 pm |
|
|
Which #use rs232 statement?
sensor or receiver? |
|
|
Guest
|
|
Posted: Sun Mar 21, 2004 5:55 pm |
|
|
I'd rather add a stream identifier in each of the #use rs232() function. Use it this way:
for debugging...
fprintf(com1,"<text here>",variables)
for getting data....
fgetc(com2)
Hope this helps... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1937 Location: Norman, OK
|
RS232 |
Posted: Sun Mar 21, 2004 6:10 pm |
|
|
What screen are you displaying on? The PC screen?
If so, how are you connected between the PIC and the PC? Are you using an RS232 converter chip or direct connecting?
For the hardware outputs you must use an RS232 converter like the MAX232 or MAX233 (which inverts the signal) or an inverter of some sort like the SN7404. For the software UART you may need to use the INVERT keyword for USE RS232 |
|
|
janet
Joined: 17 Feb 2004 Posts: 23
|
|
Posted: Mon Mar 22, 2004 1:25 am |
|
|
ok,
since i got 2 rs232 port, how many max232 i have to use? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Mar 22, 2004 12:31 pm |
|
|
janet wrote: | ok,
since i got 2 rs232 port, how many max232 i have to use? |
How far are you sending the signal? If both PICs have a common ground and the distance is less than 10 feet at 9600 baud you don't need an RS232 converter like the MAX232. Just connect the PICs together and send "TTL serial" data.
If you are going farther, or the PICs may have different ground potentials, or you want to communicate with other true RS232 equipment, you will need a converter chip like the MAX232 at each end of the transmission line. Depending on converter chip model one chip may handle several ports on the same PIC. Read the data sheet on the MAX232 to learn a little more. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
janet
Joined: 17 Feb 2004 Posts: 23
|
|
Posted: Wed Mar 24, 2004 3:06 am |
|
|
actually the sensor pic is very near with the receiver pic. I use rs232 so that i could change the sensor easily.
unfortunately, the RS_DATA doesn't work and receive nothing. |
|
|
|
|
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
|