Operation Methods of common flash types

Source: Internet
Author: User

Operation Methods of common flash types

4.1.flash region data storage.
Use the keyword _ flash Control for storage, and the _ flash keyword for the same effect before and after the data type.
_ Flash unsigned char a; // defines a variable stored in the Flash space.
Unsigned char _ flash a; // The effect is the same as above
_ Flash unsigned char P []; // defines an array stored in the Flash Space
The read operations on the variables in the Flash space are the same as those in the SRAM data space. The Compiler automatically uses
LPM and elpm commands.
Example:
# I nclude <iom8.h>
_ Flash unsigned char P [];
_ Flash unsigned char;
Void main (void)
{Portb = P [1]; // read The Flash array variable operation
Portb = A; // read The Flash variable operation
}
In a normal program, the flash space is read-only, so variables without assignment are meaningless. To define constants in the Flash space, you only need to assign the initial values to the variables. Since the constant is randomly allocated in the Flash space address, the constant value can be read only when the read variable is used.
10
IAR-AVR-C compiler Overview
_ Flash unsigned char a = 9; // defines a constant stored in the eeprom space.
_ Flash unsigned char P [] = {1, 2, 3, 4, 5, 6, 7, 8 };
// Define a group of constants stored in the Flash space.
Example:
# I nclude <iom8.h>
_ Flash unsigned char P [] = {1, 2, 3, 4, 5, 6, 7, 8 };
_ Flash unsigned char a = 9;
Void main (void)
{
Portb = A; // read The Flash Space Value 9
Portc = P [0]; // read The Flash Space Value
}

4.1.2absolute address location of the flash space:
_ Flash unsigned char a @ 0x8; // define the variable to be stored in the Flash space 0x08 Unit _ flash unsigned char P [] @ 0x22 // define the array to be stored in the Flash space. The starting address is 0x22 unit.
_ Flash unsigned char a @ 0x08 = 9; // defines the unit 0x08 of a constant stored in the Flash space.
_ Flash unsigned char P [] @ 0x22 = {1, 2, 3, 4, 5, 6, 7, 8 };
// Define the starting address of a group constant stored in the eeprom space as 0x22
Since constants have been allocated in the Flash space address, you can use variables and addresses to read the flash space value.

4. 2. pointer operations related to _ flash. The _ flash keyword controls the storage and type of pointers.
4.2.1 pointer to flash space flash pointer (control type attribute)
Unsigned char _ flash * P; // defines the pointer to the Flash space address, which is 8 bits.
Unsigned int _ flash * P; // defines a pointer to the Flash space address, 16 bits.
Unsigned int _ farflash * P; // defines the pointer to the Flash space address, 24 bits.
Unsigned int _ hugeflash * P; // defines the pointer to the Flash space address, 24 bits.
Unsigned char _ flash * P; // defines a pointer to the Flash space address, which is stored in SARM. The value of P indicates an address of the flash space. * P indicates the content stored in the address unit of the flash space. For example, if p = 10, the address of the flash space is 10 units, and the content of the flash m space is read by * P.
Example:
# I nclude <iom8.h>
Char _ flash t @ 0x10;
Char _ flash * P;
Void main (void)
{
Portb = * P; // read the value of 10 units in the Flash space.
Portb = * (p + 3); // read the value of the flash space 0x13 unit.
}

4.2.2. pointer Data Pointer stored in Flash Space
Control the storage attributes just like the data stored in the Flash Space
_ Flash unsigned char * P; // defines the pointer to the sarmm space address, which is stored in flash.

. The _ flash definition used to control data and pointer storage must be a global variable, and the control type attribute (as if only a pointer) can be a local variable.
# I nclude <iom8.h>
_ Flash unsigned char P; // controls Storage
Void main (void)
{
Unsigned char _ flash * t; // control attributes
Portb = P;
Portb = * t;
}

4.4. The _ root keyword ensures that unused functions or variables can also be included in the target code.
Define the data stored in the _ flash space. During program compilation, the generated code is automatically embedded into the flash code, if the program is not used, the compiled data (such as your version number and time can be embedded in the Code) must be subject to the keyword _ root.
Example:
# I nclude <iom8.h>
_ Root _ flash unsigned char P @ 0x10 = 0x56;
Void main (void)
{}
If the program does not use the P variable, the Code is also generated during compilation.
: 020000020000fc
: 00016c0189518951895189518951895189518955f
: 100010005695189518951895189518951895189518953a
: 10002000189518951895089500008895fecf0fe94a
: 100030000dbf00e00ebfc0e8d0e003d0f4dff4df76
: 06004000f3cf01e008957a
: 0400000300000000f9
: 00000001ff

4.5.flash macro functions: Detailed descriptions are provided in the header file comp_a90.h intrinsics. h. The Flash space has the read-only performance normally. For the read flash data compiler, the corresponding LPM and elpm commands are automatically compiled, however, there is no corresponding C command for the Self-programming write command SPM of the flash space. Here we will not explain the detailed self-programming method, but will explain the Read and Write Functions of the flash space.
Read the address data of the flash space directly in the program: the file must contain the intrinsics. h header file.
_ Load_program_memory (const unsigned char _ flash *); // 64 K space
// Read data from the specified flash space address. This function is described in the intrinsics. h header file.
The comp_a90.h file has its simplified write _ LPM (ADDR ). Note that the Assembly command LPM Rd, Z in Z is a pointer. Therefore, (const unsigned char _ flash *) is used to forcibly convert the pointer to the address of the flash space. Therefore, the correct syntax of this macro function should be as follows:
_ Load_program_memory (const unsigned char _ flash *) ADDR );
Example:
# I nclude <iom8.h>
# I nclude <intrinsics. h>
Void main (void)
{Portb =__ load_program_memory (const unsigned char _ flash *) 0x12 );
}
This function is not easy to write. It is simplified in the comp_a90.h file:
# DEFINE _ LPM (ADDR) _ load_program_memory (ADDR) is a little more convenient. Change
# DEFINE _ LPM (ADDR) _ load_program_memory (const unsigned char
_ Flash *) ADDR) makes it easier to use data directly.
Example:
# I nclude <iom8.h>
# I nclude <comp_a90.h>
# I nclude <intrinsics. h>
Void main (void)
{
Portb =__ LPM (0x12); // read data from the specified flash space address unit 0x12
}
_ Extended_load_program_memory (const unsigned char _ farflash *);
// 128k Space _ elpm (ADDR); // 128k Space
It is easier to write with reference to the above understanding and modification.

4. Self-programmed functions:
_ Spm_get_lockbits (); // read and shrink location
_ Spm_get_fusebits (); // read the fuse bit
_ Spm_erase (ADDR); // 16-bit page Erasure
_ Spm_filltemp (ADDR, word); // 16-bit page Buffer
_ Spm_pagewrite (ADDR;) // write a 16-bit page
_ Spm_24_erase (ADDR); // 24-bit page Erasure
_ Spm_24_filltemp (ADDR, data); // 24-bit page Buffer
_ Spm_24_pagewrite (ADDR) // 24-bit page write

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.