Bonjour,
Je créé un fichier log.csv sur une carte SD à l'aide d'un pic18f46J50, et plus précisement du matériel EXPLORER 18 + Pic Dem 18F46J50 PIM + Pic Tail Board SD/MMC Card.
Le fichier est bien créé et lisible. Je voudrais écrire du texte dans les 4 premiere cases de la ligne 1, pour avoir un nom de colonne, et ensuite y mettre des valeurs. Je n'est pas de probleme pour ecrire les valeurs.
Mais la chaine de texte quqi correspond à mon nom de colonne fonctionne pour les deux premieres cases, mais pas dans les deux dernieres, alors que j'utilise les meme fonctions.
J'utilise MCC18 Pro et Mplab v8.63.
Voici ce que je ressort du csv :
_____A____|_____B_____|___C___ |_____D___________|_
1|..1ainG_C1....2ainG_C2...... .......3...........4ainD_C4ain DainD
Voila ce que j'ai quand je regarde en txt:
1ainG_C1;2ainG_C2;3;4ainD_C4ai nDainD
Les 4 noms de colonnes que j'utilise sont :
"1ainG_C1"
"2ainG_C2"
"3ainD_C1"
"4ainD_C2"
Vous pouvez les retrouver dans le code. On constate que les deux premières colonnes ont bien leurs nom, mais les colonnes 3 et 4, c'est du n'importe quoi....
Si vous avez une idée, elle est la bienvenue.
Merci de votre aide.
Le programme:
Code:#include <p18F46J50.h> #include <stdio.h> #include "HardwareProfile.h" #include "MDD File System/SD-SPI.h" #include "MDD File System/FSIO.h" #include <delays.h> #pragma config WDTEN = OFF //WDT disabled (enabled by SWDTEN bit) #pragma config PLLDIV = 3 //Divide by 3 (12 MHz oscillator input) #pragma config STVREN = ON //stack overflow/underflow reset enabled #pragma config XINST = OFF //Extended instruction set disabled #pragma config CPUDIV = OSC1 //No CPU system clock divide #pragma config CP0 = OFF //Program memory is not code-protected #pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB #pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled #pragma config IESO = OFF //Two-Speed Start-up disabled #pragma config WDTPS = 32768 //1:32768 #pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock #pragma config RTCOSC = T1OSCREF //RTCC uses T1OSC/T1CKI as clock #pragma config DSBOREN = OFF //Zero-Power BOR disabled in Deep Sleep #pragma config DSWDTEN = OFF //Disabled #pragma config DSWDTPS = 8192 //1:8,192 (8.5 seconds) #pragma config IOL1WAY = OFF //IOLOCK bit can be set and cleared #pragma config MSSP7B_EN = MSK7 //7 Bit address masking #pragma config WPFP = PAGE_1 //Write Protect Program Flash Page 0 #pragma config WPEND = PAGE_0 //Start protection at page 0 #pragma config WPCFG = OFF //Write/Erase last page protect Disabled #pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored #pragma config T1DIG = ON //Sec Osc clock source may be selected #pragma config LPT1OSC = OFF //high power Timer1 mode /** PRIVATE PROTOTYPES *********************************************/ static void InitializeSystem(void); //WORD_VAL ReadPOT(void); int can(void); void main(void) { unsigned int* data; unsigned int i; FSFILE *logFile; BOOL initResults; WORD_VAL ADCResult; WORD_VAL MainG_C1; WORD_VAL MainG_C2; WORD_VAL MainD_C1; WORD_VAL MainD_C2; char NomCol1 [9] = {'1','a','i','n','G','_','C','1',';'}; char NomCol2 [9] = {'2','a','i','n','G','_','C','2',';'}; char NomCol3 [9] = {'3','a','i','n','D','_','C','3',';'}; char NomCol4 [9] = {'4','a','i','n','D','_','C','4',';'}; int ResultCAN; BYTE printColon[9]; BYTE printData[6]; //set the data pointer for the FSfwrite function data = &i; //Initialisation du systeme (E/S) InitializeSystem(); //Initialisation du systeme de fichier initResults = FSInit(); //initialize the A/D mInitPOT(); //Set up the LED as output mInitAllLEDs(); //Set the push button input mInitSwitch2(); //The log file is not open so let's make sure the pointer is NULLed out logFile = NULL; while(1) { if(initResults == TRUE) { if(sw2 == 0) { if(logFile != NULL) { // Get an ADC sample //ADCResult = ReadPOT(); ResultCAN = can(); //sprintf((char*)&printData[0],"%d; ",ADCResult.Val); // sprintf((char*)&printData[0],"%d; ", ResultCAN); // FSfwrite((const void*)&printData[0],1,sizeof(printData),logFile); // // sprintf((char*)&printData[0],"%d; ", ResultCAN); // FSfwrite((const void*)&printData[0],1,sizeof(printData),logFile); // // sprintf((char*)&printData[0],"%d; ", ResultCAN); // FSfwrite((const vo"id*)&printData[0],1,sizeof(printData),logFile); // // sprintf((char*)&printData[0],"%d \r\n", ResultCAN); // FSfwrite((const void*)&printData[0],1,sizeof(printData),logFile); mLED_1_On(); mLED_2_Off(); } else { logFile = FSfopenpgm("log_test.csv",WRITE); //Ecriture du nom colonnes sprintf((char*)&printColon[0],"%s", NomCol1); FSfwrite((const void*)&printColon[0],1,sizeof(printColon),logFile); //Ecriture du nom colonnes sprintf((char*)&printColon[0],"%s", NomCol2); FSfwrite((const void*)&printColon[0],1,sizeof(printColon),logFile); //Ecriture du nom colonnes sprintf((char*)&printColon[0],"%s", NomCol3); FSfwrite((const void*)&printColon[0],1,sizeof(printColon),logFile); //Ecriture du nom colonnes sprintf((char*)&printColon[0],"%s", NomCol4); FSfwrite((const void*)&printColon[0],1,sizeof(printColon),logFile); mLED_2_On(); mLED_1_On(); } } else { if(logFile != NULL) { FSfclose(logFile); logFile = NULL; mLED_1_Off(); mLED_2_On(); } } } else { if(MDD_SDSPI_MediaDetect() == TRUE) { initResults = FSInit(); } } }//end while } //end main static void InitializeSystem(void) { ADCON1 |= 0x0F; // Default all pins to digital //Configure all I/O pins to use digital input buffers. The PIC18F87J50 Family devices //use the ANCONx registers to control this, which is different from other devices which //use the ADCON1 register for this purpose. ANCON0 = 0xFF; // Default all pins to digital ANCON1 = 0xFF; // Default all pins to digital //On the PIC18F87J50 Family of USB microcontrollers, the PLL will not power up and be enabled //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). //This allows the device to power up at a lower initial operating frequency, which can be //advantageous when powered from a source which is not gauranteed to be adequate for 48MHz //operation. On these devices, user firmware needs to manually set the OSCTUNE<PLLEN> bit to //power up the PLL. { unsigned int pll_startup_counter = 600; OSCTUNEbits.PLLEN = 1; //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module while(pll_startup_counter--); } //Device switches over automatically to PLL output after PLL is locked and ready. //********* Initialize Peripheral Pin Select (PPS) ************************* // This section only pertains to devices that have the PPS capabilities. // When migrating code into an application, please verify that the PPS // setting is correct for the port pins that are used in the application. //Initialize the SPI //RPINR21bits.SDI2R = 1; //RPOR4bits.RP4R = 10; //RP4 = SCK //RPOR2bits.RP2R = 9; //RP2 = SDO RPINR21 = 1; //SDI = RP1 RPOR4 = 10; //RP4 = SCK RPOR2 = 9; //RP2 = SDO RPINR22 = 4; //SCK = RP4 //enable a pull-up for the card detect, just in case the SD-Card isn't attached // then lets have a pull-up to make sure we don't think it is there. INTCON2bits.RBPU = 0; } /******Conversion Analogique Numérique*******/ int can() // Sous programme CAN { int ResultConv; ResultConv = 0; ADCON0bits.GO = 1; // Lancement de CAN while(ADCON0bits.NOT_DONE); // Attente fin CAN //ResultConv = ((ADRESH <<8) + ADRESL); // Lecture résultat sur 16 bits (10 utiles) ResultConv = ADRESH; ResultConv <<=8; ResultConv = ResultConv + ADRESL; return ResultConv ; /******Fin Conversion Analogique Numérique*******/ }
-----