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

how to accept value from other pic?

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



Joined: 17 Feb 2004
Posts: 23

View user's profile Send private message

how to accept value from other pic?
PostPosted: Sun Mar 21, 2004 7:39 am     Reply with quote

/*
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








PostPosted: Sun Mar 21, 2004 2:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 21, 2004 4:51 pm     Reply with quote

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.
janetsmith2000@yahoo.com
Guest







PostPosted: Sun Mar 21, 2004 5:33 pm     Reply with quote

Which #use rs232 statement?
sensor or receiver?
Guest








PostPosted: Sun Mar 21, 2004 5:55 pm     Reply with quote

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: 1934
Location: Norman, OK

View user's profile Send private message

RS232
PostPosted: Sun Mar 21, 2004 6:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 22, 2004 1:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 22, 2004 12:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 3:06 am     Reply with quote

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.
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