📄 rteeprom.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -