CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Reading data from a file

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

Reading data from a file
PostPosted: Wed Jan 11, 2012 10:00 pm     Reply with quote

I want to write a program in which RGB LEDs will be cycled based upon some predefined patterns. Those patterns will be saved in the pattern.h file.
How can I make my program read the pattern file and then read each line of the file ?

Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 10:50 pm     Reply with quote

Are you proposing that the compiler should read an MSDOS text file at
compile-time ? Or do you mean the PIC should read the file at run-time ?
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:18 pm     Reply with quote

PCM programmer wrote:
Are you proposing that the compiler should read an MSDOS text file at
compile-time ? Or do you mean the PIC should read the file at run-time ?


No not the DOS text file. I want to read specific lighting patterns which will be linked with #include <pattern.h> file in the Main.c program. But I am now sure how to code the pattern.h file so the main.c program will be able to read each line from the pattern.h file and then process these values.

The pattern.h file will have many many patterns. And currently I am thinking to terminate the file with a value of 255 to tell the main.c to stop reading the file. Hope this is a bit more clearer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:36 pm     Reply with quote

Since it's an #include file, why not just put the data into an 'const' array ?
Then the compiler can compile it and include in the program.

If your pattern file is in a raw form, the WinHex program can convert a
binary data file into an array. In the version I have, you go to the menu
Edit / Copy All / C Source. Then it creates the array and puts it into the
Windows Clipboard. From there you can copy it into your pattern.h file
and add the 'const' qualifier.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 12:12 am     Reply with quote

PCM programmer wrote:
Since it's an #include file, why not just put the data into an 'const' array ?
Then the compiler can compile it and include in the program.

If your pattern file is in a raw form, the WinHex program can convert a
binary data file into an array. In the version I have, you go to the menu
Edit / Copy All / C Source. Then it creates the array and puts it into the
Windows Clipboard. From there you can copy it into your pattern.h file
and add the 'const' qualifier.


Thanks very much. Can you give me an example of the array with the 'const' qualifier? The reason I want to include it as a pattern.h file is that I will be able to change just the include file to change the patterns. Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 12:49 am     Reply with quote

These CCS files (included with the compiler) have examples of one-
dimensional arrays in ROM (const arrays):
Quote:

c:\program files\picc\examples\ex_dtmf.c
c:\program files\picc\examples\ex_sine.c
c:\program files\picc\examples\ex_patg.c
c:\program files\picc\drivers\tones.c


This one has an example of a 2-dimensional const array, if you need it:
Quote:

c:\program files\picc\drivers\glcd.c
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 10:36 pm     Reply with quote

PCM programmer wrote:
These CCS files (included with the compiler) have examples of one-
dimensional arrays in ROM (const arrays):
Quote:

c:\program files\picc\examples\ex_dtmf.c
c:\program files\picc\examples\ex_sine.c
c:\program files\picc\examples\ex_patg.c
c:\program files\picc\drivers\tones.c


This one has an example of a 2-dimensional const array, if you need it:
Quote:

c:\program files\picc\drivers\glcd.c


These examples are just what I needed. Thank you so much for your help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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