tica, Tahoma, Arial, sans-serif">请问以下两种方式读取外部扩展RAM,有什么差别呢?为什么在我的程序返回的结果很怪呢?
方式一:
j = 0x0016;
k = 0x16;
pToV = &pV->bTsAddr;//0x4016
for( i = 0x16; i < RAM_LENGTH; i++ )
{
*pToV=k;
abSndBuffer [bWriteSndPtr++] = 0x5A; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)(i>>8); bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)i; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = 0x5A; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)k; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = 0x5A; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)*pToV; bSndCounter++;
StartSerialCommunication();
pToV++;
j++;k++;
}
串口接收如下结果:
5A 00 16 5A 16 5A 16
5A 00 17 5A 17 5A 17
5A 00 18 5A 18 5A 18
5A 00 19 5A 19 5A 19
5A 00 1A 5A 1A 5A 1A
5A 00 1B 5A 1B 5A 1B
5A 00 1C 5A 1C 5A 1C
5A 00 1D 5A 1D 5A 1D
5A 00 1E 5A 1E 5A 1E
5A 00 1F 5A 1F 5A 1F
5A 00 20 5A 20 5A 20
. . .
方式二:
j = 0x0016;
pToV = &pV->bTsAddr;
for( i = 0x16; i < RAM_LENGTH; )
{
*pToV = (uint8_t)(j>>8);
pToV++;
*pToV = (uint8_t)j;
pToV++;
abSndBuffer [bWriteSndPtr++] = 0x5A; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)(i>>8); bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)i; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)(j>>8); bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)j; bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)(*(pToV-2)); bSndCounter++;
abSndBuffer [bWriteSndPtr++] = (uint8_t)(*(pToV-1)); bSndCounter++;
StartSerialCommunication();
i+=2;
j+=2;
}
串口接收如下结果:
5A 00 16 00 16 16 17
5A 00 18 00 18 18 19
5A 00 1A 00 1A 1A 1B
5A 00 1C 00 1C 1C 1D
5A 00 1E 00 1E 1E 1F
5A 00 20 00 20 20 21
. . .
各位帮忙看看吧,实在找不出问题在哪里
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>