错误的例子:
/* Variables' number */
#define NumbOfVar ((uint8_t)0x05)
uint16_t VirtAddVarTab[NumbOfVar] = {0, 1, 2};
//NumbOfVar 定义的比用的多实际是{0, 1, 2, 0, 0},虚拟地址0 的数据换页后将出现旧数据覆盖最新数据
int main(void)
{
uint16_t temp;
for (VarValue = 0; VarValue < 100; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[0], VarValue+10);
}
for (VarValue = 0; VarValue < 500; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[1], VarValue);
temp=0;
EE_ReadVariable(0, &temp);//不换页读出数据是对的,换页后读出数据错误
}
}
//====================================================================================
/* Variables' number */
#define NumbOfVar ((uint8_t)0x03)
uint16_t VirtAddVarTab[NumbOfVar] = {0, 1, 2};
//NumbOfVar 定义为3,下面用到虚拟地址超过VirtAddVarTab 表里面的值
int main(void)
{
uint16_t temp;
for (VarValue = 0; VarValue < 100; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[0], VarValue);
}
for (VarValue = 0; VarValue < 50; VarValue++)
{
EE_WriteVariable(3, VarValue+2);
}
for (VarValue = 0; VarValue < 200; VarValue++)
{
EE_WriteVariable(2, VarValue);
temp=0;
EE_ReadVariable(3, &temp);//不换页读出数据是对的,换页后读出数据错误
}
}
|