(1)晶振起振,12MHz (2)25腳為低電平,26腳為高電平 全部正常!
就這樣結(jié)束了?
那你這樣吧,把程序貼出來我們看看!
http://wch.cn/bbs/View.asp?S=101&I=24703 按這個(gè)主題的程序好了!問題現(xiàn)在就出現(xiàn)在這兒!按回貼的程序也試過了!行不通!
void CPU_Delay_US(word USTime)//精確的1us延時(shí)處理 { word i; for(i=0;i} void CH375_WR_CMD(byte Command) { CH375_WR=0; CH375_RD=1; CH375_CS=0; CH375_A0=1; Data_IO =0xff; CPU_Delay_US(3); CH375_Data=Command; CPU_Delay_US(3); CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_Data=0; }
void CH375_WR_DAT(byte Data) { CH375_WR=0; CH375_RD=1; CH375_CS=0; CH375_A0=0; Data_IO =0xff; CPU_Delay_US(2); CH375_Data=Data; CPU_Delay_US(2); CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_A0=1; CH375_Data=0; }
byte CH375_RD_DAT(void) { byte ReadByte; CH375_WR=1; CH375_RD=0; CH375_CS=0; CH375_A0=0; Data_IO =0x00; CPU_Delay_US(3); ReadByte=CH375_Data; Data_IO =0xff; CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_A0=1; CH375_Data=0; return ReadByte; }
byte Set_USB_Mode(void) { byte ReadByte; CH375_WR_CMD(CMD_SET_USB_MODE); CPU_Delay_US(20); CH375_WR_DAT(6); CPU_Delay_US(20); ReadByte=CH375_RD_DAT(); if(ReadByte==CMD_RET_SUCCESS) return TRUE; //操作成功 return FALSE; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte CHBUF[CHBUF_LENGTH]; SYS_INFO_BLOCK DeviceInfo; CH_CMD_BLOCK CHCmdBlock; CH_RSP_BLOCK CHRspBlock; FILE_INFO ThisFile;
byte EnumMassDev(void) { byte ReadByte; PMBR_BLOCK pMBR; PBPB_BLOCK pBPB; CH375_WR_CMD(CMD_DISK_INIT); // 初始化USB存儲(chǔ)器 CPU_Delay_US(20); if(mWaitInterrupt()!=USB_INT_SUCCESS) return FALSE; // U盤已經(jīng)成功初始化
pMBR=(PMBR_BLOCK)DBUF; DeviceInfo.BPB_BytesPerSec=512; //暫假設(shè)為512
//檢查USB存儲(chǔ)器錯(cuò)誤 CH375_WR_CMD(CMD_DISK_R_SENSE); CPU_Delay_US(20); if(mWaitInterrupt()!=USB_INT_SUCCESS ) return FALSE; //讀容量 if(!ReadCapacity()) return FALSE;
//讀指定扇區(qū)的數(shù)據(jù)到給這緩沖區(qū)中 //未調(diào)通 if(!RBC_Read(0x00,1,DBUF)) return FALSE; /* if(DBUF[0]==0xeb||DBUF[0]==0xe9) { DeviceInfo.StartSector=0; } else { DeviceInfo.StartSector=Swapdword(pMBR->StartSector); }
pBPB=(PBPB_BLOCK)DBUF; if(!RBC_Read(DeviceInfo.StartSector,1,DBUF)) return FALSE;
DeviceInfo.BPB_BytesPerSec=Swapword(pBPB->BPB_BytesPerSec); DeviceInfo.BPB_SecPerClus=pBPB->BPB_SecPerClus; DeviceInfo.BPB_NumFATs=pBPB->BPB_NumFATs; DeviceInfo.BPB_RootEntCnt=Swapword(pBPB->BPB_RootEntCnt); DeviceInfo.BPB_TotSec16=Swapword(pBPB->BPB_TotSec16); DeviceInfo.BPB_FATSz16=Swapword(pBPB->BPB_FATSz16); DeviceInfo.BPB_TotSec32=Swapdword(pBPB->BPB_TotSec32); DeviceInfo.FatStartSector=DeviceInfo.StartSector+pBPB->BPB_RsvdSecCn[0]; DeviceInfo.RootStartSector=DeviceInfo.StartSector+2*DeviceInfo.BPB_FATSz16+pBPB->BPB_RsvdSecCn[0]; DeviceInfo.FirstDataSector=DeviceInfo.FatStartSector+2*DeviceInfo.BPB_FATSz16+32; ThisFile.bFileOpen=0; bXXGFlags.bits.SLAVE_IS_ATTACHED=1; */ return TRUE; }
byte mWaitInterrupt(void) { byte ReadByte=0; while (CH375_INT_WIRE) ; // 如果CH375的中斷引腳輸出高電平則等待 while(!CH375_INT_WIRE) // 保證能取消中斷狀態(tài) { CH375_WR_CMD(CMD_GET_STATUS); // 獲取當(dāng)前中斷狀態(tài) CPU_Delay_US(20); ReadByte=CH375_RD_DAT(); // 返回中斷狀態(tài) CPU_Delay_US(20); } return(ReadByte); }
//#define TranR_D; byte ReadCapacity(void) { byte *buf; byte ReadByte=0; #ifdef TranR_D byte SaveLong=0; #endif buf=DBUF; CH375_WR_CMD(CMD_DISK_SIZE);// 讀取容量 CPU_Delay_US(20); while(mWaitInterrupt()!=USB_INT_SUCCESS) { CPU_Delay_US(20); CH375_WR_CMD(CMD_DISK_SIZE);// 讀取容量 CPU_Delay_US(20); } CH375_WR_CMD(CMD_RD_USB_DATA); // 從CH375緩沖區(qū)讀取數(shù)據(jù)塊 CPU_Delay_US(300); ReadByte=CH375_RD_DAT(); // 后續(xù)數(shù)據(jù)的長度 CPU_Delay_US(20); #ifdef TranR_D SaveLong=ReadByte; #endif while(ReadByte) // 根據(jù)長度讀取數(shù)據(jù)并保存 { *buf=CH375_RD_DAT(); buf++; ReadByte--; CPU_Delay_US(20); } #ifdef TranR_D for(ReadByte=0;ReadByte { SCI0DRL=DBUF[ReadByte]; while((SCI0SR1&0x80)==0) ; } #endif return TRUE; }
//iLbaStart 是讀取的線起始性扇區(qū)號(hào), iSectorCount 是讀取的扇區(qū)數(shù) byte RBC_Read(dword iLbaStart, byte iSectorCount,byte *mBufferPoint) { word mBlockCount; byte ReadByte=0; byte SaveLong=0;
SCI0DRL=0x11;//用于示波器查找本部分程序運(yùn)行起始位置 while((SCI0SR1&0x80)==0) ; CPU_Delay_US(500); CH375_WR_CMD(CMD_DISK_READ); // 從USB存儲(chǔ)器讀數(shù)據(jù)塊 CPU_Delay_US(20); CH375_WR_DAT((byte)iLbaStart); // LBA的最低8位 CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>8)); CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>16)); CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>24)); // LBA的最高8位 CPU_Delay_US(20); CH375_WR_DAT(iSectorCount); // 扇區(qū)數(shù) for(mBlockCount=iSectorCount*CH375_BLK_PER_SEC; mBlockCount!=0; mBlockCount--) { if(mWaitInterrupt()==USB_INT_DISK_READ) { CH375_WR_CMD(CMD_RD_USB_DATA); // 從CH375緩沖區(qū)讀取數(shù)據(jù)塊 CPU_Delay_US(30); ReadByte=CH375_RD_DAT(); ReadByte=64; while (ReadByte) { CPU_Delay_US(10); *mBufferPoint=CH375_RD_DAT(); mBufferPoint++; ReadByte--; } CH375_WR_CMD(CMD_DISK_RD_GO); } else break; } if(mBlockCount==0) { // 等待中斷并獲取狀態(tài) SCI0DRL=0x55; while((SCI0SR1&0x80)==0) ; if(mWaitInterrupt()==USB_INT_SUCCESS) return TRUE; // 操作成功 } SCI0DRL=0xAA; while((SCI0SR1&0x80)==0) ; SCI0DRL=mBlockCount; while((SCI0SR1&0x80)==0) ; return FALSE; // 操作失敗 }
程序員懷疑硬件電路上有問題!
你的時(shí)序由些問題 void CH375_WR_CMD(byte Command) { CH375_Data=Command; Data_IO =0xff; /* 置輸出方向 */ CH375_RD=1; CH375_A0=1; CH375_CS=0; CH375_WR=0; /*添加100ns的延時(shí)*/ CH375_WR=1; CH375_CS=1; CH375_A0=0; Data_IO =0x00; /* 置輸入方向 */ }
void CH375_WR_DAT(byte Data) { CH375_Data=Data; Data_IO =0xff; /* 置輸出方向 */ CH375_RD=1; CH375_A0=0; CH375_CS=0; CH375_WR=0; /*添加100ns的延時(shí)*/ CH375_WR=1; CH375_CS=1; Data_IO =0x00; /* 置輸入方向 */ }
byte CH375_RD_DAT(void) { byte ReadByte;
Data_IO =0x00; /* 置輸入方向 */ CH375_WR=1; CH375_A0=0; CH375_CS=0; CH375_RD=0; /*添加100ns的延時(shí)*/ ReadByte = CH375_Data; CH375_RD=1; CH375_CS=1; return ReadByte; }