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.

Variable specify in flash

Status
Not open for further replies.

Hesam Kamalan

New Member
Hi,
How can i specify a variable in flash or ROM of PIC16F877A. (MicroC compiler)
my variable is "unsigned char temp[1024];" but this is so larg for RAM. i want specify this variable in flash but i don't know how can i.
 
Hesam Kamalan said:
Hi,
How can i specify a variable in flash or ROM of PIC16F877A. (MicroC compiler)
my variable is "unsigned char temp[1024];" but this is so larg for RAM. i want specify this variable in flash but i don't know how can i.

You can't, by definition you can't have a variable in ROM.
 
Thanks Nigle,

I have 512K EEPROM and i want to write 1024 byte of EEPROM in ROM. i write this code :
I2C_Start();
I2C_Wr(0xA2); // send byte via I2C (device address + W)
I2C_Wr(2); // send byte (data address)
I2C_Repeated_Start(); // issue I2C signal repeated start
I2C_Wr(0xA3); // send byte (device address + R)
for(i=0; i<1024; i++)
temp = I2C_Rd(0u); // Read the data (NO acknowledge)
I2C_Stop();

but "temp" is larger than RAM size and error appeared.
how can i write EEPROM data on ROM?
 
As Nigel says, you can't have variables in ROM but you can have constant in ROM.

In C18 you would do,
Code:
rom char RomData[] = "This is character data";
rom char RomHex[]="\x23\x45\x67";                  // will be bytes 0x23,0x45,0x67

Check your compilers manual for something similar.

Alternatively you could do a large table in asm using retlw.

Edit, I just noticed you want to write to your variable. This can be done but you have to write the bit that does the writing in asm. Check out the EEPROM section in the data sheet.

Mike.
 
Last edited:
Nigel Goodwin said:
I suggest you consider what ROM stands for?

READ ONLY memory.

That is why it isn't referred to as ROM anymore. It's flash and can be written to.

Mike.
 
Pommie said:
That is why it isn't referred to as ROM anymore. It's flash and can be written to.

Some is FLASH and some is EEPROM, and some can be reprogrammed within a program, and some can't - depending on the chip - however, self modifying code has always been fraught with danger! :D
 
Nigel Goodwin said:
Some is FLASH and some is EEPROM, and some can be reprogrammed within a program, and some can't - depending on the chip - however, self modifying code has always been fraught with danger! :D

All very true but, in this case the OP is asking about storing data in program memory which is easily done on an 877. However, I do wonder why, as he has the I²C capabilities, he doesn't just stick another serial EEPROM on the same bus.

Mike.
 
Pommie said:
All very true but, in this case the OP is asking about storing data in program memory which is easily done on an 877. However, I do wonder why, as he has the I²C capabilities, he doesn't just stick another serial EEPROM on the same bus.

Would there be any point?, why not just leave it in the existing one? - presumably he's wanting to process it in some way?, but he's never suggested what he's trying to do.

But I would suggest he needs to rethink what he's doing?, I suspect he's a PC programmed and used to fairly unlimited resources.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top