以字節(jié)方式讀取文本???請hcn幫忙。

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)生的?

你的這部分程序沒什么問題。不正常會不會出錯呢?


什么地方出錯呢?


我的意思是說在你數(shù)據(jù)不正常的時候,會不會出錯,看下返回的錯誤代碼才可以進行分析


文本文件的數(shù)據(jù)不正常是怎么產(chǎn)生的? i = CH375ByteRead( ); i都會等于0。 5400015B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B15 5400025B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B16 以上文本類型

就是 讀行數(shù)多了,375讀取時會越過好幾行,大約10600左右個字節(jié)時,接著又能正常讀取數(shù)據(jù)了。 不知哪里出錯了??!


你可以不可以將你的程序發(fā)過來看下啊。 E-MIAL:tech@wch.cn


程序就是前面的。


int main_x( ) { ... ... //初始化硬件,ch375 while (1) { CH375File_open( FileTitle1); //打開文本 for (i=0x00;i<33;i++) CH375FileByteRead_320 (648,i ); CH375FileByteRead_320 (648,i ); //i等于33,讀的數(shù)據(jù)開始不正常,跳過8000多過字節(jié)。

for (i=0x33;i<240;i++) //接下來又正常的順序,但是否一直正常未知。 CH375FileByteRead_320 (648,i ); }

} //子程序 //每次讀648個字節(jié)。 如果有換行就多出字節(jié)了,說明文本要一定的格式!?。???? 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 ); /* 顯示讀出的字符 */ // file_bit_buff_1 [k++] = mCmdParam.ByteRead.mByteBuffer //處理 { ch = (mCmdParam.ByteRead.mByteBuffer) 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; } } }


我要讀取2M的文本,以上程序只是測試,LOCATE的命令是在什么子程序中產(chǎn)生的?


多字節(jié)寫入也存在問題。512字節(jié)*10次后就不能寫入了,等待375中斷,一直沒反應。


mCmdParam.ByteLocate.mByteOffset = 608; 跳過文件的前608個字節(jié)開始讀寫 CH375ByteLocate( ); 只要文件不關閉,就可以不用ByteLocate,文件自動按順序。


如果按照你上面的說法的話,你讀2M的數(shù)據(jù)的話,你沒必要用LOCATE這個命令,你在你的TotalCount的輸入的數(shù)據(jù)為文件的總長度CH375vFileSize,這樣的話,你就可以在那邊進行循環(huán)的讀取數(shù)據(jù)了,還有就是你用的是什么單片機?我在這邊用51單片機做過測試的,讀取2M的文件的時候是沒有問題的,如果是51的話,你可以參考這個例子UploadImages/hcn0012006629135025.rar


總長度CH375vFileSize,哦,我考慮


很多時候會,等待375中斷。是不是PCB不好??!


很多時候會,等待375中斷。是不是PCB不好?,還是哪些參數(shù)沒設好(時間控制),我用lpc2212單片機,請指導!


這是一個2212的例子程序,先進行AD采集,將采集的數(shù)據(jù)存到U盤里面去的例子,你測試下看可以不可以。我在這邊測試的時候是以總線方式進行測試的,你如果不是的話,你可以將其改寫為模擬口的方式,如果這個程序在寫的過過程中還有問題的話,那可能就是你硬件有點問題了,否則就是你軟件上面有點問題UploadImages/hcn0012006630173132.rar


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频