View previous topic :: View next topic |
Author |
Message |
Doug Guest
|
#bit OR int1? |
Posted: Wed Mar 10, 2004 12:56 pm |
|
|
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
|
|
Posted: Wed Mar 10, 2004 1:20 pm |
|
|
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
|
Re: #bit OR int1? |
Posted: Wed Mar 10, 2004 1:33 pm |
|
|
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
|
|
Posted: Wed Mar 10, 2004 3:33 pm |
|
|
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
|
|
Posted: Wed Mar 10, 2004 8:27 pm |
|
|
Thanks to all who replied. Now I understand the difference.
Doug |
|
|
|