Flash Mem Library

General discussion on mikroPascal.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Flash Mem Library

#1 Post by yo2lio » 27 Feb 2007 08:55

This is a implementations of Flash Library for PIC18F MCU, writed by me.

Explanation of procedures and functions :

{ Erase ...( depends of MCU ) block at address ... (64 or 1024 bytes, see datasheet of MCU)}
{ For PIC18F452,Pic18F4520, ..., PIC18FxxJxx }

Code: Select all

procedure Flash_Mem_Erase(address : longint);
{ Write 8 bytes block at address ... }
{ Only for PIC18Fxx2 series, see datasheet of MCU }

Code: Select all

procedure Flash_Mem_Write_8(address : longint; var data : array[8] of byte);  


{ Write 64 bytes block at address ... }
{ Only for PIC18F4520, ..., PIC18FxxJxx, see datasheet of MCU }

Code: Select all

procedure Flash_Mem_Write_64(address : longint; var data : array[64] of byte); 
{ Erase and write 64 bytes 8x8 block at address ... }
{ Only for PIC18Fxx2 series, see datasheet of MCU }

Code: Select all

procedure Flash_Mem_Erase_Write_64(address : longint; var data : array[64] of byte);
{ Erase and write 64 bytes block at address ... }
{ Only for PIC18F4520 series, see datasheet of MCU }

Code: Select all

procedure Flash_Mem_Erase_Write_64A(address : longint; var data : array[64] of byte);
{ Erase and write 1024 bytes block at address ... }
{ Only for PIC18FxxJxx, see datasheet of MCU }

Code: Select all

procedure Flash_Mem_Erase_Write_1024(address : longint; var data : array[1024] of byte); 
{ Read 1 byte at address ... }
{ For all type of MCU }

Code: Select all

function Flash_Mem_Read(address : longint): byte;
{ Read N bytes (user can define this) at address ... and put them in data var... }
{ For all type of MCU }

Code: Select all

procedure Flash_Mem_Read_N_Bytes(address : longint; var data : array[max_read] of byte; N : word);

User must choose between this procedures and functions depending of MCU.

The souurce cod You can download here:

http://www.microelemente.ro/Flash_Mem_Library.zip

Enjoy

Best regards Florin Medrea

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 28 Feb 2007 08:49

Thanks Florin, i am very happy you are providing these well documented source-provided library's , if we continue with that the ME-team can concentrate on the compiler itself, together we will be stronger!

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#3 Post by janni » 01 Mar 2007 00:05

All true. It's a very good library.

Donald Shimoda
Posts: 553
Joined: 27 Feb 2006 17:00
Location: Argentina
Contact:

#4 Post by Donald Shimoda » 03 Mar 2007 16:39

Indeed, excelent libraries. I hope can help you to enhance every work you share. :)
Donald Shimoda.

homermike
Posts: 8
Joined: 12 Mar 2011 12:55

Re: Flash Mem Library

#5 Post by homermike » 03 Apr 2011 11:07

hello good day... it seems that this topic is too long ago... but thinking this was useful..

i tried and convert it to mikroC and have success in compiling it.. but it doesn't have the right result..

these are the codes in MikroC:
=============================
void Flash_Mem_Erase_Write_64A(long address, int data[64]) { //only for PIC18F4520 series, see datasheet of MCU
int i,flag; // erase and write 64 bytes block at address ...

flag = INTCON & 0x80; // save state of GIE bit
INTCON.GIE = 0; // disable interrupts
TBLPTRL = Lo(address);
TBLPTRH = Hi(address);
TBLPTRU = Higher(address);
EECON1 = EECON1 | 0x80; // for compatibility J series with standard MCU
EECON1 = EECON1 & 0xBF; // for compatibility J series with standard MCU
EECON1.WREN = 1;
EECON1.FREE = 1;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
asm {
nop
TBLRD*-
nop
}
FSR0L = Lo(data);
FSR0H = Hi(data);
while(i<64) {
TABLAT = POSTINC0;
asm {
nop
TBLWT+*
nop
}
i++; }
EECON1 = EECON1 | 0x80;
EECON1 = EECON1 & 0xBF;
EECON1.WREN = 1;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
EECON1.WREN = 0 ;
INTCON = INTCON | flag; // enable interrupts with first state of GIE bit
}
=============================

when i tried this one... and checked the FLASH MEM.. it only writes 0xFF in the address specified...

here it says that this is for PIC18F4520... but im using PIC18F4620 now...
is it ok?

any help is so much appreciated... thanks for the post...

Post Reply

Return to “mikroPascal General”