due to restrictions on the number of Flash writes and the write erasure wait time, flash variables and flash counters are difficult to construct. because '0' cannot be changed to '1', The Flash variable cannot be located on a storage unit address. Similarly, flash counters are the same. after careful analysis of "Flash secondary writing technology", it is not difficult to see that if you make some changes, you can implement real Flash variables and flash counters. the counter is set to +/-1 every time it is encountered. Why can't one bit be cleared to "counter ??? flash generally has a large space and is erased in almost all sectors. assume that the flash counter is 8 bits, that is, 0 ~ 255, 256/8 = 32 bytes can be allocated as the "Flash timer", namely: 0xff, 0xff ....., 0xff indicates 0x00 0xfe, 0xff ....., 0xff indicates 0x01 0xfc, 0xff ....., 0xff indicates 0x02 ........................... 0x00, 0xff ....., 0xff indicates 0x07 0x00, 0xfe ....., 0xff indicates 0x08 0x00, 0xfc ....., 0xff indicates 0x09 ........................... 0x00, 0x00 ....., 0xff indicates 0x0f ........................... 0x00, 0x00 ....., 0x00 indicates 0xff for flash variables, the address must be rewritten at a time based on the principle of address + 1. Number of incoming requests ". it is generally used in combination with the flash timer, that is, the flash timer is actually a "Write Pointer" of the flash variable ". when "Write count" is full, the sector where the flash counter and flash variable are located is cleared. note that the flash counter should be read to ram after initialization !!! When writing the flash variable, you must also update the flash counter to prevent power loss before reading the value of the flash counter into RAM. generally, when a flash variable is used for infrequent rewriting, you must read the flash variable into RAM if you need to rewrite it frequently. that is, the instance is running in Ram, And the instance is powered on or in flash. |