Jump to content
Sign in to follow this  
danutz

Fixed Address For Functions

Recommended Posts

How can I put a function at a certain address in BoostC?

In C2C-Plus it's void MyFunction() @ 0x1234, but this seems not to work in BoostC.

 

Thank you,

Dan

Share this post


Link to post
Share on other sites

danutz

How can I put a function at a certain address in BoostC?

In C2C-Plus it's void MyFunction() @ 0x1234, but this seems not to work in BoostC.

Can't be done ;)

Why do you want to do this?

 

Regards

Dave

Share this post


Link to post
Share on other sites
danutz
How can I put a function at a certain address in BoostC?

In C2C-Plus it's void MyFunction() @ 0x1234, but this seems not to work in BoostC.

Can't be done ;)

Why do you want to do this?

 

Regards

Dave

 

I need to do this because I store data in the code memory.

C2C-Plus had problems in accessing this data (in certain conditions makes a call to a wrong address), so I had to define that data in assembler. Like this:

 

void Init_Mem() @ 0x1500

{

asm

{

clrw

bsf PCLATH, 2

bcf PCLATH, 1

bsf PCLATH, 0

addwf PCL, 1

retlw .65

...

}

}

 

This is for initialization, then I load the offset in W and make a call to 0x1501. All the data arrays <256 bytes.

 

Since I deleted the old data declaration (const char[] = {...}:P, it wouldn't be easy to rewrite it.

 

Dan

Share this post


Link to post
Share on other sites
I need to do this because I store data in the code memory.

C2C-Plus had problems in accessing this data (in certain conditions makes a call to a wrong address), so I had to define that data in assembler. Like this:

 

void Init_Mem() @ 0x1500

{

  asm

  {

    clrw

    bsf PCLATH, 2

    bcf PCLATH, 1

    bsf PCLATH, 0

    addwf PCL, 1

    retlw .65

    ...

  }

}

 

This is for initialization, then I load the offset in W and make a call to 0x1501. All the data arrays <256 bytes.

 

Since I deleted the old data declaration (const char[] = {...};), it wouldn't be easy to rewrite it.

 

Dan

You have two options and neither are really easy:

1) Used rom data, eg

rom char* data = { 1, 2 ,3 , ... };

It should be easy to replace your existing your data by searching and replacing retlw with a ",".

The downside of this solution is the time overhead in retrieving the data. But it works reliably and is easy to code. Data accessed using y = data[ x ];

 

2) Created a ret data table outside the program memory space using #pragma data 0x1500, 0x34xx, 0x34xx, 0x34xx,

This is harder work because you will need to encode the retlw opcode in each piece of data. Data accessed by calling absolute address is inline asm call instruction.

 

Regard

Dave

Share this post


Link to post
Share on other sites

Dave missed a third option, use your chips internal eeprom if it has one :)

or an external eeprom works well too.

Share this post


Link to post
Share on other sites
Dave missed a third option, use your chips internal eeprom if it has one :)

or an external eeprom works well too.

 

No, it has no EEPROM :-(

 

I used the second option from Dave and it works fine. Only that I had to put a 0x0782 (addwf PCL, f) between address and the first 0x34xx.

(#pragma DATA 0x1500, 0x0782, 0x34xx, ....)

 

Thank you both for your answers

Dan

Share this post


Link to post
Share on other sites

danutz,

I used the second option from Dave and it works fine. Only that I had to put a 0x0782 (addwf PCL, f) between address and the first 0x34xx.

(#pragma DATA 0x1500, 0x0782, 0x34xx, ....)

Ah yes I forgot that bit.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...