View previous topic :: View next topic |
Author |
Message |
ritchie
Joined: 13 Sep 2003 Posts: 87
|
Memory Mapping |
Posted: Mon Nov 15, 2004 10:31 pm |
|
|
Hello,
Question on memory mapping?
I have a structure for PortA... say,
struct {
unsigned int A0:1;
unsigned int A1:1;
...
unsigned int A7:1;
} PortABits;
#locate PortABits=0xF80
With this structure you can now set/reset bit specific ex. PortABits.A0 = 0.
My convern really is that? Is their another way of doing this without using #locate but still you can use the instruction PortABits.A0 = 0?
Need your comments and information.
Thanx |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Nov 15, 2004 10:53 pm |
|
|
One other way:
#bit A0 = 0xF80.0
Then you can use A0=0. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 16, 2004 5:42 am |
|
|
No matter how you do it, you still have to tell the compiler what register portA is. |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Tue Nov 16, 2004 6:40 am |
|
|
ritchie,
Is your concern the portablitly of the code?
Since the CCS compiler does not have a linker, their is no other way to locate the variable other than the #locate.
What you can do is set up a #if statement which detects which compiler you are using and then place all the locate statements in there. This way your code can still compile and run on multiple compilers.
Trampas |
|
|
ritchie
Joined: 13 Sep 2003 Posts: 87
|
|
Posted: Tue Nov 16, 2004 7:15 am |
|
|
Yah my concern really is the portability of the code for other PIC compilers coz the #locate and #bit are CCS specific built-in preprocessors.
Similarly the CCS #byte preprocessor-- I never use this coz I have my own definition which is similar to a #byte and it goes this way:
Code: |
#define PORTA_BASE 0xF80
#define PortA ((unsigned int *) PORTA_BASE)
or
#define PORTA_BASE 0xF80
unsigned int * const PortA = (unsigned int *) PORTA_BASE;
then u can read/write the PortA register by using the instruction below:
*PortA = (unsigned int) value1;
value2 = *PortA;
|
With the code above this is more portable than using the #byte preprocessor of CCS.
BTW, the assembly listing of uisng the *PortA is similar to the assembly listing of using the #byte.
In relation to the #define I mention above, I came to a point if it is really possible to not using the #bit and #locate preprocessor and still you can manipulate the specific bits of a register.
Any suggestions and comments are welcome.
Thanx
Trampas wrote: | ritchie,
Is your concern the portablitly of the code?
Since the CCS compiler does not have a linker, their is no other way to locate the variable other than the #locate.
What you can do is set up a #if statement which detects which compiler you are using and then place all the locate statements in there. This way your code can still compile and run on multiple compilers.
Trampas | [/code] |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 16, 2004 7:19 am |
|
|
Put the declarations in a header file. For the C18 compiler, "I" do not have to specify the locations. Switching between the two compilers, I just include a different processor header file. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Nov 16, 2004 3:38 pm |
|
|
Stay away from #byte and #bit. Use statements like input(PIN_A0) or output_low(PIN_A0). Any other compilers you may want to migrate to later will definitely have similar funtions and changing the code will not be that difficult. |
|
|
|