#pragma used+
///Write single byte EEPROM
void EEPROM_write(unsigned int uiAddress, unsigned char ucData);
///Read single byte EEPROM
unsigned char EEPROM_read(unsigned int uiAddress);
///Write double byte EEPROM
void EEPROM_write2(unsigned int uiAddress, unsigned int ucData);
///Read double byte EEPROM
unsigned int EEPROM_read2(unsigned int uiAddress);
///Read 4 bytes EEPROM
unsigned long EEPROM_read4(unsigned int uiAddress);
///Write 4 bytes EEPROM
void EEPROM_write4(unsigned int uiAddress, unsigned long ucData);
#pragma used-
#pragma library eeprom.lib
EEPROM.C
//#include "eeprom.h"
/* EEPROM Control Register */
#define EERIE 3
#define EEMWE 2
#define EEWE 1
#define EERE 0
#if funcused EEPROM_write
///Write single byte EEPROM
void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
//#asm("cli")
////* Wait for the last write operation to end
while(EECR & (1< EEAR = uiAddress; EEDR = ucData; ////* Set EEMWE EECR |= (1< EECR |= (1< //#asm("sei") } #endif #if funcused EEPROM_read ///Read single byte EEPROM unsigned char EEPROM_read(unsigned int uiAddress) { #asm("cli") ///* Wait for the last write operation to end while(EECR & (1< EEAR = uiAddress; ///* Set EERE to start read operation EECR |= (1< return EEDR; //#asm("sei") } #endif #if funcused EEPROM_read2 ///Read double byte EEPROM unsigned int EEPROM_read2(unsigned int uiAddress) { unsigned int ucdata; // #asm("cli") ///* Wait for the last write operation to end while(EECR & (1< EEAR = uiAddress+1; ///* Set EERE to start read operation EECR |= (1< ucdata = EEDR; ucdata =ucdata<<8; while(EECR & (1< EEAR = uiAddress; ///* Set EERE to start read operation EECR |= (1< ucdata |= EEDR; return ucdata; //#asm("sei") } #endif #if funcused EEPROM_write2 ///Write double byte EEPROM void EEPROM_write2(unsigned int uiAddress, unsigned int ucData) { //#asm("cli") ////* Wait for the last write operation to end while(EECR & (1< EEAR = uiAddress; EEDR = ucData & 0x00ff; ////* Set EEMWE EECR |= (1< EECR |= (1< while(EECR & (1< EEAR = uiAddress+1; EEDR = (ucData & 0xff00)>>8; ////* Set EEMWE EECR |= (1< EECR |= (1< } #endif #if funcused EEPROM_read4 ///Read 4 bytes EEPROM unsigned long EEPROM_read4(unsigned int uiAddress) { unsigned long ucdata; // #asm("cli") ///* Wait for the last write operation to end while(EECR & (1< EEAR = uiAddress+3; ///* Set EERE to start read operation EECR |= (1< ucdata = EEDR; ucdata =ucdata<<8; EEAR = uiAddress+2; ///* Set EERE to start read operation EECR |= (1< ucdata |= EEDR; ucdata =ucdata<<8; EEAR = uiAddress+1; ///* Set EERE to start read operation EECR |= (1< ucdata |= EEDR; ucdata =ucdata<<8; while(EECR & (1< EEAR = uiAddress; ///* Set EERE to start read operation EECR |= (1< ucdata |= EEDR; return ucdata; //#asm("sei") } #endif #if funcused EEPROM_write4 ///Write 4 bytes EEPROM void EEPROM_write4(unsigned int uiAddress, unsigned long ucData) { //#asm("cli") ////* Wait for the last write operation to end while(EECR & (1< EEAR = uiAddress; EEDR = ucData & 0x000000ff; ////* Set EEMWE EECR |= (1< EECR |= (1< ucData = ucData>>8; while(EECR & (1< EEAR = uiAddress+1; EEDR = ucData & 0x000000ff; ////* Set EEMWE EECR |= (1< EECR |= (1< ucData = ucData>>8; while(EECR & (1< EEAR = uiAddress+2; EEDR = ucData & 0x000000ff; ////* Set EEMWE EECR |= (1< EECR |= (1< ucData = ucData>>8; while(EECR & (1< EEAR = uiAddress+3; EEDR = ucData & 0x000000ff; ////* Set EEMWE EECR |= (1< EECR |= (1< } #endif
Previous article:AVR MCU Study Notes – ADC
Next article:Lcd.h header file download - AVR microcontroller driver header file for character LCD
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- ST Industrial Summit 2019 invites you to meet in Shenzhen!
- Two-phase four-wire stepper motor
- I need help with the isolation problem between two 232 chips!
- Gallium Nitride
- EEWORLD University - Machine Learning from Zero to One
- About the flash programming problem of TI chip tms320C6726B
- Goodbye 2019, hello 2020! Maker education has a long way to go
- Mir MYC-YT507 development board review: Development environment part 3: Qt tank game
- XMC4800 Review (Part 1)
- FPGA Development Guide - Timing Constraints