查了一下,bmp文件的第3~6字节记录了整个bmp文件的大小,所以用语句: fileSize=*((U8 *)(downloadAddress+2))+ (*((U8 *)(downloadAddress+3))<<8)+ (*((U8 *)(downloadAddress+4))<<16)+ (*((U8 *)(downloadAddress+5))<<24); 就可以得到整个文件的大小。(downloadAddress是ram中下载地址的首地址。)
之后就按照这个文件的大小按字节为单位下载到ram中就可以了。但是实验中我发现,程序运行过程中下载到16500个字节以后就停止了,应该是死循环了。我想了一下,如果fileSize的取值很大可文件却很小的话很有可能会变成这样,这是怎么回事呢?按说应该没错阿。
还有我是用超级终端监视的,用的里面的'发送文本文件'传送的bmp文件,是不是这样做不对阿???
源程序: int DownloadData(void) { U32 i; U32 fileSize=10; U8 *downPt; U8 discard;
downPt=(U8 *)downloadAddress; Uart_Printf("downloadAddress=%x\n",downloadAddress);
rINTMSK=~BIT_GLOBAL;
if(!(rUTRSTAT0&0x1)) { discard=RdURXH0(); //To remove overrun error state. }
Uart_Printf("Receive the bmp file from UART:"); i=0; while(i<fileSize) { while(!(rUTRSTAT0&0x1)); *(downPt+i)=RdURXH0(); if(i==5) { fileSize=*((U8 *)(downloadAddress+2))+ (*((U8 *)(downloadAddress+3))<<8)+ (*((U8 *)(downloadAddress+4))<<16)+ (*((U8 *)(downloadAddress+5))<<24); Uart_Printf("\n%x",*((U8 *)(downloadAddress+2))); Uart_Printf("\n%x",*((U8 *)(downloadAddress+3))); Uart_Printf("\n%x",*((U8 *)(downloadAddress+4))); Uart_Printf("\n%x",*((U8 *)(downloadAddress+5)));
Uart_Printf("\n%x",fileSize); } i++; Delay(100); }
downloadProgramSize=fileSize;
Uart_Printf("\nDownload O.K.\n"); while(1); return 1; }
|