AVR internal EEPROM read and write program - write data first, then read it out to see if it is consistent

Publisher:范隆Latest update time:2019-10-28 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


/*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



}


Keywords:AVR Reference address:AVR internal EEPROM read and write program - write data first, then read it out to see if it is consistent

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

Basic knowledge and features of AVR microcontrollers
AVR microcontroller is a new type of microcontroller developed by ATMEL. Compared with 51 microcontroller and PIC microcontroller, it has a series of advantages: 1: AVR runs fastest under the same system clock; 2: The capacity of Flsah, EEPROM and SRAM inside the chip is large; 3: All models of Flash and EEPROM
[Microcontroller]
Solve "#include error detected
After configuring the Arduino environment of VSCode, the following errors may occur when writing code #include error detected. Please update includePath. Squiggle has been disabled for this translation unit (E:abc.ino). C/C++(1696) Unable to open source file "avr/pgmspace.h" (dependency of "C:Program Files (x86)Ar
[Microcontroller]
Solve
AVR analog-to-digital (AD) conversion program
1. Development language This example is developed using WinAVR/GCC 20050214 version 2. Example description This program simply demonstrates how to use the ADC analog-to-digital converter of ATMEGA16. Ordinary single-ended input Differential input and calibration of reference voltage Query method Interrupt method
[Microcontroller]
AVR analog-to-digital (AD) conversion program
AVR Series MCU FAQ
Q: I want to use the Mega series of AVR microcontrollers. What development tools support this microcontroller? A: The Mega series of AVR microcontrollers has a complete set of development tools. Evaluation/programming boards. ATMEL's STK500 (980 yuan/set) starter kit is suitable for developing Atmega103 chips. Program
[Microcontroller]
ds1302 clock-AVR program code
#include  #include "DS1302.h" #include    void ds1302_init(void) {     PORTX=0x00;     DDRX=0x07; }   void write_ds1302_byte(unsigned char dat) {          unsigned char i;     for(i=0;i 8;i++)     {     SCK=0;     IO_out=dat&0x01;     that=that 1;      SCK=1;     } }   void write_ds1302(unsigned char add,unsigned char
[Microcontroller]
AVR Basics: The ATMEGA's SPI Bus - Part 1
When the AVR communicates with other devices, we need to choose which method to use. You can use classic serial ports such as UART and I2C, or you can choose the serial peripheral interface (SPI). I prefer the SPI bus method. So let's talk about this bus form. relation An important concept in SPI is the master-slave
[Microcontroller]
AVR Basics: The ATMEGA's SPI Bus - Part 1
AVR User Notes
After power-on, when the peripheral devices of the microcontroller do not have normal phenomena, it may be that the peripheral crystal oscillator of the microcontroller has not started to oscillate. At this time, you can set the fuse bit to select the clock source of the AVR microcontroller as the internal clock. Po
[Microcontroller]
KC-101 51/AVR MCU Minimum System Core Board Product Description
After the launch of "Enhanced 51 Experiment Board" and "51 MCU Comprehensive Learning System", they are well received and trusted by users due to their simple operation and convenient learning. We have also received suggestions and feedback from users. To thank you for your support and concern, we have modularized the
[Microcontroller]
KC-101 51/AVR MCU Minimum System Core Board Product Description
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号