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.

[SOLVED] moving memory from ram to rom

Status
Not open for further replies.

jayanthyk192

Full Member level 3
Full Member level 3
Joined
Sep 17, 2010
Messages
179
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
2,580
Hi,

i'm trying build a (keyboard)piano using a P89V51RD2,right now i'm using only 2 buttons to produce varying frequency clock pulse.output is a quartz crystal.i have made a c program which stores the keys i press and the delay between each.the problem is i'm storing it in the ram => when i switch off the supply all the data is lost.the program size around 3KB,(which i saw by clicking properties of the hex file) and the MC's rom is 64KB.so i wanted to transfer the data to the rom during the time when the program is running.i would appreciate if anyone could give me a c code or the algorithm that can do the job when i press a button.please don't give assembly codes as i'm still in the process of learning it.

thank you.
 

What controller and compiler are you using?
Some compilers have built-in libraries for copying data to the EEPROM directly.
 

use the internal eeprom. read the datasheet. its all in there.
 

The P89V51RD2 has "In-Application Programming method" --> "Several In-Application Programming (IAP) calls are available for use by an application
program to permit selective erasing, reading and programming of Flash sectors,
pages, security bit, configuration bytes, and device id."

https://www.keil.com/dd/docs/datashts/philips/p89v51rd2.pdf
page 23/ 7.2.7
 
@ blind man,thank you,that's exactly as i wanted,could you please tell me how to perform the operation in C.i'm not yet good at writing assembly programs.

@seadolphine2000 take a look at the page no. specified by blind man.it says we can erase and write in the flas memory during an application.
 

Post same C code and we shall have a look on it.

here it is.
Code:
#include<reg51.h>
#define out P1
sbit in1 = P3^0;
sbit in2 = P3^1;
sbit in3 = P3^2;
void delay(int x)
{
int i;
for(i=0;i<=x;i++);
}


void freq(int x,y)
{
int i;
for(i=0;i<y;i++)
 {
 out=0x01;
 delay(x);
 out=0x00;
 delay(x);
 }
}

int main()
{
int i=0,a=200,b=400,B[20],A[20];
while(1)
  
  {
   if(in3==1)
   {
     if(in1==0){freq(a,1);A[i]=1;B[i]=(A[i])+1;}
     if(in1==1){i++;}
     if(in2==0){freq(b,1);A[i]=0;B[i]=(B[i])+1;}
     if(in2==1){i++;}
   }

  for(i=0;i<=20;i++)
  {
    if((B[i])==1){freq(a,A[i]);}
	if(B[i]==0){freq(a,A[i]);}
  }
}
}

the code isn't good,i'm still learning.this is the basic code i wrote.now i need to get the array from ram to rom so that when i switch on the power the tone should be played.this is not the complete code,its only to show what i'm trying to do.
 

Unfortunately is not so simple. There are block of flash:
- first block is block 0 and contain 64kB user code, including your code
- second block is block 1 and contain ISP/IAP routines, including your functions to program errase flash.
In order to have access to IAS routine you have to be enable by clearing BSEL flag. (chapter 7.1.1).

In order to access IAP routine there is PGM_MTP routine at 1ff0h. Jumping to this address with parameters:

Program User Code Input parameters:
R1 = 02h
DPH = memory address MSB
DPL = memory address LSB
ACC = byte to program
Return parameter(s):
ACC = 00 = pass
ACC = !00 = fail

You will program a address in flash in block 0.
There still a problem. To erase you have erase block 0 that contains also application code. => you can only programmed but not erase data. Also you have to be careful not to flash in same sector you are running the program.

It is complicated. If it better in your case to buy an external eeprom and the information in it.

Regarding your program, you will have to replace lines
B=(A)+1;
with write function that you have to code.

Sorry for long time to wait, I thought you are not working on this topic anymore.
 

thank you for the help.i did'nt understand most of it :sad: .but i'll learn it.i guess i'll be using the eeprom.can you please tell me if i can send the data while running the program.
 

Yes , you can sent it while is running, the benefit using EEPROM is that you can read/write/erase data on byte granuality. Good luck.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top