Jump to content
Sign in to follow this  
vergy

Default value in EE

Recommended Posts

Hi,

Does anybody know how can I insert in my c source code some byte to be stored in the internal EEPROM douring the micro programming? (to be used as default value in my application).

 

 

thanks

 

Francesco

Share this post


Link to post
Share on other sites

Hi Francenco !

 

You can try this:

 

/*

   Write a byte to flash memory

*/

void SaveParam( char value, char addr )

{

  EE_ADR = addr;

  EE_DATA = value;  // Valor que se almacena

  clear_bit( EE_CON1, EEPGD_BIT );

  set_bit ( EE_CON1, WREN_BIT ); // Habilita la escritura

  EE_CON2 = 0x55;  // Comando obligatorio

  EE_CON2 = 0xaa;  // Comando obligatorio

  set_bit ( EE_CON1, WR_BIT );// Realiza la escritura

  clear_bit ( EE_CON1, WREN_BIT ); // Deshabilita la escritura

}

 

/*

  Read a byte from flash memory

*/

char LoadReg( char reg )

{

  char lreg = 0;

  EE_ADR = reg;  // Direccion de la EEPROM  

  clear_bit( EE_CON1, EEPGD_BIT );

  set_bit ( EE_CON1, RD_BIT );// Realiza la lectura

  lreg = EE_DATA;

  return lreg;

}

 

Bye

Daniel

Share this post


Link to post
Share on other sites

Francesco, I forget

 

These defines are necesary

 

char EE_DATA  @ 0x10C;

char EE_ADR   @ 0x10D;

 

// EEDATA

#define  RD          1

#define  RD_BIT 0

#define  WR          2

#define  WR_BIT 1

#define  WREN        4

#define  WREN_BIT   2

#define  WRERR       8

#define  WRERR_BIT 3

#define  EEPGD       128

#define  EEPGD_BIT 7

 

I hope help you

 

Bye

Daniel

Share this post


Link to post
Share on other sites

Hola dvaccaro,

 

Thank you for the answare but my question was: how can I put some bytes in .hex file, that during programming (by MPLAB), are written in the PIC16F877 EEPROM area?

 

(sorry for my english)

 

Bye

Share this post


Link to post
Share on other sites

Hola Francesco

 

In fact, if default values are load in first program run

is a problem ? This way ins´t need write EEPROM area

at download time. Can you put some flag at EEPROM

area to verify the first time ( at first run )

 

I help you ?

Bye

Daniel

Share this post


Link to post
Share on other sites
Francesco: Thank you for the answare but my question was: how can I put some bytes in .hex file, that during programming (by MPLAB), are written in the PIC16F877 EEPROM area?

 

This data can be added to the .hex file.

It needs to be programmed to PIC address 0x2100h and onwards.

 

Here an extract that does that. Note that the address 2100h is multiplied by 2 ie  4200h is used because each location consists of two bytes.

 

:104200001200340056007800FF00FF00FF00FF009E

:10421000FF00FF00FF00FF00FF00FF00FF00FF00A6

:10422000FF00FF00FF00FF00FF00FF00FF00FF0096

:10423000FF00FF00FF00FF00FF00FF00FF00FF0086

:10424000FF00FF00FF00FF00FF00FF00FF00FF0076

:10425000FF00FF00FF00FF00FF00FF00FF00FF0066

:10426000FF00FF00FF00FF00FF00FF00FF00FF0056

:10427000FF00FF00FF00FF00FF00FF00FF00FF0046

:00000001FF

 

so to add data to eprom from a .asm file you just add

org 0x2100

dw 12,34,56,78

to set data in EEPROM at program time.

 

 

****This is what you really want!******

:) :) :)

To add eprom data in your C code add the following, do NOT do this inside a function body - otherwise it can get optimised away!

 

asm last_addr equ $ ; save current address for assembly

 

asm org 0x2100 ; Eprom address when programming PIC

asm dw 12,34,56,78 ; set our bytes in eprom - only when programmed!

 

asm org last_addr ; restore current address for assembly to contniue as normal

 

void main()

{

      my code.....

}

 

This generates the correct stuff in the .hex - I have not tried programming a device, so please let me know if this works.

 

The only other thing is that your programmer software correctly handles EEPROM programming.

 

Regards

Hobknob

Share this post


Link to post
Share on other sites
asm last_addr equ $ ; save current address for assembly

 

asm org 0x2100 ; Eprom address when programming PIC

asm dw 12,34,56,78 ; set our bytes in eprom - only when programmed!

 

asm org last_addr ; restore current address for assembly to contniue as normal

 

void main()

{

    my code.....

}

 

This generates the correct stuff in the .hex - I have not tried programming a device, so please let me know if this works.

The only other thing is that your programmer software correctly handles EEPROM programming.

 

Regards

Hobknob

-----------------------------------------------------------

Well, but how I can to place a label for a future reference from a C source? For instance could I use a labeled address from EEProm area as address variable for EE-service function?

I never could to do this..

:)

Victor.

Share this post


Link to post
Share on other sites
Guest Pavel

The 5.0.5 compiler version has a new pragma that reserves data in code or eeprom memory. Unfortunately this change wasn't added to the compiler help file. Help update is available to download here.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
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...
Sign in to follow this  

×
×
  • Create New...