Jump to content
dgille

Pre-loading Processor Ee

Recommended Posts

#pragma DATA _EEPROM

 

Hello all,

I am attempting to load many locations in the device EE memory. I am getting a compile error "File.c(54): error: failure" (where line 54 holds the input string which loads the EE locations).

 

The line looks like:

#pragma DATA _EEPROM VAR1, ... 0xFF, 0xFF,VAR25,\

VAR26, ...., VAR50,\

VAR51, ..., VAR54,\

VAR55, ..., VAR55,\

VAR56, ..., VAR60

 

The VARs are defined with "#define" statements previously to the pragma. It appears that there is a limit to how many locations can be pre-programmed or a limit on the input string length. If I remove 12 of the data from the pragma statement, it will compile and load the EE properly.

 

Does someone know the answer?

 

Thank you in advance,

D

Share this post


Link to post
Share on other sites

Edit: Corrections below, If you read this before the edit date at the bottom, please re-read it

You are satisfied the EEPROM is being programmed correctly if you shorten your multi-line #pragma by 12 values and have verified the EEPROM contents, either in the simulator, or using your programmer software?

 

#pragma DATA _EEPROM VAR1, ... 0xFF, 0xFF,VAR25,\
VAR26, ...., VAR50,\
VAR51, ..., VAR54,\
VAR55, ..., VAR55,\
VAR56, ..., VAR60

The VARs are defined with "#define" statements previously to the pragma.

 

I presume VAR1 .. VAR60 resolve to unsigned bytes and the 0xFF values are padding or reserved space.

 

You have hit a compiler limit for continuation lines.

EDIT: I *HAD* a proposed work around which I will leave below for the entertainment of those of you who have already got their scars from banging their head against a brick wall. It WON'T work as the compiler doesn't evaluate expressions used as the address parameter of #pragma data!

 

From the manual:

#pragma DATA

Syntax:

#pragma DATA addr, d1, d2, ...

or

#pragma DATA addr, “abcdefg1”, “abcdefg2”, ...

Elements:

addr is any valid code memory address.

d1, d2... are 8-bit integer constants.

“abcdefgX” is a character string, the ASCII values of the

charcters will be stored as 8 bit value.

Purpose:

User data can be placed at a specific location using this construct.

In particular, this can be used to specify target configuration word

or to set some calibration/configuration data into on-chip eeprom.

 

There is NOTHING magical about #pragma DATA _EEPROM and you can use multiple #pragma DATA lines to do the job. _EEPROM is just a constant for the base address of the EEPROM when its mapped into the programming address space and is defined in PxxFxxxx.h(No thats C2C!) PICxxFxxxx.h.

/////////////////////////////////////////////////
// EEPROM Base Address when programing
/////////////////////////////////////////////////
// To initialise EEPROM when a device is programmed
// use #pragma DATA _EEPROM, 12, 34, 56 
#define _EEPROM			   0x2100

 

Edit: So far so good, I was just quoting from the manual and include files. but the next bit is broken.

 

DON'T use continuation lines for this. You need to break up your EEPROM initialisation into separate lines with a sensible number of bytes on each line.

I strongly recommend using 16 bytes per line, but if your variables naturally break into smaller blocks AND YOU HAVE CONSTANTS DEFINED FOR THEIR OFFSETS within the EEPROM, you could vary the line length.

 

E.g.

#pragma DATA _EEPROM+0x00, <byte1>, <byte2>, ... <byte16>
#pragma DATA _EEPROM+0x10, <byte17>, <byte18>, ... <byte32>
...
#pragma DATA _EEPROM+0xF0, <byte240>, <byte241>, ... <byte256>

 

I hope that helps :-)

Edit: well that was no use or help at all. I apologise profusely for posting untested code. My fault and very lazy of me as well. <eats crow>

 

Lastly, many technically skilled people in countries where English is the national language are less likely to respond to:

Does someone know the answer?

Thank you in advance,

as the reaction is often: Thanks in advance is rarely followed by any appreciation or acknowledgement afterwards and Yes, certainly there is at least one person somewhere who knows the answer. Fortunately this forum is very friendly, but even so I would be inclined to use 'I would be grateful for any assistance.' then thank everybody afterwards. If you are visiting some of the more 'touchy' electronics groups and forums on other sites, *please* remember this ;-) Edited by IanM

Share this post


Link to post
Share on other sites

Hi Ian,

 

I have always found that the preprocessor for pragma never likes to do arithmetic for adding an offset to a symbol.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
I have always found that the preprocessor for pragma never likes to do arithmetic for adding an offset to a symbol.

AAAGH!!!!, If that is in fact the case (and you are usually spot on), its a serious bug or implementation deficiency.

 

The arithmetic *has* to be done at compile time and putting it in a #define isn't going to get us out of the mess as the arithmetic is just deferred till the symbol is used.

 

This *TOTALLY* breaks portability as one would need to hard code EEPROM addresses.

 

I will look into this in more detail.

...

EDIT: LATER . . .

 

#pragma DATA _EEPROM+0x00, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#pragma DATA _EEPROM+0x10, 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32

gives

"C:\PROGRAM FILES\SOURCEBOOST\boostc_pic16.exe" -t PIC16F88 SourceBoost1.c

...

SourceBoost1.c

C:\My Documents\SourceBoost1.c(18): warning: unknown or invalid pragma (ignored)

C:\My Documents\SourceBoost1.c(19): warning: unknown or invalid pragma (ignored)

 

success

Done

 

Reynard is (as usual) correct, it doesn't work. B)

 

That's just gotta be a bug as

#pragma DATA _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

evaluates to the correct configuration (verified in the Hex file) so the preprocessor *can* do maths on the data values at compile time *AND* is calculating and storing WORDS, not bytes (the manual is wrong) so can definitely handle the full unsigned int number range.

 

I'll edit my post accordingly <eats crow> and try to dream up and test a workaround other than this really *F*UGLY* one.

//WARNING: NON-PORTABLE CODE FOLLOWS
//#pragma DATA _EEPROM+0xnn, <data ... >
//does not work as the first parameter is not evaluated.
// For this PIC _EEDATA is 0x2100 and the address
// of each line below must be manually incremented.
// 
#pragma DATA 0x2100, <byte1>, <byte2>, ... <byte16>
#pragma DATA 0x2110, <byte17>, <byte18>, ... <byte32>
...
#pragma DATA 0x21F0, <byte240>, <byte241>, ... <byte256>
//
//END WARNING: AFTER NON-PORTABLE CODE

Edited by IanM

Share this post


Link to post
Share on other sites

Hi,

 

What is the actual problem?

 

This seems to work for me:

 

#pragma DATA _EEPROM,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

 

Unless it was a typo the OP missed the comma after _EEPROM

 

Cheers

 

davidb

Share this post


Link to post
Share on other sites

Long lines work OK for me too.

 

#pragma DATA _EEPROM,\
var0,var1,var2,var3,var4,var5,var6,var7,var8,var9,\
var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,\
var20,var21,var22,var23,var24,var25,var26,var27,var28,var29,\
var30,var31,var32,var33,var34,var35,var36,var37,var38,var39,\
var40,var41,var42,var43,var44,var45,var46,var47,var48,var49,\
var50,var51,var52,var53,var54,var55,var56,var57,var58,var59,\
var60,var61,var62,var63,var64,var65,var66,var67,var68,var69,\
var0,var1,var2,var3,var4,var5,var6,var7,var8,var9,\
var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,\
var20,var21,var22,var23,var24,var25,var26,var27,var28,var29,\
var30,var31,var32,var33,var34,var35,var36,var37,var38,var39,\
var40,var41,var42,var43,var44,var45,var46,var47,var48,var49,\
var50,var51,var52,var53,var54,var55,var56,var57,var58,var59,\
var60,var61,var62,var63,var64,var65,var66,var67,var68,var69,\
var0,var1,var2,var3,var4,var5,var6,var7,var8,var9,\
var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,\
var20,var21,var22,var23,var24,var25,var26,var27,var28,var29,\
var30,var31,var32,var33,var34,var35,var36,var37,var38,var39,\
var40,var41,var42,var43,var44,var45,var46,var47,var48,var49,\
var50,var51,var52,var53,var54,var55,var56,var57,var58,var59,\
var60,var61,var62,var63,var64,var65,var66,var67,var68,var69,\
var0,var1,var2,var3,var4,var5,var6,var7,var8,var9,\
var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,\
var20,var21,var22,var23,var24,var25,var26,var27,var28,var29,\
var30,var31,var32,var33,var34,var35,var36,var37,var38,var39,\
var40,var41,var42,var43,var44,var45,var46,var47,var48,var49,\
var50,var51,var52,var53,var54,var55,var56,var57,var58,var59,\
var60,var61,var62,var63,var64,var65,var66,var67,var68,var69

 

Reynard

Share this post


Link to post
Share on other sites
Edit: Corrections below, If you read this before the edit date at the bottom, please re-read it

You are satisfied the EEPROM is being programmed correctly if you shorten your multi-line #pragma by 12 values and have verified the EEPROM contents, either in the simulator, or using your programmer software?

 

#pragma DATA _EEPROM VAR1, ... 0xFF, 0xFF,VAR25,\
VAR26, ...., VAR50,\
VAR51, ..., VAR54,\
VAR55, ..., VAR55,\
VAR56, ..., VAR60

The VARs are defined with "#define" statements previously to the pragma.

 

I presume VAR1 .. VAR60 resolve to unsigned bytes and the 0xFF values are padding or reserved space.

 

You have hit a compiler limit for continuation lines.

EDIT: I *HAD* a proposed work around which I will leave below for the entertainment of those of you who have already got their scars from banging their head against a brick wall. It WON'T work as the compiler doesn't evaluate expressions used as the address parameter of #pragma data!

 

From the manual:

#pragma DATA

Syntax:

#pragma DATA addr, d1, d2, ...

or

#pragma DATA addr, “abcdefg1”, “abcdefg2”, ...

Elements:

addr is any valid code memory address.

d1, d2... are 8-bit integer constants.

“abcdefgX” is a character string, the ASCII values of the

charcters will be stored as 8 bit value.

Purpose:

User data can be placed at a specific location using this construct.

In particular, this can be used to specify target configuration word

or to set some calibration/configuration data into on-chip eeprom.

 

There is NOTHING magical about #pragma DATA _EEPROM and you can use multiple #pragma DATA lines to do the job. _EEPROM is just a constant for the base address of the EEPROM when its mapped into the programming address space and is defined in PxxFxxxx.h

/////////////////////////////////////////////////
// EEPROM Base Address when programing
/////////////////////////////////////////////////
// To initialise EEPROM when a device is programmed
// use #pragma DATA _EEPROM, 12, 34, 56 
#define _EEPROM			   0x2100

 

Edit: So far so good, I was just quoting from the manual and include files. but the next bit is broken.

 

DON'T use continuation lines for this. You need to break up your EEPROM initialisation into separate lines with a sensible number of bytes on each line.

I strongly recommend using 16 bytes per line, but if your variables naturally break into smaller blocks AND YOU HAVE CONSTANTS DEFINED FOR THEIR OFFSETS within the EEPROM, you could vary the line length.

 

E.g.

#pragma DATA _EEPROM+0x00, <byte1>, <byte2>, ... <byte16>
#pragma DATA _EEPROM+0x10, <byte17>, <byte18>, ... <byte32>
...
#pragma DATA _EEPROM+0xF0, <byte240>, <byte241>, ... <byte256>

 

I hope that helps :-)

Edit: well that was no use or help at all. I apologise profusely for posting untested code. My fault and very lazy of me as well. <eats crow>

 

Lastly, many technically skilled people in countries where English is the national language are less likely to respond to:

Does someone know the answer?

Thank you in advance,

as the reaction is often: Thanks in advance is rarely followed by any appreciation or acknowledgement afterwards and Yes, certainly there is at least one person somewhere who knows the answer. Fortunately this forum is very friendly, but even so I would be inclined to use 'I would be grateful for any assistance.' then thank everybody afterwards. If you are visiting some of the more 'touchy' electronics groups and forums on other sites, *please* remember this ;-)

 

 

Thank you very much for the reply! I've learned much and your suggestion will get me back in business.

All the best,

D

Share this post


Link to post
Share on other sites
...

Thank you very much for the reply! I've learned much and your suggestion will get me back in business.

All the best,

D

 

I'm just sorry I didn't provide fully tested code initially and very glad you found my post helpful. As it was originally written before Reynard kindly corrected me, it would have been most unhelpful and in fact misleading and I am thankful he caught my mistake before I wasted your time.

 

Here is tested (PIC16F88) code for easier and *somewhat* more portable EEPROM initialisation. It will detect if the EEPROM is at the wrong address and then you would have to edit in the new base address. On PIC18, it will currently only work for the first 256 bytes of the EEPROM.

 

Best viewed in 1024x768 mode or higher to avoid line wrap.

// ***** EEPROM offset fixup *****
// for #pragma data <addr>,< ... > maths problem in <addr>.
//
#ifndef _EEPROM
#error "Error: Cannot define EEPROM_ROW(hh) without any EEPROM!"
#endif
// Change the 0x21... in the first, fourth and fifth lines below for other EEPROM base addresses.
#if _EEPROM != 0x2100 
#error "Error: EEPROM_ROW(hh) cannot be defined (Wrong EEPROM base)"
#else  
#warning "EEPROM_ROW(hh) expands to 0x21hh *BUT* hh *MUST* be two HEX digits!"
#define EEPROM_ROW( hh ) 0x21 ## hh
#endif
// ***** end of EEPROM offset fixup *****

// Test data for EEPROM
#pragma DATA EEPROM_ROW(00), 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#pragma DATA EEPROM_ROW(10), 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
// ...
#pragma DATA EEPROM_ROW(F0), 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256

 

I hope that's some use to you . . .

 

Ian M

Edited by IanM

Share this post


Link to post
Share on other sites
I have always found that the preprocessor for pragma never likes to do arithmetic for adding an offset to a symbol.

AAAGH!!!!, If that is in fact the case (and you are usually spot on), its a serious bug or implementation deficiency.

 

The arithmetic *has* to be done at compile time and putting it in a #define isn't going to get us out of the mess as the arithmetic is just deferred till the symbol is used.

 

This *TOTALLY* breaks portability as one would need to hard code EEPROM addresses.

 

I will look into this in more detail.

...

EDIT: LATER . . .

 

#pragma DATA _EEPROM+0x00, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#pragma DATA _EEPROM+0x10, 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32

gives

"C:\PROGRAM FILES\SOURCEBOOST\boostc_pic16.exe" -t PIC16F88 SourceBoost1.c

...

SourceBoost1.c

C:\My Documents\SourceBoost1.c(18): warning: unknown or invalid pragma (ignored)

C:\My Documents\SourceBoost1.c(19): warning: unknown or invalid pragma (ignored)

 

success

Done

 

Reynard is (as usual) correct, it doesn't work. B)

 

That's just gotta be a bug as

#pragma DATA _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

evaluates to the correct configuration (verified in the Hex file) so the preprocessor *can* do maths on the data values at compile time *AND* is calculating and storing WORDS, not bytes (the manual is wrong) so can definitely handle the full unsigned int number range.

 

I'll edit my post accordingly <eats crow> and try to dream up and test a workaround other than this really *F*UGLY* one.

//WARNING: NON-PORTABLE CODE FOLLOWS
//#pragma DATA _EEPROM+0xnn, <data ... >
//does not work as the first parameter is not evaluated.
// For this PIC _EEDATA is 0x2100 and the address
// of each line below must be manually incremented.
// 
#pragma DATA 0x2100, <byte1>, <byte2>, ... <byte16>
#pragma DATA 0x2110, <byte17>, <byte18>, ... <byte32>
...
#pragma DATA 0x21F0, <byte240>, <byte241>, ... <byte256>
//
//END WARNING: AFTER NON-PORTABLE CODE

 

 

 

You guys seem to have a better grip on the preprocessor than I do perhaps you would be willing to fix/improve the article at: http://www.opencircuits.com/The_C_Preproce...d_pound_Defines

Share this post


Link to post
Share on other sites

I've done a bit of research and imported all the #define _EEPROM lines in the header files and sizes from Microchip into a database. Here is the resulting report:

BoostC supported PICs By EEPROM address and size

Based on BoostC 6.96 header files PICxxxxxx.h cross referenced with PIC 12,16 and 18 families exported from the Microchip product selector on 3/10/2009.

 

Addr: -none- Size: 0

12C671, 12C672, 12HV609, 12HV615, 16C432, 16C433, 16C554, 16C557, 16C558, 16C61, 16C62, 16C620, 16C620A, 16C621, 16C621A, 16C622, 16C622A, 16C62A, 16C62B, 16C63, 16C63A, 16C64, 16C642, 16C64A, 16C65, 16C65A, 16C65B, 16C66, 16C662, 16C67, 16C71, 16C710, 16C711, 16C712, 16C715, 16C716, 16C717, 16C72, 16C72A, 16C73, 16C73A, 16C73B, 16C74, 16C745, 16C74A, 16C74B, 16C76, 16C765, 16C77, 16C770, 16C771, 16C773, 16C774, 16C781, 16C782, 16C84, 16C923, 16C924, 16C925, 16C926, 16CE623, 16CE624, 16CE625, 16CR62, 16CR620A, 16CR63, 16CR64, 16CR65, 16CR72, 16CR83, 16CR84, 16HV610, 16HV616, 18C242, 18C252, 18C452, 18C601, 18C658, 18C801, 18C858, 18F84J15, 12F609, 12F615, 16F610, 16F616, 16F716, 16F72, 16F722, 16F723, 16F724, 16F726, 16F727, 16F73, 16F737, 16F74, 16F747, 16F76, 16F767, 16F77, 16F777, 18F2410, 18F2450, 18F24J10, 18F2510, 18F2515, 18F25J10, 18F2610, 18F4410, 18F4450, 18F44J10, 18F4510, 18F4515, 18F45J10, 18F4610, 18F6310, 18F6390, 18F6393, 18F63J11, 18F63J90, 18F6410, 18F6490, 18F6493, 18F64J11, 18F64J90, 18F65J10, 18F65J11, 18F65J15, 18F65J50, 18F65J90, 18F66J10, 18F66J11, 18F66J15, 18F66J16, 18F66J50, 18F66J55, 18F66J60, 18F66J65, 18F67J10, 18F67J11, 18F67J50, 18F67J60, 18F8310, 18F8390, 18F8393, 18F83J11, 18F83J90, 18F8410, 18F8490, 18F8493, 18F84J11, 18F84J90, 18F85J10, 18F85J11, 18F85J15, 18F85J50, 18F85J90, 18F86J10, 18F86J11, 18F86J15, 18F86J16, 18F86J50, 18F86J55, 18F86J60, 18F86J65, 18F87J10, 18F87J11, 18F87J50, 18F87J60, 18F96J60, 18F96J65, 18F97J60

 

Addr: 0x2100 Size: 0

12CE673, 12CE674, 16F627, 16F628, 16F83, 16F84, 16F870, 16F871, 16F872, 16F873, 16F873A, 16F874, 16F874A, 16F876, 16F876A, 16F877, 16F877A, 16HV785

 

Addr: 0x2100 Size: 64

16F84A

 

Addr: 0x2100 Size: 128

12F629, 12F635, 12F675, 16F627A, 16F628A, 16F630, 16F631, 16F676, 16F818, 16F882

 

Addr: 0x2100 Size: 256

12F683, 16F636, 16F639, 16F648A, 16F677, 16F684, 16F685, 16F687, 16F688, 16F689, 16F690, 16F785, 16F819, 16F87, 16F88, 16F883, 16F884, 16F886, 16F887, 16F913, 16F914, 16F916, 16F917, 16F946

 

Addr: 0xF00000 Size: 0

18C442, 18F242, 18F2439, 18F248, 18F252, 18F2539, 18F258, 18F442, 18F4439, 18F448, 18F452, 18F4539, 18F458, 18F6525, 18F6585, 18F6620, 18F6621, 18F6680, 18F6720, 18F8525, 18F8585, 18F8620, 18F8621, 18F8680, 18F8720, 18LF13k50, 18LF14k50, 18LF2423, 18LF2523, 18LF4423, 18LF4523

 

Addr: 0xF00000 Size: 128

18F1230, 18F1330

 

Addr: 0xF00000 Size: 256

18F1220, 18F1320, 18F13k50, 18F14k50, 18F2220, 18F2221, 18F2320, 18F2321, 18F2331, 18F23K20, 18F2420, 18F2423, 18F2431, 18F2455, 18F2458, 18F2480, 18F24K20, 18F2520, 18F2523, 18F2550, 18F2553, 18F2580, 18F25K20, 18F4220, 18F4221, 18F4320, 18F4321, 18F4331, 18F43K20, 18F4420, 18F4423, 18F4431, 18F4455, 18F4458, 18F4480, 18F44K20, 18F4520, 18F4523, 18F4550, 18F4553, 18F4580, 18F45K20

 

Addr: 0xF00000 Size: 1024

18F2525, 18F2585, 18F2620, 18F2680, 18F2682, 18F2685, 18F26K20, 18F4525, 18F4585, 18F4620, 18F4680, 18F4682, 18F4685, 18F46K20, 18F6520, 18F6527, 18F6622, 18F6627, 18F6628, 18F6722, 18F6723, 18F8520, 18F8527, 18F8622, 18F8627, 18F8628, 18F8722, 18F8723

The address is from the #define _EEPROM line or -none- if not present in the header and the size is from the 'EEPROM Data Memory' column of spreadsheets exported from the Microchip PIC12, PIC16 and PIC18 product family chart pages. I am *very* suspicious of those PICs highlighted in brick red and I suspect the product selector isn't giving the correct data for chips that are no longer in production.

 

This does however give me enough data to modify my EEPROM initialisation macro to cover PIC18 as well as PIC16. It will be Coming Soon . . .

Share this post


Link to post
Share on other sites

As promised, Macros for all EEPROM PIC16/18. I've tested them on a variety of parts, verifying the EEPROM contents using the PICKit 2 GUI.

 

First the header "EEROW.h" (also attached):

/***********************************************************************

EEROW.h - User header file for BoostC and BoostC++ compilers

V1.0 Freely donated to the user community by Ian M, 2009 

Provides macros for portable EEPROM addressing in 
#pragma DATA lines.  EEROW(nn) will give the programming mode
address of byte nn of the EEPROM but nn *MUST* be two HEX
digits.  DO NOT use a leading 0x or omit digits - You wont 
like the result!  If there is more than 256 bytes EEPROM, an 
additional macro EEROWX(nnn) is defined that takes three hex
digits to address the whole EEPROM.  EEROW will then address 
the first page for compatibility.  THERE IS NO ERROR CHECKING
WHEN EITHER MACRO IS USED. Basic sanity checks are made when 
this file is included.   

Workaround for maths problem in <addr> in: 
#pragma data <addr>,< ... > 
e.g.
#pragma DATA _EEPROM+0x10, 16,17,18,19
is ignored by the compiler!


************************************************************************/

#ifndef EEROW
//Check it's not allready defined 
#ifndef _EEPROM
//Handle parts with NO EEPROM: Fatal error.
#error "Error: Cannot define EEROW(hh) without any EEPROM!"
#elif _EEPROM == 0x2100
//Handle PIC16 EEPROM parts
#warning "EEROW(hh) expands to 0x21hh *BUT* hh *MUST* be two HEX digits!"
#define EEROW( hh ) 0x21 ## hh
#elif _EEPROM == 0xF00000
//Handle PIC18 EEPROM parts, under 256 byte access for compatibility
#warning "EEROW(hh) expands to 0xF000hh *BUT* hh *MUST* be two HEX digits!"
#define EEROW( hh ) 0xF000 ## hh
#ifdef EEADRH
//Handle PIC18 Big EEPROM parts
#warning "EEROWX(hhh) expands to 0xF00hhh *BUT* hhh *MUST* be three HEX digits!"
#define EEROWX( hhh ) 0xF00 ## hhh
//end #ifdef EEADRH
#endif
#else
#error "Error: EEROW(hh) cannot be defined (Wrong EEPROM base)"  
#endif
//end #ifndef EEROW
#endif

 

and then the test program:

// EEPROM Initialization for all EEPROM PIC16/18
#include <system.h>
#include "EEROW.h"  
//include EEROW.h AFTER system.h

void main(void) {}  //dummy program

//EEPROM data as expected
//#pragma DATA _EEPROM, 1,2,3,4 

// BUG or missing feature: 
//#pragma DATA _EEPROM+0x10, 16,17,18,19
//gets ignored because of the addition!
//See EEROW.h for workaround. 

//Remember the data can also be character strings
//e.g.
//#pragma DATA EEROW(A8),"Any text here",0x0D,0x0A,0x00
//
//Unfortunately there is currently NO way of getting the current 
//memory address or doing maths with it during preprocessing so
//you need to count your strings carefully.  

// Test data for EEPROM, PIC16/18
#pragma DATA EEROW(00), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
#pragma DATA EEROW(10), 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
#pragma DATA EEROW(20), 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48
#pragma DATA EEROW(30), 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
#pragma DATA EEROW(40), 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
#pragma DATA EEROW(50), 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
#pragma DATA EEROW(60), 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112
#pragma DATA EEROW(70), 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
#pragma DATA EEROW(80), 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144
#pragma DATA EEROW(90), 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160
#pragma DATA EEROW(A0), 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176
#pragma DATA EEROW(B0), 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192
#pragma DATA EEROW(C0), 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208
#pragma DATA EEROW(D0), 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224
#pragma DATA EEROW(E0), 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240
#pragma DATA EEROW(F0), 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 0

// Test data for BIG EEPROM, PIC18
#ifdef EEROWX
#pragma DATA EEROWX(100), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
#pragma DATA EEROWX(110), 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
#pragma DATA EEROWX(120), 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48
#pragma DATA EEROWX(130), 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
#pragma DATA EEROWX(140), 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
#pragma DATA EEROWX(150), 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
#pragma DATA EEROWX(160), 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112
#pragma DATA EEROWX(170), 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
#pragma DATA EEROWX(180), 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144
#pragma DATA EEROWX(190), 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160
#pragma DATA EEROWX(1A0), 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176
#pragma DATA EEROWX(1B0), 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192
#pragma DATA EEROWX(1C0), 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208
#pragma DATA EEROWX(1D0), 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224
#pragma DATA EEROWX(1E0), 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240
#pragma DATA EEROWX(1F0), 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 0
#endif

 

Download the header here: EEROW.h

 

Comments and feedback are welcome.

 

ENJOY!

 

Ian M

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×