新接触KEIL,程序有个功能是读SD卡文件UPDATE.UDT来升级烧录机程序,但不会用,也看不明代码,也不知这个UPDATE.UDT是怎么来的,只有代码,但不知这个代码有没有问题,原来的程序员跑了也不告诉,希望有大神能帮我,谢谢,以下为更新的代码。
void Update(void)
{
unsigned char count,temp,tmp1,tmp2,tmp3,tmp4;
unsigned char FlashBuffer[0x800];
unsigned long i,cnt,j;
while(EEPROMReadBuffer(EEPROMBuffer,0,128)==0);
if(UpdateFlag)
{
LCDWriteCmdU(0x01);
if(LanguageType == 0)
{
LCDWriteCmdU(0x80);
LCDWriteDataU('U');
LCDWriteDataU('p');
LCDWriteDataU('d');
LCDWriteDataU('a');
LCDWriteDataU('t');
LCDWriteDataU('e');
LCDWriteDataU(':');
LCDWriteCmdU(0x90);
LCDWriteDataU('U');
LCDWriteDataU('p');
LCDWriteDataU('d');
LCDWriteDataU('a');
LCDWriteDataU('t');
LCDWriteDataU('i');
LCDWriteDataU('n');
LCDWriteDataU('g');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
}
else
{
LCDWriteCmdU(0x80);
LCDWriteDataU(0xc9);
LCDWriteDataU(0xfd);
LCDWriteDataU(0xbc);
LCDWriteDataU(0xb6);
LCDWriteDataU(':');
LCDWriteCmdU(0x90);
LCDWriteDataU(0xd5);
LCDWriteDataU(0xfd);
LCDWriteDataU(0xd4);
LCDWriteDataU(0xda);
LCDWriteDataU(0xc9);
LCDWriteDataU(0xfd);
LCDWriteDataU(0xbc);
LCDWriteDataU(0xb6);
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
}
if(SDOperation()) //SD卡系統文件初始化
{
Command.Parameter[0] = 'U';
Command.Parameter[1] = 'P';
Command.Parameter[2] = 'D';
Command.Parameter[3] = 'A';
Command.Parameter[4] = 'T';
Command.Parameter[5] = 'E';
Command.Parameter[6] = 0x20;
Command.Parameter[7] = 0x20;
Command.Parameter[8] = 'U';
Command.Parameter[9] = 'D';
Command.Parameter[10] = 'T';
Command.Parameter[11] = 0x20;
bFlags.bits.bOperate=1;
Command.CLass=1;
SDOperation(); //打開文件
}
else
{
if(LanguageType == 0)
{
LCDWriteCmdU(0x90);
LCDWriteDataU('S');
LCDWriteDataU('D');
LCDWriteDataU(' ');
LCDWriteDataU('c');
LCDWriteDataU('a');
LCDWriteDataU('r');
LCDWriteDataU('d');
LCDWriteDataU(' ');
LCDWriteDataU('i');
LCDWriteDataU('s');
LCDWriteDataU(' ');
LCDWriteDataU('e');
LCDWriteDataU('r');
LCDWriteDataU('r');
LCDWriteDataU('o');
LCDWriteDataU('r');
LCDWriteDataU('!');
}
else
{
LCDWriteCmdU(0x90);
LCDWriteDataU(0x53);
LCDWriteDataU(0x44);
LCDWriteDataU(0xbf);
LCDWriteDataU(0xa8);
LCDWriteDataU(0xed);
LCDWriteDataU(0xce);
LCDWriteDataU(0xbc);
LCDWriteDataU(0xf3);
LCDWriteDataU(0x21);
}
while(ReadKeyU()==0);
return;
}
if(Response.Result)
{
cnt = LSwapINT32(FileName[0x1c],FileName[0x1d],FileName[0x1e],FileName[0x1f]);
ReadFile32(512,DBUF); //讀文件
temp = DBUF[0x100];
temp = temp - 0x55;
temp = temp ^ 0xaa;
if(temp != 0x55)
{
return;
}
temp = DBUF[0x101];
temp = temp - 0x55;
temp = temp ^ 0xaa;
if(temp != 0xaa)
{
return;
}
temp = DBUF[0x102];
temp = temp - 0x55;
temp = temp ^ 0xaa;
if(temp != 0x33)
{
return;
}
temp = DBUF[0x103];
temp = temp - 0x55;
temp = temp ^ 0xaa;
if(temp != 0xcc)
{
return;
}
temp = DBUF[0x30];
temp = temp - 0x55;
tmp1 = temp ^ 0xaa;
temp = DBUF[0x31];
temp = temp - 0x55;
tmp2 = temp ^ 0xaa;
temp = DBUF[0x32];
temp = temp - 0x55;
tmp3 = temp ^ 0xaa;;
temp = DBUF[0x33];
temp = temp - 0x55;
tmp4 = temp ^ 0xaa;
ProgramFileLength = 0xf000;
count = 0;
for(i=0x0;i < (cnt-0x200);)
{
ReadFile32(512,DBUF); //讀文件
i = i+ 0x200;
for(j=0;j<0x200;j++)
{
temp = DBUF[j];
temp = temp - 0x55;
temp = temp ^ 0xaa;
FlashBuffer[j] = temp;
}
ReadFile32(512,DBUF); //讀文件
i = i+ 0x200;
for(j=0;j<0x200;j++)
{
temp = DBUF[j];
temp = temp - 0x55;
temp = temp ^ 0xaa;
FlashBuffer[0x200+j] = temp;
}
ReadFile32(512,DBUF); //讀文件
i = i+ 0x200;
for(j=0;j<0x200;j++)
{
temp = DBUF[j];
temp = temp - 0x55;
temp = temp ^ 0xaa;
FlashBuffer[0x400+j] = temp;
}
ReadFile32(512,DBUF); //讀文件
i = i+ 0x200;
for(j=0;j<0x200;j++)
{
temp = DBUF[j];
temp = temp - 0x55;
temp = temp ^ 0xaa;
FlashBuffer[0x600+j] = temp;
}
Flash_Write(FlashBuffer,ProgramFileLength,0x800);
ProgramFileLength += 0x800;
count++;
if(count >= 7)
count = 0;
LCDWriteCmdU(0x94);
if(count == 0)
{
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
}
else if(count == 1)
{
LCDWriteDataU('.');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
}
else if(count == 2)
{
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
}
else if(count == 3)
{
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
}
else if(count == 4)
{
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU(' ');
LCDWriteDataU(' ');
}
else if(count == 5)
{
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU(' ');
}
else if(count == 6)
{
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
LCDWriteDataU('.');
}
}
while(EEPROMWrite1Byte(0x30,tmp1)==0);
while(EEPROMWrite1Byte(0x31,tmp2)==0);
while(EEPROMWrite1Byte(0x32,tmp3)==0);
while(EEPROMWrite1Byte(0x33,tmp4)==0);
(*(unsigned long *)0xe000ed0c) = 0x05fa0004;
Reset();
}
else
{
if(LanguageType == 0)
{
LCDWriteCmdU(0x90);
LCDWriteDataU('S');
LCDWriteDataU('D');
LCDWriteDataU(' ');
LCDWriteDataU('i');
LCDWriteDataU('s');
LCDWriteDataU(' ');
LCDWriteDataU('n');
LCDWriteDataU('o');
LCDWriteDataU(' ');
LCDWriteDataU('f');
LCDWriteDataU('i');
LCDWriteDataU('l');
LCDWriteDataU('e');
LCDWriteDataU('!');
}
else
{
LCDWriteCmdU(0x90);
LCDWriteDataU(0x53);
LCDWriteDataU(0x44);
LCDWriteDataU(0xbf);
LCDWriteDataU(0xa8);
LCDWriteDataU(0xc3);
LCDWriteDataU(0xbb);
LCDWriteDataU(0xd3);
LCDWriteDataU(0xd0);
LCDWriteDataU(0xce);
LCDWriteDataU(0xc4);
LCDWriteDataU(0xbc);
LCDWriteDataU(0xfe);
LCDWriteDataU(0x21);
}
while(ReadKeyU()==0);
}
}
}
我只看到
ReadFile32(512,DBUF); //讀文件
以下TEMP不知为什么不对就退出也不知为什么要0x100之类的
temp = DBUF[0x100];
temp = temp - 0x55;
temp = temp ^ 0xaa;
if(temp != 0x55){
return;
} } |