EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 489

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 473 -
Note: For general purpose, the program does not recognize whether the sector is valid or not, and the user decides according to the
specific model.
Date: 2021-11-5
******************************************/
#include "config.H"
#include "EEPROM.h"
#define Baudrate1 115200L
/************* local constant declaration **************/
u8 code T_StringD[]={"
去年今日此门中,人面桃花相映红。人面不知何处去,桃花依旧笑春风。
"};
u8 code T_StringW[]={"
横看成岭侧成峰,远近高低各不同。不识庐山真面目,只缘身在此山中。
"};
/************* local variable declaration **************/
u8 xdata tmp[70]; //General data
u8 xdata SaveTmp[70]; // array to write
bit B_TX1_Busy;
u8 cmd; // single character command of UART
/************* local function declaration **************/
void UART1_config(void);
void TX1_write2buff(u8 dat); //write send buffer
void PrintString1(u8 *puts); //send a string
/************* External function and variable declarations *****************/
/************* Read the EEPROM record, and verify, return the verification result, 0 is correct, 1 is wrong*****************/
u8 ReadRecord(u16 addr)
{
u8 i;
u16 ChckSum; //Calculated cumulative sum
u16 j; //Accumulated sum of reading
for(i=0; i<66; i++) tmp[i] = 0; //clear buffer
PassWord = D_PASSWORD; //given password
EEPROM_read_n(addr,tmp,66); //read sector 0
for(ChckSum=0, i=0; i<64; i++)
ChckSum += tmp[i]; //Calculate the cumulative sum
j = ((u16)tmp[64]<<8) + (u16)tmp[65]; //Read cumulative sum of records
j ^= 0x5555; //Invert every other bit, avoid all 0s
if(ChckSum != j) return 1; //If the cumulative sum is wrong, return 1
return 0; // If the cumulative sum is right, return 0
}
/************* Write the EEPROM record, and verify, return the verification result, 0 is correct, 1 is wrong *****************/
u8 SaveRecord(u16 addr)
{
u8 i;
u16 ChckSum; //Calculated cumulative sum
for(ChckSum=0, i=0; i<64; i++)

Table of Contents

Related product manuals