11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C Language FeaturesPreprocessing3.12.3.5 The #pragma psect DirectiveNormally the object code generated by the compiler is broken into the standard psects as describedin Section 3.9.1. This is fine for most applications, but sometimes it is necessary to redirect variablesor code into different psects when a special memory configuration is desired. Code and data for anyof the standard C psects may be redirected using a #pragma psect directive.The general form of this pragma looks like:#pragma psect default_psect=new_psectand instructs the code generator that anything that would normally appear in the compiler-generatedpsect default_psect, will now appear in a new psect called new_psect. This psect will beidentical to default_psect in terms of its options, however will have a different name. Thus,this new psect can be explicitly positioned by the linker without affect the original psect’s location.If the name of the default psect that is being redirected contains a counter, e.g. text0, text1,text2, then the placeholder %u should be used in the name of the psect at the position of the counter,e.g. text%u. Any default psect, regadless of the counter value, will match such a psect name.This pragma remains in force until the end of the module and any given psect should only beredirected once in a particular module. All psect redirections for a particular module should beplaced at the top of the source file, below any #include statements and above any other declarations.TUT•RIALA particular function, called read_port(), needs to be located at the absolute address0x400 in a program. Using the #pragma psect directive in the source code, and addinga new linker option can do this. First write the function in the usual way. Place thefunction definition in a separate module. There is obvioulsy something special aboutthis function so a module all to itself is probably a good idea anyway.unsigned char read_port(void){return PORTA;}Now, how do we know in which psect the code associated with the function will beplaced? Compile you program, inlcuding this new module and generate an assemblylist file, see Section 2.4.18.Look for the definition of the function. A function starts with an assembly label whichis the name of the function prepended with an underscore. In this example, the labelappears on line 37.59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!