讀取扇區(qū)正常 但是寫入扇區(qū)發(fā)生錯(cuò)誤,寫扇區(qū)錯(cuò)誤時(shí)返回的狀態(tài)碼是1FH(USB存儲(chǔ)器操作失敗),弄了好幾天也沒弄明白,高手們幫看一下,部分代碼如下: void CH375_Write_Cmd(unsigned char cmd) //寫命令 { // CS=0; //強(qiáng)制片選,只有一個(gè)ch375,直接接地 A0=1; P2=cmd; WR=0; WR=1; // CS=1; A0=1; }
void CH375_Write_Dat(unsigned char dat) //寫數(shù)據(jù) { // CS=0; A0=0; P2=dat; WR=0; WR=1; // CS=1; A0=1; }
unsigned char CH375_Wait_Int() //等待中斷信號(hào),即int引腳 { INT=1; while(INT); CH375_Write_Cmd(CMD_GET_STATUS); //產(chǎn)生操作完成中斷獲取 return CH375_Read_Dat(); }
unsigned char CH375_WriteSector(unsigned long addr,unsigned char *pBuf) { unsigned char i=0,j; unsigned char status; CH375_Write_Cmd(CMD_DISK_WRITE); //磁盤寫入命令 CH375_Write_Dat((unsigned char)addr); CH375_Write_Dat((unsigned char)(addr>>8)); CH375_Write_Dat((unsigned char)(addr>>16)); CH375_Write_Dat((unsigned char)(addr>>24)); //送入32位扇區(qū)地址,先送低字節(jié) CH375_Write_Dat(1); //送入扇區(qū)數(shù) for(i=0;i<8;i++) { status=CH375_Wait_Int(); if(status==USB_INT_DISK_WRITE) { CH375_Write_Cmd(CMD_WR_USB_DATA7); CH375_Write_Dat(64); for(j=0;j<64;j++) { CH375_Write_Dat(*pBuf); pBuf++; } CH375_Write_Cmd(CMD_DISK_WR_GO); } else { printf("xierushujufashengcuowu\n"); printf("%d\n",(int)status); return status; } } if(status==USB_INT_SUCCESS) //如果狀態(tài)碼為USB_INT_SUCCESS { printf("xieshanquchenggong\n"); return 0; } else { printf("xieshanqushibai\n"); //發(fā)生錯(cuò)誤,返回狀態(tài)碼 return status; } }