EmbeddedRelated.com
Forums

library stdio.h of CCS C Compiler

Started by Paolo April 29, 2004
Hi everybody,

I use the CCS C Compiler to program the behavior of a robot (controled by a
PIC 16F877) and I want to write some data from the PIC to a file via port
serial RS232. But the problem is that "stdio.h" library of the compiler
contains only 'getc', 'putc' but no file handling functions like 'fopen',
'fputc', fgetc', etc...

Is there some solution i can use to perform "file handling" with this
compiler ?

Thank you very much !

Paolo.



Paolo <doute@altern.org> wrote:

> Is there some solution i can use to perform "file handling" with this > compiler ?
What makes you believe you need "file handling" to write to the serial port? Did you even start to RTFM before posting? -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
"Hans-Bernhard Broeker" <broeker@physik.rwth-aachen.de> a &#4294967295;crit dans le
message de news:c6s0db$fk1fp$2@ID-231750.news.uni-berlin.de...
> Paolo <doute@altern.org> wrote: > > > Is there some solution i can use to perform "file handling" with this > > compiler ? > > What makes you believe you need "file handling" to write to the serial > port?
Thanks you for answering but nothing makes me believe that. What I want is write some data from the robot to a file, like for example : #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7); [...] while(TRUE) { if (kbhit()) { File *fp; fp = fopen("abc.txt", "w+"); char CharReceived; CharReceived=getc(); switch (CharReceived) { case 'p': fputc("Hello World", fp);} but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ? Thank you, Paolo.
Paolo <doute@altern.org> wrote:

> but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ?
Usually because the class of target system the compiler is designed for doesn't have anything remotely like a disk or other kind of mass storage device that would warrant putting a file system onto it. Where would you expect that "abc.txt" to end up on a remotely typical PIC-based embedded system? -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
Paolo said...
> "Hans-Bernhard Broeker" <broeker@physik.rwth-aachen.de> a =E9crit dans le > > Paolo <doute@altern.org> wrote: > > > > > Is there some solution i can use to perform "file handling" with this > > > compiler ? > > > > What makes you believe you need "file handling" to write to the serial > > port? >=20 > Thanks you for answering but nothing makes me believe that. What I want i=
s
> write some data from the robot to a file, like for example :
Nothing may make you believe that, but sooner or later you're going to=20 have to face the fact that there's no way to use "file handling" with=20 this compiler for this processor to write to the serial port. You=20 can't find it because it's not there. =20
> #use rs232(baud=3D9600,parity=3DN,xmit=3DPIN_C6,rcv=3DPIN_C7); > [...] > while(TRUE) { > if (kbhit()) { > File *fp; > fp =3D fopen("abc.txt", "w+"); > char CharReceived; > CharReceived=3Dgetc(); > switch (CharReceived) { > case 'p': fputc("Hello World", fp);} >=20 > but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ?
Because it's supposed to run on a PIC? Why would you expect to see=20 them and what's the point of trying to use a file? This is a small processor with a small amount of memory. You need to=20 forget the file idea and think more along the lines of sending=20 characters and receiving characters over the RS232. Casey
"Paolo" <doute@altern.org> wrote in message
news:c6rs36$fo0cq$1@ID-101169.news.uni-berlin.de...
> Hi everybody, > > I use the CCS C Compiler to program the behavior of a robot (controled by
a
> PIC 16F877) and I want to write some data from the PIC to a file via port > serial RS232. But the problem is that "stdio.h" library of the compiler > contains only 'getc', 'putc' but no file handling functions like 'fopen', > 'fputc', fgetc', etc... > > Is there some solution i can use to perform "file handling" with this > compiler ? > > Thank you very much ! > > Paolo. > >
This file would be on a PC I take it? If so then you need a different compilier on the PC side (like Boreland or Microsofts) and it needs to receive the serial information from the PIC and store it in the file there. A PIC can't just write to a file on a PC . Unless you actually have a drive connected to this pic somehow, but that doesn't make sense, since you are talking about RS-232. (however there are serial to CF drives out there, but they don't use a file system that I have seen). Tony
"Casey" <cclremovethispart@cox.net> a &#4294967295;crit dans le message de
news:cRskc.3530$Lm3.263@lakeread04...
Paolo said...
> > [...]. > > > > #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7); > > [...] > > while(TRUE) { > > if (kbhit()) { > > File *fp; > > fp = fopen("abc.txt", "w+"); > > char CharReceived; > > CharReceived=getc(); > > switch (CharReceived) { > > case 'p': fputc("Hello World", fp);} > > > > but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ? > > Because it's supposed to run on a PIC? Why would you expect to see > them and what's the point of trying to use a file?
Thank you for taking time to answer me. Actually I program a genetic algorithm for a population of robots, and I want to store some data like genome and fitness into a file. This way, I can use these files to make the mutation/recombination/selection process with a PC and then re-use them to program the robots with the new genome parameter. But as Anthony Marchini (thanks to him) pointed out, I guess the only solution I have is to use a different compiler on the PC side which will receive the serial information from the PIC and will store it in the file there. Paolo.
Paolo said...
> Casey said > > Paolo said > > > > > > but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ? > > > > Because it's supposed to run on a PIC? Why would you expect to see > > them and what's the point of trying to use a file? > > Thank you for taking time to answer me. Actually I program a genetic > algorithm for a population of robots, and I want to store some data like > genome and fitness into a file. This way, I can use these files to make the > mutation/recombination/selection process with a PC and then re-use them to > program the robots with the new genome parameter. > But as Anthony Marchini (thanks to him) pointed out, I guess the only > solution I have is to use a different compiler on the PC side which will > receive the serial information from the PIC and will store it in the file > there.
Quicker solution is to transmit serial characters from the PIC as data is collected and run an off-the-shelf terminal emulator (even Hyperterminal) on the PC that does nothing but capture the incoming data stream and store it in a log file. Casey
"Casey" <cclremovethispart@cox.net> wrote in message
news:Nhwkc.3550$Lm3.2562@lakeread04...
> Paolo said... > > Casey said > > > Paolo said > > > > > > > > but 'fopen()' and 'FILE' aren't defined in the 'stdio.h'. Why ? > > > > > > Because it's supposed to run on a PIC? Why would you expect to see > > > them and what's the point of trying to use a file? > > > > Thank you for taking time to answer me. Actually I program a genetic > > algorithm for a population of robots, and I want to store some data like > > genome and fitness into a file. This way, I can use these files to make
the
> > mutation/recombination/selection process with a PC and then re-use them
to
> > program the robots with the new genome parameter. > > But as Anthony Marchini (thanks to him) pointed out, I guess the only > > solution I have is to use a different compiler on the PC side which will > > receive the serial information from the PIC and will store it in the
file
> > there. > > Quicker solution is to transmit serial characters from the PIC as data > is collected and run an off-the-shelf terminal emulator (even > Hyperterminal) on the PC that does nothing but capture the incoming > data stream and store it in a log file. > > > Casey
I was making the assumption that the information would be in a binary non human readable format that may require direct processing for error recovery. But if the data is ASCII then that will work fine. Tony