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() not working

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



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

make8() not working
PostPosted: Thu Dec 09, 2010 2:02 pm     Reply with quote

4.114, PIC18F8722

Make8() will not compile when a variable is used as the offset. Here is an example I created that will not compile:
Code:
void somefunction(void) {
   int8 iData[4];
   int32 lPortBit[] = { 0x00000010,0x000000020,0x00000040,0x00000080,0x00000100,
      0x00000001,0x00000002,0x00000004,0x00000008 };
   int8 iCnt,iOffset;

   for(iCnt=0;iCnt<9;iCnt++) {
      for(iOffset=0;iOffset<3;iOffset++)  iData[iOffset] = make8(lPortBit[iCnt],iOffset);
      fprintf(TERM,"%02X\n\r",iData[0]
   }
}
This would make iData[3] contain the MSB and iData[0] contain the LSB of the int32.

Quote:
*** Error 108 "AB12-IO.c" Line 121(39,46): Invalid parameters to built in function ::
where line 121 is the line with make8() in it.

The CCS manual does not indicate if offset must be a constant. Am I doing something wrong?

Thanks,
Kyle
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 09, 2010 2:12 pm     Reply with quote

I don't think a variable parameter is supported for the offset.
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Thu Dec 09, 2010 2:32 pm     Reply with quote

Thanks, that was my conclusion, but I don't see why they would not. It seems sophomoric to do:
Code:
      iData[0] = make8(lPortBit[iCnt],0);
      iData[1] = make8(lPortBit[iCnt],1);
      iData[2] = make8(lPortBit[iCnt],2);
      iData[3] = make8(lPortBit[iCnt],3);
My professors would have laughed at me for forgetting how to do loops. Wink

Thanks,
Kyle
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Dec 09, 2010 3:52 pm     Reply with quote

The problem is down to the nature of the function. It uses the simplest approach, to select the byte _efficiently_ at compile time. You can do it with a loop, using a union, or casting an int8 pointer to the memory you want to transfer, _but_ the variable version, will probably be about 3 or 4 times the size of all four of the single byte transfers, and slower too...

Best Wishes
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