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

int32 problems

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



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

int32 problems
PostPosted: Fri Apr 01, 2005 6:54 pm     Reply with quote

Maybe it's because it's 5 to 5 on a Friday, but I can't figure this out. I'm sure that I'll smack myself come Monday. (And not just because it's Monday.)

I'm using a 16F88, CCS v 3.222. I've got to use a 32 bit number becuase I'm interfacing with a SEEPROM that uses 24-bit addressing. Testing has shown that it's only using the 16 lower bits in the int32.

After several attempts, I end up with this:

Code:

int1 write_SEEPROM( int32 address, int data )
{
  //Yes, this is stupid.
  #bit addr_0 = address.0
  #bit addr_1 = address.1
  #bit addr_2 = address.2
  #bit addr_3 = address.3
  #bit addr_4 = address.4
  #bit addr_5 = address.5
  #bit addr_6 = address.6
  #bit addr_7 = address.7
  #bit addr_8 = address.8
  #bit addr_9 = address.9
  #bit addr_10 = address.10
  #bit addr_11 = address.11
  #bit addr_12 = address.12
  #bit addr_13 = address.13
  #bit addr_14 = address.14
  #bit addr_15 = address.15
  #bit addr_16 = address.16
  #bit addr_17 = address.17 //<-- error highlights here.
  #bit addr_18 = address.18
  #bit addr_19 = address.19
  #bit addr_20 = address.20
  #bit addr_21 = address.21
  #bit addr_22 = address.22
  #bit addr_23 = address.23

  int upper_address;
  #bit ua_0 = upper_address.0
  #bit ua_1 = upper_address.1
  #bit ua_2 = upper_address.2
  #bit ua_3 = upper_address.3
  #bit ua_4 = upper_address.4
  #bit ua_5 = upper_address.5
  #bit ua_6 = upper_address.6
  #bit ua_7 = upper_address.7
 
  int middle_address;
  #bit ma_0 = middle_address.0
  #bit ma_1 = middle_address.1
  #bit ma_2 = middle_address.2
  #bit ma_3 = middle_address.3
  #bit ma_4 = middle_address.4
  #bit ma_5 = middle_address.5
  #bit ma_6 = middle_address.6
  #bit ma_7 = middle_address.7
 
  int lower_address;
  #bit la_0 = lower_address.0
  #bit la_1 = lower_address.1
  #bit la_2 = lower_address.2
  #bit la_3 = lower_address.3
  #bit la_4 = lower_address.4
  #bit la_5 = lower_address.5
  #bit la_6 = lower_address.6
  #bit la_7 = upper_address.7
 
  #bit la_0 = address.0
  #bit la_1 = address.1
  #bit la_2 = address.2
  #bit la_3 = address.3
  #bit la_4 = address.4
  #bit la_5 = address.5
  #bit la_6 = address.6
  #bit la_7 = address.7
 
  #bit ma_0 = address.8
  #bit ma_1 = address.9
  #bit ma_2 = address.10
  #bit ma_3 = address.11
  #bit ma_4 = address.12
  #bit ma_5 = address.13
  #bit ma_6 = address.14
  #bit ma_7 = address.15
 
  #bit ua_0 = address.16
  #bit ua_1 = address.17
  #bit ua_2 = address.18
  #bit ua_3 = address.19
  #bit ua_4 = address.20
  #bit ua_5 = address.21
  #bit ua_6 = address.22
  #bit ua_7 = address.23



The rest of the code isn't important, since the compiler gives up and says "Number of bits is out of range" once it gets to bit 17. It's an extension of the working great 16-bit addressing function that I've been using for months. (Customer requirements are demanding that we bump up the SEEPROM capacity.)

Thanks for you help.
_________________
In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;)
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Apr 01, 2005 7:15 pm     Reply with quote

I am surprise that you got anything past 7. Read the manual. Only bits 0-7 are valid. I guess the real question is what in the heck are you trying to do. Why do you need all of those bit definitions!
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Fri Apr 01, 2005 7:26 pm     Reply with quote

Use bit_test(), bit_set() and bit_clear() instead.
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 04, 2005 10:17 am     Reply with quote

Mark wrote:
I am surprise that you got anything past 7. Read the manual. Only bits 0-7 are valid. I guess the real question is what in the heck are you trying to do. Why do you need all of those bit definitions!


I'm trying to break an int32 into four 8-bit values so I can send them over SPI. The memory chip uses 24-bit addressing, and I've spent some time trying to get the 32 -> 8 conversion. I tried bit-shifting, and that only gets me the 16-bit lower half of the int32. The bit-assignment was sort of a last-ditch effort, but I get the feeling that they are indicative of the same PEBKAS error.

I'm tried bit-shifting, I've tried make(8), but it just seems like it doesn't understand the concept of 32-bit numbers.
_________________
In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;)


Last edited by theMagni on Mon Apr 04, 2005 11:19 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Apr 04, 2005 10:31 am     Reply with quote

Quote:
I've spent some time trying to get the 32 -> 8 conversion.
Have you tried make8()? This accepts 32-bit integers.
Ttelmah
Guest







PostPosted: Mon Apr 04, 2005 3:27 pm     Reply with quote

theMagni wrote:
Mark wrote:
I am surprise that you got anything past 7. Read the manual. Only bits 0-7 are valid. I guess the real question is what in the heck are you trying to do. Why do you need all of those bit definitions!


I'm trying to break an int32 into four 8-bit values so I can send them over SPI. The memory chip uses 24-bit addressing, and I've spent some time trying to get the 32 -> 8 conversion. I tried bit-shifting, and that only gets me the 16-bit lower half of the int32. The bit-assignment was sort of a last-ditch effort, but I get the feeling that they are indicative of the same PEBKAS error.

I'm tried bit-shifting, I've tried make(8), but it just seems like it doesn't understand the concept of 32-bit numbers.


Use a union.
[code]
union {
int32 word;
int8 b[4];
} value;
[code]
Then 'value.word', accesses the 32 bit value, while value.b[0] to value.b[3] access the individual bytes. This is the standard C way to do this sort of access, and works fine. :-)

Best Wishes
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 04, 2005 4:08 pm     Reply with quote

Funnily enough, it didn't work until I used #type long=32. For some reason int32 just didn't cut it.

I wonder why.

Thanks for the advice on the union, though. That worked great.
_________________
In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;)
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