|
|
View previous topic :: View next topic |
Author |
Message |
tepes
Joined: 25 Jan 2012 Posts: 18
|
fprintf to a text file |
Posted: Mon Jun 04, 2012 7:15 am |
|
|
can anyone give me an example of how to to print the data from the PIC in to a text file? something like bellow...
Code: | FILE * pFile;
.....
pFile = fopen ("myfile.txt","w");
for (n=0 ; n<100 ; n++)
{
fprintf (pFile, "%d ",n);
}
fclose (pFile);
...... |
Thank you very much! |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Jun 04, 2012 9:45 am |
|
|
Hi...
where would such file be?
SD card?
on a host PC?
Programing on a PIC is not like programing C++ on a PC where you just print to file.
the easiest way is get an "Open Log" set you back ~25 bucks... does all you want. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Mon Jun 04, 2012 9:49 am |
|
|
or buy an FTDI Vinculum based USB flash drive module for same money +-
SUPER easy to create files,save data,etc. and 100% PC compatible ! |
|
|
tepes
Joined: 25 Jan 2012 Posts: 18
|
|
Posted: Tue Jun 05, 2012 1:10 am |
|
|
I needed the .txt file to be on a computer and to fprint in to it by using RS232! But instead I print the data to hyper terminal now, and then I copy the data to a .txt file and then I use a C++ program to create a new file where the data is formated the way I need! It takes a litle more time but I obtain what I need! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Jun 05, 2012 1:45 am |
|
|
First, forget fprintf. This is designed for talking to a serial stream in the PIC, or a open file on the PC, and isn't the tool needed here.
On the PIC, with CCS, 'printf', is a generic output tool, able to route it's output to _any_ output routine using the syntax:
printf(routine_to_use,"what you want to send");
If you have a file open on an SD card, using the fat.h library, this offers 'fatputc', allowing you to write a character to this file. So you can use this as the output routine for printf, and write the text to the file. Obviously open first, flush & close when finished.
This then puts the data (text or binary), sequentially into the selected file.
Best Wishes |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Jun 05, 2012 8:09 am |
|
|
.... you can set hyperterminal to receive/capture a text file.
so basically what ever you see printed in hyperterminal is saved to a TXT file...
its a standard feature of Hyperterminal.
You can set your PIC to output your data in the format you want.
I did this for a data logger i was building a while back.
Each line the pic printed was
Code: | ADCvalue1, Year, Month, Day, Hour, Min \n\r
ADCvalue2, Year, Month, Day, Hour, Min \n\r
ADCvalue3, Year, Month, Day, Hour, Min \n\r
....
ADCvalueN, Year, Month, Day, Hour, Min \n\r |
and then i could easily import data to Excel as it was a comma delimited text file. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
tepes
Joined: 25 Jan 2012 Posts: 18
|
|
Posted: Wed Jun 06, 2012 3:40 am |
|
|
Thank you all for your help! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|