C 소스 코드

#include <stdio.h> 

// 프로그램 메모리 영역에 상수 위치 시키기 
const unsigned __attribute__ ((space(psv), address(0x2000))) 
    table[10] = {0,1,2,3,4,5,6,7,8,9};

// 데이터 메모리 영역에 변수 위치 시키기 
int __attribute__ ((address(0x900))) x = 5; 

// 프로그램 메모리 영역에 함수 위치 시키기 
int __attribute__ ((address(0x2100))) square(int a);

int main(void) 

    int i, y;

    y = square(x); 
    printf("square = %d\n", y);

    for(i=0;i<10;i++) 
    { 
        printf("table[%d] = %d\n", i, table[i]); 
    } 
    while(1); 


// square 함수 정의 
int square(int a) 

    return (a * a); 
}


결과
Watch창의 Address 필드에 P라고 되어있는 부분은 프로그램 메모리 영역이라는 표시이다.

'PIC' 카테고리의 다른 글

C30 컴파일러의 I/O 포트 액세스  (0) 2011.04.04
C30 컴파일러 속성(Attribute)  (1) 2011.04.01
MPLAB IDE - C30 컴파일러 사용 [PIC24FJ128GA010]  (0) 2011.03.31

+ Recent posts