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

#bit OR int1?

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







#bit OR int1?
PostPosted: Wed Mar 10, 2004 12:56 pm     Reply with quote

What is the difference between using:

Code:
int x;
#bit bit_1 = x.0
#bit bit_2 = x.1

etc...


-OR-

Code:
typedef int1 bit;
bit bit_1, bit_2;


Is one better than the other?

Thanks
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 1:20 pm     Reply with quote

My suggestion: check the assembly out of the code (program memory) and needed RAM to understand which one needs less resources.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: #bit OR int1?
PostPosted: Wed Mar 10, 2004 1:33 pm     Reply with quote

Doug wrote:
What is the difference between using:

Code:
int x;
#bit bit_1 = x.0
#bit bit_2 = x.1

etc...


-OR-

Code:
typedef int1 bit;
bit bit_1, bit_2;


Is one better than the other?

Thanks


I perfer using #bit because I am able to locate the variable where I want to. If I have a function that uses several variables I perfer to insure the variables are in a common memory bank. Using variables that are located in different memory banks generates more code that runs slower.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 10, 2004 3:33 pm     Reply with quote

Quote:
Is one better than the other ?


Use int1 to let the compiler automatically allocate the
variable locations. This is one of the main reasons we
buy the CCS compiler. If we have to do it manually
and assign addresses to each variable, then we basically
have converted the CCS compiler to the Hi-Tech compiler.

I suppose you might want to manually set the location of
some commonly used variables in the common ram
area at the end of each bank in the 16F877. Then the
compiler wouldn't have to generate bank select code
each time it accessed one of these variables. Example:

#locate my_flags = 0x70

#bit flag0 = my_flags.0
#bit flag1 = my_flags.1
#bit flag2 = my_flags.2
#bit flag3 = my_flags.3
// etc.

void main(void)
{
flag0 = 1;
flag1 = 1;
// etc.

while(1);
}

But I've never found a need for this.
--------------------------------------------

The #bit directive is primarily intended to allow accessing
bits within SFR registers as if they are variables.
For example, if I want to be able to directly read or write
to the Interrupt Flag for the External Interrupt in the 16F877,
I can do this:

#bit INTF_BIT = 0x0B.1

main()
{

INTF_BIT = 0;

while(1);
}
Doug
Guest







PostPosted: Wed Mar 10, 2004 8:27 pm     Reply with quote

Thanks to all who replied. Now I understand the difference.

Doug
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