RAM、ROM自检函数在DEBUG调试的时候,发现自定义的指针赋值语句无效,不被执行。指针变量显示未分配,不知道指针变量的问题出在哪里,本人初学者,还请各位不吝啬赐教,指出函数的问题,谢谢!
uint8_t Test_ROM(uint16_t *startadr,uint16_t *endadr)
{
uint16_t *adrptr = startadr;
uint16_t sum = 0;
uint16_t i = 0;
uint16_t CHECKSUM = 0;
//adrptr = startadr;
for(i=0;i<=(endadr-startadr);i++)
{
(*adrptr) = i;
adrptr++;
}
CHECKSUM = (endadr-startadr)/2; //等差求和公式
adrptr = startadr;
for(i=0;i<=(endadr-startadr);i++)
{
sum = sum + (*adrptr);
adrptr++;
}
if(sum != CHECKSUM) return 1;
return 0;
}
uint8_t Test_RAM(uint16_t *startadr,uint16_t *endadr)
{
uint16_t adrgroup[16] = {0x7FFF,0xBFFF,0xDFFF,0xEFFF,0xF7FF,0xFBFF,0xFDFF,0xFEFF,0xFF7F,0xFFBF,0xFFDF,0xFFEF,0xFFF7,0xFFFB,0xFFFD,0xFFFE};
uint16_t adrgroup1[16] = {0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};
uint16_t *adrptr=0;
uint16_t i;
/*** 地址线 ***/
for (i = 0;i < 16;i++) //0滑动
{
adrptr = (uint16_t *)0x1000;
//adrptr = (uint16_t *)(adrgroup
);
*adrptr = 0x5555;
if((*adrptr) != 0x5555) return 1;
}
for (i = 0;i < 16;i++) //1滑动
{
adrptr = (uint16_t *)(adrgroup1);
*adrptr = 0xAAAA;
if ((*adrptr)!= 0xAAAA) return 1;
}
adrptr = (uint16_t *)0xFFFF; //全0变1
*adrptr = 0xAAAA;
adrptr = (uint16_t *)0x0000;
*adrptr = 0xAAAA;
adrptr = (uint16_t *)0xFFFF;
*adrptr = 0xAAAA;
adrptr = (uint16_t *)0x0000; //全1变0
*adrptr = 0x5555;
for(i = 0;i <= (endadr - startadr);i++) //粘连测试
{
adrptr = startadr;
*adrptr = i;
if(i != (*adrptr)) return 1;
adrptr++;
}
for(i = 0;i<300;i++) //全0全1高速变换
{
adrptr = (uint16_t *)0xFFFF;
*adrptr = 0xAAAA;
adrptr = (uint16_t *)0x0000;
*adrptr = 0xAAAA;
adrptr = (uint16_t *)0xFFFF;
*adrptr = 0x5555;
adrptr = (uint16_t *)0x0000;
*adrptr = 0x5555;
}
adrptr = (uint16_t *)0xFFFF;
if (0x5555 != (*adrptr)) return 1;
adrptr = (uint16_t *)0x0000;
if (0x5555 != (*adrptr)) return 1;
/*** 数据线 ***/
for (i = 0;i < 16;i++) //0滑动
{
adrptr = (uint16_t *)0xFFFF;
*adrptr = adrgroup;
if((*adrptr) != adrgroup) return 1;
}
for (i = 0;i < 16;i++) //1滑动
{
adrptr = (uint16_t *)0xFFFF;
*adrptr = adrgroup1;
if((*adrptr) != adrgroup1) return 1;
}
adrptr = startadr;
for(i=0;i<=(endadr-startadr);i++) //全0变1
{
*adrptr = 0;
*adrptr = 1;
if(1 != (*adrptr)) return 1;
adrptr++;
}
adrptr = startadr;
for(i=0;i<=(endadr-startadr);i++) //全1变0
{
*adrptr = 0;
if(0 != (*adrptr)) return 1;
adrptr++;
}
adrptr = (uint16_t *)0xFFFF;
for(i = 0;i<300;i++) //全0全1高速变换
{
*adrptr = 0xFFFF;
*adrptr = 0x0000;
}
if (0x0000 != (*adrptr)) return 1;
return 0;
}
void main(void)
{
Test_ROM((uint16_t *)0x4000,(uint16_t *)0x4010);
Test_RAM((uint16_t *)0x2000,(uint16_t *)0x2010);
}
此帖出自小平头技术问答
一周热门 更多>