Moving Relocatable Code Files - org Directive

For simplicity's sake, up until this point I have been keeping all of my LCD writing functions and tables in the same file, but now that I am cleaning up my code in its near-polished state, I'm looking to move my tables to a separate file.

 

I have no problem with all of the basic steps, but since I am using relocatable code generated with the code flag, the linker always puts my tables in the last part of the program memory, which makes the tables work incorrectly (as we all know, there is a 256 line limit).

 

I've looked at the sample code, and I see that they've specified their "lcd.asm" file with the directive code org 0x10, which works when I compile it. However, when I add this location specification into my projects, I get the following error message:

 

MPLINK 4.38, Linker Copyright (c) 1998-2010 Microchip Technology Inc.

Error - section '.code' type is non-overlay and absolute but occurs in more than one input file.

Errors    : 1

LINK STEP FAILED

 

From what I can understand from this error, it seems to be telling me that I cannot use the code directive in more than once file. However, I have used that directive in five-six files for the entire duration of this project (without the org specification).

 

In addition, I have tried simply moving my code by using org 0x20 in the new tables file, but that also generates the same error message.

 

Has anyone experienced this problem? Any ideas would be appreciated. I can keep all my tables in the same file as my LCD functions, but I'd like to move them to their own separate file for readability purposes.

 

Mark

Views: 358

Comment

You need to be a member of Personal Mechatronics Lab to add comments!

Join Personal Mechatronics Lab

Comment by Hollis Milroy on March 28, 2011 at 7:38pm
try giving all your "code" sections different names.  I believe that each section has to have a unique name (label).  This worked for me
Comment by Jeff Nicholls on March 2, 2011 at 3:17pm

I'm pretty sure your problem is that you are trying to put code into already occupied program memory.  Check your main program, are you using any ORGs in it?  I know my main program first has:

ORG 0x0000

goto Initialize

 

ORG 0x0004

goto Isr

 

;TABLES

;ISR

;MAIN CODE (which includes initialize)

 

So my main code will be starting at 0x0000 and running down from that point for about ~1400 lines of code.  If I tried to set my lcd code to ORG at 0x0010 or 0x0020 it would conflict with the location of my main program.  Therefore, in all of my linked asm files I just use the directive code with no ORGs whatsoever.  I only use ORGs in my main program.

 

Another thing is to make sure you know how long each piece of code is and where it is being placed.  Check the disassembly listing when you compile and it will show you where everything is being placed (if you were able to compile).

 

As you can see my tables are within the first 256 lines of code (the tables are only about 80 lines of code if that).  After tables comes the ISR, then initialization code, then main program.  If you want to put your tables in a separate file, just figure out how many lines of code they take up, then leave that much space at the top of your main program and do what you are currently trying to do.  You will then need an ORG 0xXXXX in front of your main code in order to create that space for the tables code.

© 2024   Created by PML.   Powered by

Badges  |  Report an Issue  |  Terms of Service