rteeprom.c

来自「AVR系列单片机ATMEGA64开发的LED显示屏程序 内容包括ATMEGA6」· C语言 代码 · 共 40 行

C
40
字号
#include <include.h>
// function to test if the EEPROM is ready for a read or write operation
// returns non zero if ready, zero if not ready 
unsigned char RTEEPROMReady(void)
{
	return !(EECR & 0x02);
}



// function to initiate an EEPROM write
// writes the specified data byte to the specified location
// this will fail if the EEPROM is not ready!
void RTEEPROMwrite(int location, unsigned char databyte)
{
	unsigned char savedSREG;
	EEAR = location;								// set address
	EEDR = databyte;								// set data	
	savedSREG = SREG;								// keep setting so it can be restored
	CLI();													// disable interrupts
	EECR |= BIT(EEMWE);							// set "write enable" bit
	EECR |= BIT(EEWE);							// set "write" bit
	SREG = savedSREG;								// restore SREG
	EEAR = 0;
	while(!RTEEPROMReady());
}



// function to read from the EEPROM
// reads a byte from the specified location
// this will fail if the EEPROM is not ready!
unsigned char RTEEPROMread(int location)
{
	EEAR = location;								// set address
	EECR |= BIT(EERE);							// set "read enable" bit
	EEAR = 0;
	return (EEDR);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?