各位前辈们好,小弟在使用CH376的时候遇到了一个问题就是使用单芯片发指令建立一个TEST.TXT的文本文件,然后针对这个文本文件进行写入的动作写入动作都不成功,可是如果是在计算机上建立一个TEST.TXT档案在使用单芯片执行OPEN File然后针对这个TEST.TXT的文本文件做写入的话写入数据就会成功,目前看到的差异是使用单芯片建立TEST.TXT的时候文本文件里面会多出一个"1"的字符,请问建立档案的时候怎样才不会产生字符或者是说怎么使用覆盖的方式来处理这个问题呢?还是说还有其他解决方法呢?请前辈们指教,感谢!
以下昰我的程式碼 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); }