View previous topic :: View next topic |
Author |
Message |
CMatic
Joined: 11 Jan 2012 Posts: 69
|
Reading data from a file |
Posted: Wed Jan 11, 2012 10:00 pm |
|
|
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
|
|
Posted: Wed Jan 11, 2012 10:50 pm |
|
|
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
|
|
Posted: Wed Jan 11, 2012 11:18 pm |
|
|
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
|
|
Posted: Wed Jan 11, 2012 11:36 pm |
|
|
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
|
|
Posted: Thu Jan 12, 2012 12:12 am |
|
|
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
|
|
Posted: Thu Jan 12, 2012 12:49 am |
|
|
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
|
|
Posted: Thu Jan 12, 2012 10:36 pm |
|
|
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. |
|
|
|