这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » philips51 求助:philips51的单片机读写U盘的问题 附源码

共2条 1/1 1 跳转至

philips51 求助:philips51的单片机读写U盘的问题 附源码

院士
2006-09-17 18:14:16     打赏
philips51 求助:philips51的单片机读写U盘的问题 附源码



关键词: philips51     求助     单片机     读写     问题     源码    

院士
2006-12-22 22:43:00     打赏
2楼
问 这是读写U盘部分的源码
我们的单片机在读写U盘的时候遇到了问题,主要是,U盘里的数据单片机可以读,在写U盘的时候能够成功的写入文件名
用计算机打开文件以后,里面却时空的,没有数据,有能帮忙解决的朋友我请吃饭呀
附程序源码如下:
printf( "Wait Udisk\n" );
while ( CH375DiskStatus != DISK_CONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );


for ( i = 0; i < 10; i ++ ) {
mDelay100mS( );
printf( "Ready ?\n" );
if ( CH375DiskReady( ) == ERR_SUCCESS ) break;
}

printf( "Open\n" );
mCopyCodeStringToIRAM( mCmdParam.Open.mPathName, "/MY_ADC.TXT" );
i = CH375FileOpen( );
if ( i == ERR_SUCCESS ) {
printf( "File size = %ld\n", CH375vFileSize );
printf( "Locate tail\n" );
mCmdParam.ByteLocate.mByteOffset = 0xffffffff;
i = CH375ByteLocate( );
mStopIfError( i );
}
else if ( i == ERR_MISS_FILE ) {
printf( "Create\n" );
i = CH375FileCreate( );
mStopIfError( i );
}
else mStopIfError( i ); /* 打开文件时出错 */
printf( "Write begin\n" );
i = sprintf( mCmdParam.ByteWrite.mByteBuffer, "此前文件长度= %ld 字节\xd\xa", CH375vFileSize );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Write ADC data\n" );
TR0=1;
for ( hour = 8; hour != 20; hour ++ ) {
month = 5;
date = TL1 & 0x1F;
adc = get_adc_data( );
adc = ( (UINT16)TH0 << 8 ) | TL0;
len = sprintf( mCmdParam.ByteWrite.mByteBuffer, "%02d.%02d.%02d ADC=%u\xd\xa", (UINT16)month, date, (UINT16)hour, adc );
mCmdParam.ByteWrite.mByteCount = (unsigned char)len;
i = CH375ByteWrite( );
mStopIfError( i );
printf( "Current offset ( file point ) is %ld\n", CH375vCurrentOffset );
}
mCmdParam.ByteWrite.mByteCount = 0;
printf( "Write end\n" );
i = mCopyCodeStringToIRAM( mCmdParam.ByteWrite.mByteBuffer, "数据到此结束\xd\xa" );
mCmdParam.ByteWrite.mByteCount = i;
i = CH375ByteWrite( );
printf( "Close\n" );
mCmdParam.Close.mUpdateLen = 1;
i = CH375FileClose( );
mStopIfError( i );
printf( "Take out\n" );
while ( CH375DiskStatus != DISK_DISCONNECT ) xQueryInterrupt( );
mDelay100mS( );
mDelay100mS( );
}
1: 搞错了吧!  沁恒的片子拿到ARM版来请教。

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]