ATmega128A-AU EEPROM的读写

#include <iom128a.h>

#include "intrinsics.h"



// write one byte data to pointed EEPROM address

void pdd_write_eeprom_byte(u16 uiAddress, u8 ucData)

{

    char cSREG;

    

    // store SREG value

    cSREG = SREG;    

    

    // disable global interrupt

    __disable_interrupt();

    

    // Wait for completion of previous write

    while (EECR & (1 << EEWE))

    {

        ;

    }

    

    // Set up address and data registers

    EEAR = uiAddress;

    EEDR = ucData;



    // Write logical one to EEMWE

    EECR |= (1<<EEMWE);

    // Start eeprom write by setting EEWE

    EECR |= (1<<EEWE);

    

    // restore SREG value

    SREG = cSREG;

}



// read one byte data from pointed EEPROM address

u8 pdd_read_eeprom_byte(u16 uiAddress)

{

    char cSREG;

    

    // store SREG value

    cSREG = SREG;        

    

    __disable_interrupt();

    

    // Wait for completion of previous write

    while (EECR & (1 << EEWE))

    {

        ;

    }

    

    // Set up address register

    EEAR = uiAddress;    

    

    // Start eeprom read by writing EERE

    EECR |= (1 << EERE);

    

    // restore SREG value

    SREG = cSREG;

    

    // Return data from data register

    return EEDR;

}

 

你可能感兴趣的:(ROM)