1.我首先用的是ch375hf6.lib和ch375hf6.h 2.当我在main函数里设一个unsigned char xdata buf[512]的时候,出现xdata=1111,然后下载到stc11F16XE中运行出现异常,程序根本不运行 3.当我吧xdata buf[512]改为xdata buf[256]时,程序可以开始运行,但是不能正常进行扇区读写。 4.此时我以为是单片机内部扩展ram的问题,于是换了个内部扩展ram为4k的STC90C58RD+。 但是此时在超级终端中出现乱码(波特率正确)!
请各位大侠帮小弟看看问题出在哪,到底是ch375hf6.lib和ch375hf6.h要修改,还是ram的大小问题?谢谢了
PS:没有define FILE_DATA_BUF_LEN 512 只有define DISK_BASE_BUF_LEN 512
main函数如下:
#include #include #include "uart.h" #include "myfun.h"
#define CH375_CMD_PORT_ADDR 0x8DF1 /* CH375命令端口的I/O地址 */ #define CH375_DAT_PORT_ADDR 0x8CF0 /* CH375数据端口的I/O地址 */
#include "ch375hf6.h"
unsigned char i,j,len;
unsigned char xdata buf[512];
sfr BUS_SPEED=0xa1;
void delay(unsigned int time) { while(time--); }
void main() { BUS_SPEED=0x27;//调整总线速度 UART_Init(); UART_Send_Str("串口通信测试...\n");
if(!CH375LibInit()) { UART_Send_Str("初始化CH375程序库及CH375芯片成功!\n"); UART_Send_Str("插入U盘\n");
UART_Send_Str("开始检测U盘是否插入...\n"); while(CH375DiskConnect()!=ERR_SUCCESS) { delay(3000); } UART_Send_Str("U盘已经插入\n");
UART_Send_Str("开始检测U盘是否就绪...\n"); while(CH375DiskReady()!=ERR_SUCCESS) { delay(1000); } UART_Send_Str("U盘已经就绪,可以操作\n");
UART_Send_Str("获取磁盘物理总容量...\n"); CH375DiskSize(); UART_Put_Inf("硬盘物理总容量为(扇区):",mCmdParam.DiskSize.mDiskSizeSec);
UART_Send_Str("获取磁盘信息...\n"); CH375DiskQuery(); UART_Put_Inf("磁盘总容量(兆):",mCmdParam.Query.mTotalSector/2048); UART_Put_Inf("剩余容量(兆):",mCmdParam.Query.mFreeSector/2048); strcpy(mCmdParam.Open.mPathName,"\\TEST.TXT"); UART_Send_Str("打开文件/目录:"); UART_Send_Str(mCmdParam.Open.mPathName); UART_Send_Str("\n");
if(CH375FileOpen()==ERR_SUCCESS) { UART_Send_Str("打开文件/目录成功\n");
UART_Put_Inf("当前文件的偏移量为:",CH375vCurrentOffset);
UART_Send_Str("以扇区模式写入:\n"); mCmdParam.Locate.mSectorOffset=1; CH375FileLocate(); UART_Put_Inf("当前文件的偏移量为:",CH375vCurrentOffset); for(i=0;i { buf[i]='a'; } mCmdParam.WriteX.mDataBuffer=buf; mCmdParam.WriteX.mSectorCount=1; CH375FileWriteX();
mCmdParam.WriteX.mDataBuffer=buf; mCmdParam.WriteX.mSectorCount=0; CH375FileWriteX(); } else { UART_Send_Str("打开文件/目录失败\n"); } } else { UART_Send_Str("初始化CH375程序库及CH375芯片失败!\n"); } while(1); }