Hello all! I am trying to include a text file (about 10kB) into a project. I want this file to be as is in the MSP flash and read it out when needed. It contains a lot of special characters that I would need to escape when including as a string. Is there a way to include the file into the project as is? I tried to add it to the project and of course it produced a lot of errors as the compiler hasn't been told how to handle it. Has anyone tried this before? How do I have to go about it? How do I do this with binary files? Thanks a lot!! -Jean-
How to include data file (text) into C code in Crossworks
Started by ●September 28, 2004
Reply by ●September 28, 20042004-09-28
Jean, You can use an assembler insert to include the file directly; INCLUDEBIN is the directive. For instance: filecontents.asm: .const _filecontentsstart:: INCLUDEBIN "myliteralfile.txt" _filecontentsend:: ...this includes the contents of myliteralfile.txt into the assembly module as binary data directly, and the two symbols define the extent of this in the CONST section. We'd use it in C like this: usefile.c: extern unsigned char filecontentsstart[], filecontentsend[]; void peek_contents(void) { unsigned char *filecontents = filecontentsstart; size_t len = filecontentsend - filecontentsstart; // Now we have the start of the file (as a binary image) and its length. } Hopefully this will aid you on your way. -- Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors > -----Original Message----- > From: jean_randhah [mailto:jean@jean...] > Sent: 28 September 2004 12:08 > To: msp430@msp4... > Subject: [msp430] How to include data file (text) into C code > in Crossworks > > Hello all! > > I am trying to include a text file (about 10kB) into a > project. I want this file to be as is in the MSP flash and > read it out when needed. It contains a lot of special > characters that I would need to escape when including as a string. > > Is there a way to include the file into the project as is? I > tried to add it to the project and of course it produced a > lot of errors as the compiler hasn't been told how to handle > it. Has anyone tried this before? How do I have to go about it? > How do I do this with binary files? > > Thanks a lot!! > > -Jean- > > > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > $9.95 domain names from Yahoo!. Register anything. > http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/CFFolB/TM > -------------------------- > ------~-> > > . > > > Yahoo! Groups Links > > > > > > >
Reply by ●September 28, 20042004-09-28
> Hopefully this will aid you on your way. Thanks a lot, Paul! Unfortunatly I am not that much into assembler to find these things myself right away. BTW, I am compiling a small FAQ on things like this on http://msp430. info. I know that a full FAQ is quite impossible for such a broad spectrum, but I hope this helps others with some very common questions. If anyone is really interested, they can obtain a login to submit/edit FAQ entries. Just write me a mail. -Jean-