View previous topic :: View next topic |
Author |
Message |
atta Guest
|
MASTER Slave communicaton |
Posted: Thu Jul 12, 2007 2:23 am |
|
|
PLZ some one can help me?
- LM35 is conected to Slave controller(PIC16f877)
-slave is sending the temperature value to master controller(pic16f877) as string string via RS232.
-master on reciving this string on soft-port will send this string to PC on hardport.
-slave also attach its adress with the string.
ON master side i have to seprate the adress and temp value for my control logic.
PLZ can some one help me by giving me the code of
-how the slave will send string(temperatur + adress)
-how the master will receive the string
-how the master will saperate the adress and teperature value |
|
|
atta Guest
|
|
Posted: Fri Jul 13, 2007 1:56 pm |
|
|
Code: | printf ("%3.1fslave1\r",(float)temperatur);
\\slave is sending temperature value |
************************************************************
master will receive following string i want to separate temperature value and slave1 from this string.
i am using following code at master side to separate temperature value and slave1 from this string.
Code: | fgets (string1,COM_A);
fprintf (PC, string1);
temp1=strtod(string1,&ptr1);
delay_ms (1000);
fprintf (PC,"temperature(Slave) = ");
fprintf (PC,"%3.1f", (float)temp1); |
************************************************************
the above code works if slave send sitring by this way
|
|
|
Guest
|
|
Posted: Fri Jul 13, 2007 2:24 pm |
|
|
PLZ help me where is the problem in the above code |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 13, 2007 2:46 pm |
|
|
It's not clear to me exactly what you want to do. You need to show
the string that your master will receive, and then show the two extracted
sub-strings that you want to get.
It may be that you want the C language equivalent of MID$ in Basic.
If so, see this thread.
http://www.ccsinfo.com/forum/viewtopic.php?t=27121 |
|
|
atta Guest
|
|
Posted: Fri Jul 13, 2007 3:01 pm |
|
|
actuly i want to use this function
Code: | float result;
char str[12]="123.45hello";
char *ptr;
result=strtod(str,&ptr);
//result is 123.45 and ptr is "hello" |
********************************
slave send the following command to master
Code: |
temperature=read_adc ();
printf ("%3.1fA\n\r",(float)temperature);
|
*****************************
master on receiving this string has to send the result to PC seriallly by using the following code
Code: | fgets (string1,COM_A);// from slave
result=strtod(string1,&ptr1);
fprintf (PC,"%6.2f", (float)result);//to PC |
|
|
|
|