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

make8() help

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



Joined: 02 Feb 2010
Posts: 354

View user's profile Send private message

make8() help
PostPosted: Mon Mar 21, 2011 5:43 am     Reply with quote

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: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 5:57 am     Reply with quote

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: 354

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 6:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 8:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 8:25 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 8:34 am     Reply with quote

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: 354

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 2:52 pm     Reply with quote

Thanks for your help developers. Idea
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