|
|
View previous topic :: View next topic |
Author |
Message |
Engineer1616
Joined: 30 Nov 2007 Posts: 4
|
writing to arrays which are located in flash program memory |
Posted: Fri Nov 30, 2007 9:07 am |
|
|
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
}
************************************************************* |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Fri Nov 30, 2007 9:21 am |
|
|
Why can you not use write_program_memory(address,dataptr,count) ?
Supply the program memory address you want to write to, the address of the data you want to write, and the byte count.
Perhaps I'm missing something in your question?
Ken |
|
|
Ttelmah Guest
|
|
Posted: Fri Nov 30, 2007 10:00 am |
|
|
He is ignoring the answer already given to him in another thread, which is that a constant array, has a program in front of it, to access the data. He needs to use the 'label address' function, to find where the data is actually stored.
Best Wishes |
|
|
Engineer1616
Joined: 30 Nov 2007 Posts: 4
|
Thank you for your answer but |
Posted: Fri Nov 30, 2007 10:01 am |
|
|
Dear Ken;
I tried alot of things. But I could not manage the write correct data to the flash area. If you have a time you can run my programs and see the wrongs. The aim of the program is that the changing of values in arrays. For example the first element of array is 3. The program must change this value with 1. If you can modify my program like this, it will be very good for me.
Sincerely.
Ken Johnson wrote: | Why can you not use write_program_memory(address,dataptr,count) ?
Supply the program memory address you want to write to, the address of the data you want to write, and the byte count.
Perhaps I'm missing something in your question?
Ken |
|
|
|
|
|
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
|