共2条
1/1 1 跳转至页
philips51 求助:philips51的单片机读写U盘的问题 附源码
问
这是读写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版来请教。
我们的单片机在读写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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |