Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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 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,};
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top