• AVR Freaks

Hot!How to save a structure in the EEPROM?

Author
Neraildes
Super Member
  • Total Posts : 207
  • Reward points : 0
  • Joined: 2017/10/11 07:13:25
  • Location: 0
  • Status: offline
2019/04/19 10:18:00 (permalink)
0

How to save a structure in the EEPROM?

void EEPROM_Write_Byte(unsigned int addr, unsigned char dado)
{
    unsigned char last_GIE;
    Delay_Led_Memory=DEFAULT_LEDS;
    
    while(EECON1bits.WR==1) continue;
    
  
       if(INTCONbits.GIE)
          last_GIE=1;
       else
          last_GIE=0;
       EEADRH=Hi(addr);
       EEADR=Lo(addr);
       EEDATA=dado;
       EECON1bits.EEPGD=0;
       EECON1bits.CFGS=0;
       EECON1bits.WREN=1;
       INTCONbits.GIE=0;
       EECON2=0x55;
       EECON2=0xAA;
       EECON1bits.WR=1;
       
       if(last_GIE)
          INTCONbits.GIE=1;
       else
          INTCONbits.GIE=0;
       
       EECON1bits.WREN=0;
       __delay_ms(25);
    
}

 

      struct {
             unsigned flag_global_datalog : 1 ;
             unsigned flag_global_aquecimento : 1 ;
             unsigned flag_global_condensador : 1 ;
             unsigned flag_global_vacuo : 1 ;
             unsigned flag_time_process : 1 ;
             
             }statuspower;

      

#define flag_global_datalog statuspower.flag_global_datalog
#define flag_global_aquecimento statuspower.flag_global_aquecimento
#define flag_global_condensador statuspower.flag_global_condensador
#define flag_global_vacuo statuspower.flag_global_vacuo
#define flag_time_process statuspower.flag_time_process

 
 
void main(){
 
       EEPROM_Write_byte(0x0F, statuspower);
}

#1

3 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17230
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: How to save a structure in the EEPROM? 2019/04/19 10:26:48 (permalink)
    +1 (1)
    Make a pointer to your struct
    Use sizeof() to To get its size
    Use a for loop To write it one byte at a time
    #2
    1and0
    Access is Denied
    • Total Posts : 9011
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: How to save a structure in the EEPROM? 2019/04/19 10:27:12 (permalink)
    +1 (1)
    Make that struct a part of a union with a byte member, and save that byte.
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11129
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: How to save a structure in the EEPROM? 2019/04/19 13:52:25 (permalink)
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5