Constant Array in C

Status
Not open for further replies.

Suraj143

Active Member
In assembly we writing tables in program memory.But in C language we are writing an array in the PIC memory.How can I store my array in program memory without wasting valuable RAM?

Code:
short num=0;
short ssd [10]={0,1,2,3,4,5,6,7,8,9,};

void main (){
	TRISB=0x00;
	PORTB=0x00;

while(1){
	PORTB=ssd[num];
	num++;
	if(num==10)num=0;
	delay_ms(1000);
	}
}
 

In C18 you could use:
const rom short ssd [10]={0,1,2,3,4,5,6,7,8,9,};
 
Just lookup the "const" keyword in your documentation... In hitech I just use const int ssd[] = {1,2,3,4,5,6,7,8};

No need to specify the size of the array as it's initialized as well.
 
Guys I tried like this.

const short ssd[10]={0,1,2,3,4,5,6,7,8,9};

But in debug window it shows it still wasted RAM from 20h onwards.
 
You can find this on page 136 of your manual

According to the mikroC manual it's initialized like this using the code keyword.

const short code ssd[10]={0,1,2,3,4,5,6,7,8,9};
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…