DEMOREAD - Open a Text
File and Read Data From It
Okay, so we were able to write using the
Experimenter and read using the PC, but let’s
double-check that the Experimenter can read the
file it created. Download and unzip READDEMO
from the website. Open the folder and double-click
on MDDFS_SD_PIC24.mcp. Again, the LCD library
is used to display the status. Let’s remove the SD
card from the PC and put it back in the
Experimenter SD carrier board. Note the use of the
SetClockVars () in the beginning of the code. Steps
1 and 2 are identical to the earlier write code. In
Step 3, we open the file for reading using FSfopen
(), using the FILE1. TXT file name, and an “r” or read
attribute. In Step 4, we do the actual reading with
FSfread (). The entire content from the file is read
one byte at a time and loaded into a receiveBuffer.
We then close the file in Step 5. In Step 6, the LCD
display is used to show the entire contents in
receiveBuffer. You can exam the LCD for a
complete string readout for “This a file I/O test
using Microchip library.”
DEMOREADWRITE - A
Larger Example Using Two
Files, File Pointers, RTCC,
LCD, and Serial I/O
This demo creates two files (one at a time) and
uses the RTCC to set the date/time of file usage. In
addition, both the UART and LCD libraries are used.
The UART is totally optional but does require an
Acroname adapter (covered in NV June ‘ 10 issue)
and setting Hyper Terminal to 9600 8N1 (see the
hook-up diagram shown earlier) to display the
contents on your PC. Download and unzip
READWRITEDEMO from the website. Open the
folder and double-click on MDDFS_SD_PIC24.mcp.
This demo first writes a “This is Experimenter
String1” to FILE1. TXT; it then copies this to
FILE2. TXT and rewrites the last character in
FILE1. TXT to a 2. The results are shown in Figure
14. All steps are displayed on the Experimenter LCD
simultaneously as they’re being written to
HyperTerminal.
Future Expansion
We’ve now added a pretty substantial
capability to our Experimenter. Data logging and
data sharing have reached new heights —- we now
have GB storage and retrieval capability in a
microcontroller environment and the ability to use
Windows-based tools seamlessly with the data.
Think of the applications! NV
■ FIGURE 12. Read and write demo with serial port
interface shown.
■ FIGURE 13. HyperTerminal output.
October 2010 51
■ FIGURE 14. Disk contents.