void CH375FileByteRead_320(UINT16 N_bit,UINT16 C_line) { static UINT8 i,ch; UINT16 k=0; UINT16 TotalCount,c; volatile uint16 *file_bit_buff_1;
file_bit_buff_1 = (volatile uint16 *)(ExSRAM_ADDR1); // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); /* 文件名,該文件在C51子目錄下 */ // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); // i = CH375FileOpen( ); /* 打開文件 */ TotalCount = N_bit; /* 準備讀取總長度 */ // MAX_BYTE_IO=32 // printf( "從文件中讀出的前%d個字符是:\n",TotalCount ); // mCmdParam.ByteLocate.mByteOffset = 650*C_line; // 跳過文件的前324個字節(jié)開始讀寫,估計多出了換行。 CH375ByteLocate( ); while ( TotalCount ) { /* 如果文件比較大,一次讀不完,可以再調(diào)用CH375ByteRead繼續(xù)讀取,文件指針自動向后移動 */ if ( TotalCount > MAX_BYTE_IO ) c = MAX_BYTE_IO; /* 剩余數(shù)據(jù)較多,限制單次讀寫的長度不能超過 sizeof( mCmdParam.ByteRead.mByteBuffer ) */ else c = TotalCount; /* 最后剩余的字節(jié)數(shù) */ mCmdParam.ByteRead.mByteCount = c; /* 請求讀出幾十字節(jié)數(shù)據(jù) */ i = CH375ByteRead( ); /* 以字節(jié)為單位讀取數(shù)據(jù)塊,單次讀寫的長度不能超過MAX_BYTE_IO,第二次調(diào)用時接著剛才的向后讀 */ mStopIfError( i ); TotalCount -= mCmdParam.ByteRead.mByteCount; /* 計數(shù),減去當前實際已經(jīng)讀出的字符數(shù) */ for ( i=0; i // printf( "%C", mCmdParam.ByteRead.mByteBuffer[i] ); /* 顯示讀出的字符 */ // file_bit_buff_1 [k++] = mCmdParam.ByteRead.mByteBuffer[i] ; //處理 { ch = (mCmdParam.ByteRead.mByteBuffer[i]) ; if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k]=ch<<4 ; ch = (mCmdParam.ByteRead.mByteBuffer[++i]) ; if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k++] |= ch ; } if ( mCmdParam.ByteRead.mByteCount < c ) { /* 實際讀出的字符數(shù)少于要求讀出的字符數(shù),說明已經(jīng)到文件的結(jié)尾 */ // printf( "\n" ); // printf( "文件已經(jīng)結(jié)束\n" ); break; } } } 問題: ch375讀取文本文件。 當讀取到10600左右個字節(jié)時,沒有按正常順序讀出,10600前都正常。是什么原因產(chǎn)生的?