ATmega8535L Eeprom Example Program
//***************ICCAVR V6.30 compiled*****************//
#include
#define uchar unsigned char
#define uint unsigned int
//digital tube font table, corresponding to 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F //
uchar Table[16]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
uchar Read_Data[4]; //define read data
void DelayMs(uint i) //Ms level delay, parameter i is the delay time
{uint j;
for(;i!=0;i--)
{for(j=8000;j!=0;j--) {;}} }
void
Display(uchar *p) //Dynamic display function, parameter p is the name of the array to be displayed
{uchar i,sel=0x01;
for(i=0;i<4;i++)
{PORTA=sel; //Select the rightmost digital tubePORTC
=0xff-Table[p[i]]; //Send font code
DelayMs(1); //Display delay
sel=sel<<1; //Shift to display the previous bit
}
}
void Init_IO(void) //Initialize I/O port
{DDRA=0xff; //Set port A to push-pull 1 output
PORTA=0xff;
DDRC=0xff; //Set port C to push-pull 1 output
PORTC=0xff;
}
void Write_EEPROM(uchar Data,uint Address)
{if(EECR&0x20) DelayMs(4);
EEARH=Address>>8;
EEARL=Address&0x00ff;
EEDR=Data;
EECR=EECR|0x04;
EECR=EECR|0x02;
DelayMs(4);
}
uchar Read_EEPROM(uint Address)
{uchar i;
if(EECR&0x01) DelayMs(4);
EEARH=Address>>8;
EEARL=Address&0x00ff;
EECR=EECR|0x01;
DelayMs(5);
i=EEDR;
return(i);
}
void main(void)
{uchar i;
Init_IO(); //Initialize I/O port
PORTA=0xff; //Light up to test all digital tubes
PORTC=0x00;
DelayMs(300); //Delay
PORTC=0xff; //Turn off all digital tubes
for(i=0;i<4;i++)
Write_EEPROM(5*i,i);
for(i=0;i<4;i++)
Read_Data[i]=Read_EEPROM(i);
while(1)
Display(Read_Data);
}
Previous article:ATmega8535L Marquee Program (ICC Compiler)
Next article:atmega8535 Ad conversion c program
- Popular Resources
- Popular amplifiers
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
- Can it replace the human arm?
- What is the baud rate register used for? The documentation seems to be somewhat contradictory. It says baud rate register first and counter later.
- TMS320VC5502EMIF external flash configuration problem
- 【ST NUCLEO-H743ZI Review】——by Sodium Citrate
- Online version of esptool
- Purgatory Legend-Synchronous Counter Optimization Battle
- IoT APP Development: What should we pay attention to when developing IoT APP software?
- Registration for ST 2021 Industrial Summit is now open!
- Analyzing the interrupt behavior of gd32vf103 from the underlying principle of RISC-V
- Digital frequency meter design