www.pudn.com > iccavr_lib.rar > eepromw.c, change:2003-10-28,size:1426b


/* Modified by Richard Man 
 */ 
/* 
**	Purpose:    EEPROM read & write routines 
** 
**  Version:    1.0.0, 8:th of May 1999 
** 
**  Author:     Lars Wictorsson 
**              LAWICEL / SWEDEN 
**              http://www.lawicel.com   lars@lawicel.com 
** 
**  History:    1999-05-08  Created 
**/ 
 
/* These routines work for all AVR devices except for 2313 and below 
 * The "location" argument is not bound so in theory you should call it 
 * with something like 
 * 
 * #include <io????.h> 
 * 
 * ... 
 * EEPROMwrite(addr & E2END, byte); 
 */ 
 
#ifdef _M169 
#include <iom169v.h> 
#else 
#include <io8515.h>	// ALL devices have the same EEPROM reg locations 
#endif 
 
#include <eeprom.h> 
 
int EEPROMwrite( int location, unsigned char byte) 
{ 
	unsigned char oldSREG; 
 
    while (EECR & 0x02);                // Wait until any earlier write is done 
 
	EEAR = location; 
 
    EEDR = byte; 
 
	oldSREG = SREG; 
	SREG &= ~0x80;		// disable interrupt 
 
    EECR |= 0x04;                       // Set MASTER WRITE enable 
    EECR |= 0x02;                       // Set WRITE strobe 
 
	SREG = oldSREG; 
    return 0;                           // return Success. 
                                        // Could be expanded so that 
                                        // the routine checks that the address 
                                        // is within the range of the chip. 
}