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 support@ccsinfo.com

What should be an easy 16bit read - apparently not ?

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







What should be an easy 16bit read - apparently not ?
PostPosted: Mon Sep 10, 2007 6:24 pm     Reply with quote

Helo,

I am trying to read from a table array which is set up as 80 individual bytes, stored at every 9th and 10th byte is a single 16bit value

So, my plan was to read and write bytes 0-7 normally then when I get to the 8th byte just read it as an int16. I'm kind of used to asm where I can just use MOV.w

The idea was to do something like this:
Code:

value = table[current_entry+8];  //or something with *&table

And thus capture [8] and [9] but obviously this doesn't work. And I have to do it quiet a bit so I looking for something more effecicent then grabbing [8] and shifting over 8 bits then adding [9]

Is there a good way to do this in CCS ? I know I could maybe set up unions but I'm not sure how that would work with my indexing (current_entry is multiples of 10)

Thank You!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 8:51 pm     Reply with quote

Use the make16() function. You give it two bytes, and it will put them
together into a 16-bit value. It's in the manual.
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Redmond
Guest







PostPosted: Tue Sep 11, 2007 9:46 am     Reply with quote

Cool, I'll try that.

Is make16 fast ? I was really hoping for something quick, but the quickest I can think of would be pointers and I can't seem to get that working correctly

I can get 1 byte no problem, but no matter what I do I can't seem to get it and its next byte.
Ttelmah
Guest







PostPosted: Tue Sep 11, 2007 9:51 am     Reply with quote

Make16, is very fast.
Pointers are actually relatively slow (as is the actual access to the array). However you are only talking a handful of instructions for the array access, and the make16, is done in effectively just two instructions, just transferring the bytes (once read), into the required byte in the output variable.

Best Wishes
Redmond
Guest







PostPosted: Tue Sep 11, 2007 11:43 am     Reply with quote

I read that part in the manual about 2 ins right after I posted that. Thats cool, wish I would have know that earlier

One quick follow up about arrays being slow, it that a treat from CCS, PIC or just a general truth about all micros ?
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Sep 12, 2007 7:12 am     Reply with quote

Some micros are better than others - to access an array element (for 1-d case) you need a scaled offset from the start address of the array. So if the micro has indexed addressing then it's better, and if it has left shift capability even better (then it can address bytes, 16 bits, 32 bits etc with a simple 'add shifted index to base' to get the address).

IIRC PIC18's have some sort of extended addressing, but the CCS compiler does not use this extended mode?
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