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

Memory Mapping

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



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

Memory Mapping
PostPosted: Mon Nov 15, 2004 10:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 15, 2004 10:53 pm     Reply with quote

One other way:

#bit A0 = 0xF80.0

Then you can use A0=0.
Mark



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

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

PostPosted: Tue Nov 16, 2004 5:42 am     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Tue Nov 16, 2004 6:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 16, 2004 7:15 am     Reply with quote

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

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

PostPosted: Tue Nov 16, 2004 7:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 16, 2004 3:38 pm     Reply with quote

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.
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