⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_function_placement.c

📁 Mplab C30编译器
💻 C
字号:

 /* Example illustrating how to locate a function at a specific address */

 /***********************************************************************
 *  In this example, function func is located at a specific address.    *
 *  Two built-in compiler functions are used to calculate the program   *
 *  memory address, which is not otherwise available in C function.     *
 *                                                                      *
 *  You can view the results of the printf statements by enabling the   *
 *  MPLAB SIM tool then enabling the UART1 I/O with Output set to       *
 *  Window. The printf results are then displayed in the output window. *
 *                                                                      *
 *  A defined heap size is required since we are using a standard I/O   *
 *  function.                                                           *
 *                                                                      *
 *                                                                      *
 *  For additional information about dsPIC architecture and language    *
 *  tools, refer to the following documents:                            *
 *                                                                      *
 *  MPLAB C30 Compiler User's Guide                        : DS51284    *
 *  dsPIC 30F MPLAB ASM30, MPLAB LINK30 and Utilities                   *
 *                                           User's Guide  : DS51317    *
 *  Getting Started with dsPIC DSC Language Tools          : DS51316    *
 *  dsPIC 30F Language Tools Quick Reference Card          : DS51322    *
 *  dsPIC 30F 16-bit MCU Family Reference Manual           : DS70046    *
 *  dsPIC 30F Programmer's Reference Manual                : DS70030    *
 *                                                                      *
 *  Example file has been compiled with MPLAB C30 v1.30.00              *
 *                                                                      *
 ************************************************************************
 *                                                                      * 
 *    Author:                                                           *
 *    Company:                                                          * 
 *    Filename:       Ex_Function_Placement.c                           *
 *    Date:           02/01/2005                                        *
 *    File Version:   1.00                                              *
 *    Other Files Required: p30f6014.gld                                *
 *    Tools Used: MPLAB IDE -> 7.01.00                                  *
 *                Compiler  -> 1.30.00                                  *
 *                Assembler -> 1.30.00                                  *
 *                Linker    -> 1.30.00                                  *
 *                                                                      *
 ***********************************************************************/

/* Include the appropriate header (.h) file, depending on device used */
/* Example (for dsPIC30F5013): #include <p30f5013.h>                  */
/* Alternatively include the generic header file, p30fxxxx.h, as shown 
   below.                                                             */

	#include <p30fxxxx.h>
	#include "stdio.h"

void __attribute__((address(0x2000))) func( void )
{}
	
	
int main( void )
{
	long addr;

	addr = ((long) __builtin_tblpage(func) << 16)
	+ __builtin_tbloffset(func);
	printf("0x2000 = 0x%lx\n", addr);

	while ( 1 );
}



/*  The equivalent function definition in assembly language appears below. 
    The .align directive is optional and represents the default alignment 
    in program memory. Use of * as a section name causes the assembler to 
    generate a unique name based on the source file name.

       .section *,address(0x2000),code
       .global _func
       .align 2
_func: return

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -