(1) Flash constants:
#include //header file to be added
const prog_uchar FlashConst = 3; //define uchar type constant n in flash (flash constant)
unsigned char RamVar; //define unsigned integer variable (Ram variable)
RamVar = pgm_read_byte(&FlashConst); //read flash constant to ram variable
(2) Flash one-dimensional data:
#include
const prog_uchar s[5] = { 1, 2, 3, 4, 5 };
unsigned char RamVar; //define unsigned integer variable (Ram variable)
RamVar = pgm_read_byte( &s[1] ); //read the value of s[1] to RamVar, or RamVar = pgm_read_byte( s+1 );
(3) Flash multidimensional data:
#include
const prog_uchar s[4][16] = { {14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7 },
{ 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8 },
{ 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0 },
{15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13 } }
;
unsigned char RamVar[4],[16]; //define unsigned integer variables (Ram variables)
register char i, j;
for(i=0; i<4; ++)
{
for(j=0; j<16; j++)
{
RamVar[i][j] = pgm_read_byte( &s[i][j] ); //read the value of array s to RamVar
}//end for 2
}//end for 1
(4) The extended part
of avr addresses ram and flash independently. ram is addressed by 8 bits, while flash is addressed by 16 bits. The assembly instructions for reading ram and flash are also different.
Similar flash data types include: prog_void, prog_char, prog_int8_t, prog_uint8_t, prog_int16_t, prog_uint16_t, prog_int32_t, prog_uint32_t, etc.
The read instruction pgm_read_xxx macro definition is actually a section of inline assembly code that includes flash read instructions. The function prototype is: pgm_read_byte(address_short), pgm_read_word(address_short), pgm_read_dword(address_short), pgm_read_float(address_short). The brackets are address values.
Keywords:AVRGCC
Reference address:How to define variables in flash space in AVRGCC (big data storage)
#include
const prog_uchar FlashConst = 3; //define uchar type constant n in flash (flash constant)
unsigned char RamVar; //define unsigned integer variable (Ram variable)
RamVar = pgm_read_byte(&FlashConst); //read flash constant to ram variable
(2) Flash one-dimensional data:
#include
const prog_uchar s[5] = { 1, 2, 3, 4, 5 };
unsigned char RamVar; //define unsigned integer variable (Ram variable)
RamVar = pgm_read_byte( &s[1] ); //read the value of s[1] to RamVar, or RamVar = pgm_read_byte( s+1 );
(3) Flash multidimensional data:
#include
const prog_uchar s[4][16] = { {14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7 },
{ 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8 },
{ 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0 },
{15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13 } }
;
unsigned char RamVar[4],[16]; //define unsigned integer variables (Ram variables)
register char i, j;
for(i=0; i<4; ++)
{
for(j=0; j<16; j++)
{
RamVar[i][j] = pgm_read_byte( &s[i][j] ); //read the value of array s to RamVar
}//end for 2
}//end for 1
(4) The extended part
of avr addresses ram and flash independently. ram is addressed by 8 bits, while flash is addressed by 16 bits. The assembly instructions for reading ram and flash are also different.
Similar flash data types include: prog_void, prog_char, prog_int8_t, prog_uint8_t, prog_int16_t, prog_uint16_t, prog_int32_t, prog_uint32_t, etc.
The read instruction pgm_read_xxx macro definition is actually a section of inline assembly code that includes flash read instructions. The function prototype is: pgm_read_byte(address_short), pgm_read_word(address_short), pgm_read_dword(address_short), pgm_read_float(address_short). The brackets are address values.
Previous article:AVR microcontroller serial port multi-machine communication and examples
Next article:AVR PWM wave
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Forum mini program is online! Scan the QR code to unlock new ways to browse the forum!!
- Implement PID using FPGA and simulate with modelsim
- error: expected class-name before ‘{’ token {
- [GD32E231 DIY Contest]——03. Project Introduction: IoT Entry Example Based on MQTT Message Communication
- 3. Development of a health and sports assistant project based on Nucleo-L476L
- Calculation and selection of power input rectifier bridge and filter capacitor
- 【Silicon Labs development kit review】+SPI flash (MX25R8035F)
- Low-cost Wemos W600-PICO development board
- EEWORLD University Hall----American DIY players comprehensively test Keithley 2280S high measurement accuracy power supply
- Today at 10:00 AM, live broadcast with prizes: Melexis explains the implementation and technical support of semiconductor R&D functional safety