/*This program is to perform read and write operations on the internal EEPROM of the AVR to test the EEPROM. The main purpose is to first write to */
/*Write data into the internal EEPROM, then read it out to see if it is consistent. Finally, it is proven to be correct. This program can be used*/
/*20110414 Tianjin Fourth Project Department Dormitory Wang Junwei*/
#include #define uchar unsigned char #define uint unsigned int #define set_bit(a,b) a|=(1<#define clr_bit(a,b) a&=~(1<#define get_bit(a,b) a&(1< void write_eeprom (uchar add,uchar date) // write EEPROM { while(get_bit(EECR,1));//Check if EEWE=0 is there a write operation? If =1, then wait; if =0, then it proves that it is idle and can be written down. EEARH=0;//Not used EEARL=add; //Address preparation EEDR=date; //Data preparation clr_bit(EECR,3); //Disable EEPROM interrupt SREG=0; //Disable general interruption to prevent sudden interruption from interrupting the CPU's EEPROM write operation set_bit(EECR,2); //Turn on the master write enable bit set_bit(EECR,1); //enable write enable bit ;;;;;//Write to the on-chip EEPROM } uchar read_eeprom(uchar add) //Read EEPROM { while(get_bit(EECR,1));//Check if EEWE=0 is there a write operation? If =1, then wait; if =0, then it proves that it is idle and can be written down. EEARH=0;//Not used EEARL=add; //Address preparation SREG=0; //Disable general interruption to prevent sudden interruption from interrupting the CPU's EEPROM reading operation set_bit(EECR,0); //Start read operation ;;;;//wait return (EEDR); } void main () //Main function { DDRA=0xff; PORTA=0x00; //Port A initialization write_eeprom(0x00,0x88); //Write the first eight bits of address 0x00; and data 0x33; Note that I did not use EEARH, only EERHL, so I can only search for 256 bytes PORTA=read_eeprom(0x00);//address inside brackets }
Previous article:AVR128_uC/OS-II porting code
Next article:Introduction to IO ports of AVR microcontroller
Recommended ReadingLatest update time:2024-11-16 13:54
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- High-precision electronic heartbeat comes from TI's breakthrough BAW resonator technology
- Keil newly built project, why can't I find ADuC7029
- [Fudan Micro FM33LG0 Series Development Board Evaluation] Development Board Hardware Evaluation, CMSIS-DAP Download Test
- 【Development Kit for nRF52840】+ Three Tools for Evaluation & Cloud Gateway Testing
- What is carrier bandwidth in wireless communications?
- Participate to get gifts | Welcome to Tektronix High Speed Serial Knowledge Planet
- 【Fudan Micro FM33LC046N】A breathtaking clock
- What happened to ZTE? I saw an article and shared it with everyone
- [Gizwits Gokit 3 Review] + Late Unboxing Review
- SHT31 review + sharing an mdk5 engineering code file