CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how to place data in rom on runtime?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mrpicing



Joined: 22 Oct 2005
Posts: 20

View user's profile Send private message

how to place data in rom on runtime?
PostPosted: Tue Jul 31, 2007 1:35 am     Reply with quote

AOA. Smile
I m using PIC18F452 on 10MHz.
I want to place serially comming data in rom on runtime.
Data is 2Kbyte. Its comming through HW serial port.
I want to place this data a pre defined arrays 1K each.
I tried to use "write_program_eeprom" but is results invalid data. Confused
Have any body done it or have any code snippt.
Thanks in Advance. Smile
Ttelmah
Guest







PostPosted: Tue Jul 31, 2007 7:15 am     Reply with quote

There are two separate problems.
Write_program_eeprom, _is_ the tool to use. However the first problem is wanting to put the data in 'arrays'.
On the PIC, when 'constant' data is placed in an array, the program to access this is placed in front of the actual data. If you write directly to where the array is stored, you overwrite this program...
You have two choices:
1) Just declare a memory area using the ORG statement, the size you require, write the data into this, and then access the data using the read_program_eeprom function.
2) Declare an array as you have, and write the data to where the real data is stored. The compiler directive 'label_address', returns the actual address of the data inside the array.

The second problem, is to remember that on an '18' chip, each 'word' of memory, can store two bytes. Each pair of incoming bytes, needs to be combined to form a 16bit value, and this needs to be writen to the ROM.
The function 'write_program_memory', allows the memory to be accessed in bytes or in larger blocks. It'd be better to use this, and not write single bytes,but write a small array, whose size is determined by the value 'FLASH_WRITE_SIZE'. Even better, write an array with the size determined by the flash erase size. Either of these will massively reduce the number of erase cycles involved in the write, and extend the memory life, which will otherwise be very quickly used. Writing 'byte at a time', there will be a block erase, and a write, for every byte transferred. The cell life on the program memory, only has a specified minimum life of 10000 cycles. With 2KB of data, one fifth of this life will be used in one go...
Instead, erasing and writing in 64byte blocks, reduces this to only 250 cycles (writes are in 8byte blocks on the chip you mention).

Best Wishes
Engineer1616



Joined: 30 Nov 2007
Posts: 4

View user's profile Send private message

Writing to flash program memory
PostPosted: Fri Nov 30, 2007 8:57 am     Reply with quote

Hi there;
I have a big problem. I want to change the elements of array which must be located in flash program memory by the program. The problem is that I could not use "write_program_memory" code for writing to flash memory. At the same time I have tried to use assembly rutine, I could not manage it.
For example;
.
.
#ORG 0x0005,0x000A
int const avans[4] ={3,4,5,6};
.
.
This command line is placed in flash program memory like this;

Adress Opcode Assembly

0x0006 3403 retlw 0X03
0x0007 3404 retlw 0x04
0x0008 3405 retlw 0x05
0x0009 3406 retlw 0x06

I think opcode is a key for us. If I use directly this opcodes to the flash program memory I can change the elements of the array. Is it right or not ? I could not give a constant adress when I use this kind of command line; "int avans[4] ={3,4,5,6};" instead of "int const avans[4] ={3,4,5,6};" Because in the second from array will be placed in ram area. And array is placed in anywhere in flash memory How can I give constant adresses to the arrays?
.
I' m giving my source codes to you. If you help me for solving the problems I will be very happy.

************************C rutines******************************

#include <16F877A.h>
#device *=16 ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#BYTE EEDATA = 0X10C
#BYTE EEADR = 0X10D
#BYTE EEDATH = 0X10E
#BYTE EEADRH = 0X10F
#BYTE EECON2 = 0X18D
#BIT EECON1EEPGD = 0X18C.7
#BIT EECON1WREN = 0X18C.2
#BIT EECON1WR = 0X18C.1
#BIT STATUS5 = 0X03.5
#BIT STATUS6 = 0X03.6
#ORG 0x0005,0x000A
int const avans[4] ={3,4,5,6};
#ORG 0x000B
void main() {
disable_interrupts(GLOBAL);
write_program_memory(0X0006, 1, 2);
delay_ms(100);
}

*************************Assembly rutine***********************

#include <16F877A.h>
#device *=16 ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#BYTE EEDATA = 0X10C
#BYTE EEADR = 0X10D
#BYTE EEDATH = 0X10E
#BYTE EEADRH = 0X10F
#BYTE EECON2 = 0X18D
#BIT EECON1EEPGD = 0X18C.7
#BIT EECON1WREN = 0X18C.2
#BIT EECON1WR = 0X18C.1
#BIT STATUS5 = 0X03.5
#BIT STATUS6 = 0X03.6
#ORG 0x0005,0x000A
int const avans[4] ={3,4,5,6};
#ORG 0x000B
void main() {
disable_interrupts(GLOBAL);
#asm
BSF 0X03,6
BCF 0X03,5
MOVLW 0X00
MOVWF EEADRH
MOVLW 0X06
MOVWF EEADR
MOVLW 0x01
MOVWF EEDATA
MOVLW 0x34
MOVWF EEDATH
BSF 0X03,6
BSF 0X03,5
BSF 0X18C,7
BSF 0X18C,2
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF 0X18C,1
NOP
NOP
BCF 0X18C,2
BCF 0X03,5
INCF EEADR,1
MOVLW 0x02
MOVWF EEDATA
MOVLW 0x34
MOVWF EEDATH
BSF 0X03,5
BSF 0X03,6
BSF 0X18C,7
BSF 0X18C,2
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF 0X18C,1
NOP
NOP
BCF 0X18C,2
BCF 0X03,5
INCF EEADR,1
MOVLW 0x03
MOVWF EEDATA
MOVLW 0x34
MOVWF EEDATH
BSF 0X03,5
BSF 0X03,6
BSF 0X18C,7
BSF 0X18C,2
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF 0X18C,1
NOP
NOP
BCF 0X18C,2
BCF 0X03,5
INCF EEADR,1
MOVLW 0x04
MOVWF EEDATA
MOVLW 0x34
MOVWF EEDATH
BSF 0X03,5
BSF 0X03,6
BSF 0X18C,7
BSF 0X18C,2
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF 0X18C,1
NOP
NOP
BCF 0X18C,2
#endasm
}
*************************************************************
Ttelmah
Guest







PostPosted: Fri Nov 30, 2007 9:54 am     Reply with quote

The same comment applies. The space you are allocating is not large enough for the data _plus the program to retrieve it_. If you write retlw instructions at the start of the area, you will overwrite the program, and will no longer be able to retrieve the data.
I have already posted how to get the address, which the write_program_eeprom function (or your own assembler), needs to use to access the actual data.

Best Wishes
Engineer1616



Joined: 30 Nov 2007
Posts: 4

View user's profile Send private message

Thank you
PostPosted: Fri Nov 30, 2007 11:05 am     Reply with quote

I' m sorry because I' m new in this forum so I could not see your answer. I will try it.
Ttelmah wrote:
The same comment applies. The space you are allocating is not large enough for the data _plus the program to retrieve it_. If you write retlw instructions at the start of the area, you will overwrite the program, and will no longer be able to retrieve the data.
I have already posted how to get the address, which the write_program_eeprom function (or your own assembler), needs to use to access the actual data.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group