码迷,mamicode.com
首页 > 其他好文 > 详细

ATmega128A-AU EEPROM的读写

时间:2014-12-30 13:24:49      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

 

ATmega128A-AU EEPROM的读写

标签:

原文地址:http://www.cnblogs.com/aqing1987/p/4193355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!