Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to modify variable stored in rom?

Status
Not open for further replies.

Strike_UN

Junior Member level 1
Joined
Mar 9, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,372
hello
i had to store array in the Rom cause it took alot of memory space in the Ram and now i wanna change the array element while its being saved in the Rom
or call it in ram element by element to change it
how i do that?
and thx in advance
 

It depends largely on the exact device you are utilizing in your design.

What is it exactly, make and model?

The feature you are referring to is In Application Programming (IAP), some device support this feature others do not.

BigDog
 

iam currently using pic18F252 but i can change to any other 18 pic if it will help me solve this problem
 

It is definitely doable.

Are you coding in Assembly or C Language? If C Language, what compiler are you utilizing?

Reference: PIC18FXX2 Datasheet, Section: 5.0 FLASH PROGRAM MEMORY, Pg 55

5.0 FLASH PROGRAM MEMORY

The FLASH Program Memory is readable, writable,
and erasable during normal operation over the entire
VDD range.

A read from program memory is executed on one byte
at a time. A write to program memory is executed on
blocks of 8 bytes at a time. Program memory is erased
in blocks of 64 bytes at a time. A bulk erase operation
may not be issued from user code.
Writing or erasing program memory will cease instruction
fetches until the operation is complete. The program
memory cannot be accessed during the write or
erase, therefore, code cannot execute. An internal programming
timer terminates program memory writes
and erases.

A value written to program memory does not need to be
a valid instruction. Executing a program memory
location that forms an invalid instruction results in a
NOP.


The technique is often used in Bootloaders, which load a program's code into flash from within the bootloader application.

BigDog
 

iam using mikroc in coding and compiling
and if its possible can u show me example coding of how to do it and thx in advance
 
Last edited:

The MikroC Pro Compiler has FLASH memory routines within its library.

Reference: MikroC PRO for PIC Compiler User Manual, Section: FLASH MEMORY LIBRARY, Pg. 321

FLASH MEMORY LIBRARY

This library provides routines for accessing microcontroller Flash memory. Note that
prototypes differ for PIC16 and PIC18 families.

Note: Due to the P16/P18 family flash specifics, flash library is MCU dependent.
Since the P18 family differ significantlly in number of bytes that can be erased
and/or written to specific MCUs, the appropirate suffix is added to the names of
functions in order to make it easier to use them. Flash memory operations are MCU
dependent :

1. Read operation supported. For this group of MCU's only read function is implemented.

2. Read and Write operations supported (write is executed as erase-and-write). For
this group of MCU's read and write functions are implemented. Note that write
operation which is executed as erase-and-write, may write less bytes than it
erases.

3. Read, Write and Erase operations supported. For this group of MCU's read,
write and erase functions are implemented. Further more, flash memory block
has to be erased prior to writting (write operation is not executed as erase-andwrite).

Please refer to MCU datasheet before using flash library.

Example Code:
Code:
char i = 0;
unsigned int addr, data_, dataAR[4][4] = {{0x3FAA+0,  0x3FAA+1,  0x3FAA+2,  0x3FAA+3},
                                          {0x3FAA+4,  0x3FAA+5,  0x3FAA+6,  0x3FAA+7},
                                          {0x3FAA+8,  0x3FAA+9,  0x3FAA+10, 0x3FAA+11},
                                          {0x3FAA+12, 0x3FAA+13, 0x3FAA+14, 0x3FAA+15}};

void main() {
  ANSEL  = 0;                         // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                       // Disable comparators
  C2ON_bit = 0;
  PORTB = 0;                          // Initial PORTB value
  TRISB = 0;                          // Set PORTB as output
  PORTC = 0;                          // Initial PORTC value
  TRISC = 0;                          // Set PORTC as output
  Delay_ms(500);

  // All block writes
  // to program memory are done as 16-word erase by
  // eight-word write operations. The write operation is
  // edge-aligned and cannot occur across boundaries.
  // Therefore it is recommended to perform flash writes in 16-word chunks.
  // That is why lower 4 bits of start address [3:0] must be zero.
  // Since FLASH_Write routine performs writes in 4-word chunks,
  // we need to call it 4 times in a row.
  addr = 0x0430;                      // starting Flash address, valid for P16F887
  for (i = 0; i < 4; i++){            // Write some data to Flash
    Delay_ms(100);
    FLASH_Write(addr+i*4, dataAR[i]);
  }
  Delay_ms(500);

  addr = 0x0430;
  for (i = 0; i < 16; i++){
    data_ = FLASH_Read(addr++);       // P16's FLASH is 14-bit wide, so
    Delay_us(10);                     //   two MSB's will always be '00'
    PORTB = data_;                    // Display data on PORTB (LS Byte)
    PORTC = data_ >> 8;               // and PORTC (MS Byte)
    Delay_ms(500);
  }
}

BigDog
 

sorry but iam kinda beginner so i still dont get it
can u show it to me how to do in my program?
i identified array like that
Code:
const unsigned long sbox1[256]={0xd1310ba6, 0x98dfb5ac,  0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
    0xba7c9045, 0xf12c7f99,  0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
    0x636920d8, 0x71574e69,  0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
    0x718bcd58, 0x82154aee,  0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
    0xc5d1b023, 0x286085f0,  0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e,
    0x6c9e0e8b, 0xb01e8a3e,  0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
    0xe65525f3, 0xaa55ab94,  0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6,
    0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411,  0x636fbc2a,
    0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33,  0x6c24cf5c,
    0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b,  0x66282193,
    0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d,  0xe98575b1,
    0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3,  0x83f44239,
    0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842,  0xf6e96c9a,
    0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728,  0xab5133a3,
    0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d,  0x39af0176,
    0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3,  0x3b8b5ebe,
    0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62,  0x363f7706,
    0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3,  0x49f1c09b,
    0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a,  0xb6794c3b,
    0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2,  0x196a2463,
    0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f,  0x9b30952c,
    0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807,  0x192e4bb3,
    0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd,  0x1a60320a,
    0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8,  0xdb3222f8,
    0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa,  0xfd238760,
    0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e,  0xdf1769db,
    0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0,  0xbbca58c8,
    0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c,  0x2dd1d35b,
    0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da,  0xa4cb7e33,
    0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe,  0x2bf11fb4,
    0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0,  0xafc725e0,
    0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812,  0x900df01c,
    0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218,  0xbe0e1777,
    0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6,  0xce89e299,
    0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266,  0x80957705,
    0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5,  0xfb9d35cf,
    0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d,  0x2071b35e,
    0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d,  0x59dfa6aa,
    0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376,  0x6295cfa9,
    0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052,  0x9a532915,
    0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5,  0x571be91f,
    0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e,  0xc5855664,
    0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a};
now i need to change every element according to some calculation and thx in advance
 

Re: how to modify array stored in rom

You can't change ROM from your program; you can't use ROM as RAM. That's why it's called READ ONLY memory.
 

Sooo u cant for example call it in ram make the changes u want and then store it back in Rom thats not possible?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top