|
|
View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
make8() help |
Posted: Mon Mar 21, 2011 5:43 am |
|
|
Hi Friends !
Anybody help about this problem : Code: |
#include <16F628A.H>
#device *=16
//#device adc=8
#fuses NOWDT,HS,PUT,NOPROTECT,BROWNOUT,NOCPD,NOMCLR
#use delay(clock=11 059 200)
#use rs232(baud=9600,rcv=PIN_B1,xmit=PIN_B2,errors)
float temperature;
//.......................................
void send_packet (float *data) //
{
int i;
tx_buffer[0]=stx;
tx_buffer[1]=0x12;//cop_send temp
tx_buffer[2]=address;
tx_buffer[3]=0x00;//errors
tx_buffer[4]=0x04;//lenght of data field
tx_buffer[5]=0x11; //make8(data,0);
tx_buffer[6]=0x12; //make8(data,2);
tx_buffer[7]=0x13; //make8(data,1);
tx_buffer[8]= make8(data,0);// <------------------PROBLEM!!!!
tx_buffer[9]=get_checksum(tx_buffer,9);
tx_buffer[10]=etx;
for (i=0;i<=10;i++)
{
putc(tx_buffer[i]);
}
}
//.......................
send_packet(temperature);
[quote] compiler ver: PCM 4.104
says : "Invalid parameters to built in function "[/quote] |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Mon Mar 21, 2011 5:57 am |
|
|
The compiler may not like the spaces in the
#use delay(clock=11 059 200)
I know it confused me !
just try
#use delay(clock=11059200) or
#use delay(clock=11,059,200)
please check the CCS help file ( press F11),it says exactly how to use/format the directive. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Mar 21, 2011 6:25 am |
|
|
I checked this,,, but it's no my problem.
My problem is function " make8()". I accept float argument *data in my funct. "void send_packet (float *data)" and then try to make four bytes.. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Mar 21, 2011 8:18 am |
|
|
Code: |
void send_packet (float *data) //
{
int i;
tx_buffer[0]=stx;
tx_buffer[1]=0x12;//cop_send temp
tx_buffer[2]=address;
tx_buffer[3]=0x00;//errors
tx_buffer[4]=0x04;//lenght of data field
tx_buffer[5]=0x11; //make8(data,0);
tx_buffer[6]=0x12; //make8(data,2);
tx_buffer[7]=0x13; //make8(data,1);
tx_buffer[8]= make8(data,0);// <------------------PROBLEM!!!!
tx_buffer[9]=get_checksum(tx_buffer,9);
tx_buffer[10]=etx;
for (i=0;i<=10;i++)
{
putc(tx_buffer[i]);
}
}
//.......................
send_packet(temperature);
|
your function is expecting an address (float *data)
You are sending it a value
send_packet(temperature);
Try
send_packet(&temperature);
to send the address of the variable. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Mar 21, 2011 8:25 am |
|
|
You also have another problem
Quote: | From the help.
Syntax:
i8 = MAKE8(var, offset)
Parameters:
var is a 16 or 32 bit integer.
offset is a byte offset of 0,1,2 or 3.
|
It appears MAKE8 does not take floats. you could force it to an int32 but the compiler would convert it.
try i8 = *(data[0]);
or
i8 = *(data[3]);
It realy depends on what you are after. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Mon Mar 21, 2011 8:34 am |
|
|
Several answers, and two comment.
First the comments - what is the point of declaring 'temperature' as global?.
Second, 'data', is a pointer _to_ a float value, not the value, in the function, but you are passing the value itself. basic 'typing' error here....
1) Use a union, instead of make8. This is my 'preferred' way, since make8, is CCS specific, while unions are generic C. So:
Code: |
union {
int8 b[4];
float fpval;
} value;
value.fpval=12345.4;
|
Then value.b[0] to b[3] are the four bytes.
You can also put bytes into value.b[x], then use the floating point result....
Also, because of the 'leniency' of C regarding typing, you can declare such a union, and have your own function, like:
Code: |
union converter {
int8 b[4];
float fpval;
} ;
int do_something(union converter val) {
//Access the bytes here as val.b[0] to b[3]
}
//But call the function with:
float fred;
fred=12345.6;
do_something(fred);
|
2) take advantage of the fact you are passing a pointer. If you don't want to use the value inside the function, simply tell the function that you are handing it a pointer to an integer, not a float. So:
Code: |
void send_packet (int8 *data) //
{
//data[0], to data[3], are the four bytes of the float value.....
}
//But you then need to call with the _address_ of the number,
//not the number. So:
send_packet(&temperature);
|
3) Since the value is global, don't pass the value to the function, but just write the function to access the value directly, and use a byte statement, to give access to this. So:
Code: |
float temperature; //Value
int32 int_version;
#byte int_version=temperature;
//Then anywhere in your code,
make8(int_version,0); //Through to 3
//Will access the bytes making up 'temperature'
|
Best Wishes |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Wed Mar 23, 2011 2:52 pm |
|
|
Thanks for your help developers. |
|
|
|
|
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
|