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.

PIC 16F Flash memory writing error...SOS

Status
Not open for further replies.

sivakumarmhn

Newbie level 1
Joined
Jan 10, 2008
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
flash_write pic

Hello !

I am using pic16f873a for a small acess control project. The ids of each persons are to be stored in flash memory of pic. But I have trouble with my code , the memory location once updated is not being rewritten when the function is called again with the same address.. would some one suggest me another code

my code goes like this:

void flash_write ( int address, char data )
{

unsigned char offset;
unsigned char buffer[4]= { 0,0,0,0}; // creates 4 word block for data
int dest_addr = address;
char i = 0;


offset = (unsigned char)(address & 0x03);
dest_addr &= 0xfffc; // initialise the dest_addr to point to the first address in the 4 word block
EEADR=(unsigned char)(dest_addr & 0xff); // load current word from destination
EEADRH=(unsigned char)((dest_addr>>8) & 0xff);
for( i= 0; i <= BLOCK_LAST_BYTE; i++ )
{

WREN=0;
EEPGD = 1; // Read and save whole block
RD=1;
asm("nop");
asm("nop");
buffer= ( EEDATA );
RD = 0;
EEADR++;

}

// DelayMs(20);
EEADR=(unsigned char)(dest_addr & 0xff); // load current word from destination
EEADRH=(unsigned char)((dest_addr>>8) & 0xff);
buffer[offset] = data;


for( i = 0; i <= BLOCK_LAST_BYTE; i++ )
{

EEDATA = buffer;
EEDATH = 0;
EEPGD = 1;
WREN = 1;
//GIE = ;
EECON2 = 0x55;
EECON2 = 0xAA;
WR = 1;
asm("nop");
asm("nop");
asm("nop");
WREN = 0;
WR = 0;
//GIE =
EEADR++;


}

while ( WRERR == 1 ){;}
while ( EEIF == 1 ){;}


}
 

pic16f writing to flash memory

If you are using Hi-Tech compiler, look in the include file 'pic.h'
You will find function protoypes and macros to read and write flash and eeprom which you can call.
I think you may have to erase the flash before writing to it?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top