各位前輩們好,小弟在使用CH376的時候遇到了一個問題就是使用單芯片發(fā)指令建立一個TEST.TXT的文本文件,然后針對這個文本文件進行寫入的動作寫入動作都不成功,可是如果是在計算機上建立一個TEST.TXT檔案在使用單芯片執(zhí)行OPEN File然后針對這個TEST.TXT的文本文件做寫入的話寫入數(shù)據(jù)就會成功,目前看到的差異是使用單芯片建立TEST.TXT的時候文本文件里面會多出一個"1"的字符,請問建立檔案的時候怎樣才不會產(chǎn)生字符或者是說怎么使用覆蓋的方式來處理這個問題呢?還是說還有其他解決方法呢?請前輩們指教,感謝!
以下昰我的程式碼 while(1) { PORTB = 0X00; Delay5ms(20);
//Test communication interface and work status while(CHECK_EXIST() != 0x00) Delay5ms(1); PORTBbits.RB0 = 1; UART1_RX_Value_Buffer = 0; //Setting the USB mode while(SET_USB_MODE()!= 0x51) Delay5ms(1); PORTBbits.RB1 = 1; UART1_RX_Value_Buffer = 0; //Initialize the disk and test disk ready while(DISK_MOUNT()!=0x14) Delay5ms(1); PORTBbits.RB2 = 1; UART1_RX_Value_Buffer = 0; //Set to operate on the file name Delay5ms(1); SET_FILE_NAME(); PORTBbits.RB3 = 1; UART1_RX_Value_Buffer = 0; //Open the file or directory, enumerate files and directories while(FILE_OPEN()!=0x14) Delay5ms(1); PORTBbits.RB4 = 1; UART1_RX_Value_Buffer = 0; //while(BYTE_LOCATE()!=0x14)
BYTE_LOCATE(); Delay5ms(100); UART1_RX_Value_Buffer = 0; //Create documents // while(FILE_CREATE()!=0x14) // Delay5ms(1); // PORTBbits.RB4 = 1; // UART1_RX_Value_Buffer = 0; //===============================================================
//In bytes of the write data block to the current location //while(BYTE_WRITE()!=0x1E) BYTE_WRITE(); Delay5ms(1); PORTBbits.RB5 = 1; UART1_RX_Value_Buffer = 0; //Specified buffer to the internal write request data blocks Delay5ms(1); WR_REQ_DATA(); PORTBbits.RB6 = 1; UART1_RX_Value_Buffer = 0; //Continue byte write while(BYTE_WR_GO()!=0x14) //BYTE_WR_GO(); Delay5ms(1); BYTE_WR_GO(); PORTBbits.RB7 = 1; UART1_RX_Value_Buffer = 0; //Closes the currently open file or directory while(FILE_CLOSE()!=0x14) Delay5ms(1); PORTBbits.RB8 = 1; UART1_RX_Value_Buffer = 0;
Delay5ms(200);
//================================================================== //Test communication interface and work status unsigned char CHECK_EXIST() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x06); UART1_Send_Value(0xFF); return UART1_RX_Value_Buffer; } ////Setting the USB mode unsigned char SET_USB_MODE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x15); UART1_Send_Value(0x03); return UART1_RX_Value_Buffer; } //Initialize the disk and test disk ready unsigned char DISK_MOUNT() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x31); return UART1_RX_Value_Buffer; } //Set to operate on the file name unsigned char SET_FILE_NAME() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2F); char data[] = "TEST.TXT"; UART1_Send_String(data);
//TEST.TXT //UART1_Send_Value(0x54); //UART1_Send_Value(0x45); //UART1_Send_Value(0x53); //UART1_Send_Value(0x54); //UART1_Send_Value(0x2E); //UART1_Send_Value(0x54); //UART1_Send_Value(0x58); //UART1_Send_Value(0x54); return UART1_RX_Value_Buffer; } //Create documents unsigned char FILE_CREATE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x34); return UART1_RX_Value_Buffer; }
unsigned char BYTE_WRITE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3C); UART1_Send_Value(0x0A); UART1_Send_Value(0x0A>>8); return UART1_RX_Value_Buffer; }
unsigned char BYTE_READ() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3A); return UART1_RX_Value_Buffer; } unsigned char WR_REQ_DATA() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2D);
UART1_Send_Value(0x31); UART1_Send_Value(0x32); UART1_Send_Value(0x31); UART1_Send_Value(0x32); UART1_Send_Value(0x41); UART1_Send_Value(0x0D); // \r UART1_Send_Value(0x0A); // \n UART1_Send_Value(0x45); UART1_Send_Value(0x47); UART1_Send_Value(0x48); return UART1_RX_Value_Buffer; }
unsigned char BYTE_WR_GO() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3D); return UART1_RX_Value_Buffer; }
unsigned char FILE_CLOSE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x36); UART1_Send_Value(0x01); return UART1_RX_Value_Buffer; }
unsigned char FILE_OPEN() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x32); return UART1_RX_Value_Buffer; }
unsigned char WR_OFS_DATA() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2E); UART1_Send_Value(0x00); UART1_Send_Value(0x05);
UART1_Send_Value(0x42); UART1_Send_Value(0x42); UART1_Send_Value(0x42); UART1_Send_Value(0x46); UART1_Send_Value(0x46); return UART1_RX_Value_Buffer; }
unsigned char BYTE_LOCATE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x39);
UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); }