elements that they want to use in
their application. An excellent
resource is the Microchip
Application Note AN1045
“Implementing File I/O Functions
Using Microchip’s Memory” that is
available on their website at
www.microchip.com. We adopted
this library for the Experimenter,
and the applicable API (Application
Programming Interface) calls shown
• FSInit — Initializes card and
• FSfClose — Updates file info and
• FSfeof — Verifies if the end of the
file has been reached (used in
• FSfopen — Opens existing file or
creates new one.
• FSfread — Reads opened file.
• FSfseek — Changes the file pointer position in file.
• FSftell — Returns current pointer position in file.
• FSfwrite — Writes information to file.
■ FIGURE 6. Library Hardwareprofile.h.
There are two other functions we need to consider:
• MDD_MediaDetect — Determines if SD card is in
• SetClockVars — This API sets the timing variables
manually that are used to set the file
create/modify/access times. This function is used only if
we elect not to use the internal Real Time Clock
Calendar (RTCC) peripheral to set time.
this example can help you understand what is involved in
adopting these libraries for your own use. Keep in mind
that all our demos are preconfigured and can be used
“out of the box” as a template for your applications.
The library options are configured in FSconfig.h by
selecting which macros you want to enable. For the
Experimenter, the following is enabled:
Let’s go through a couple of examples. There are a
total of three demos: simple file write WRITEDEMO;
simple file read READDEMO; and a larger example that
uses two files (READWRITEDEMO), the RTCC peripheral,
UART, and LCD, as well.
The hardware interface for the library is configured in
two places. The first place is Hardwareprofile.h. The other
place is in Main (). Here, we map SPI2 using PPS (described
earlier) to the appropriate Experimenter I/O pins. Note that
Microchip File I/O
Library for the
Before we proceed, let’s
exam how the library was
configured to run on the
Experimenter. This section let’s us
look “under the hood” so to
speak. Microchip offers lots of
free libraries and working through
■ FIGURE 7. Library reference and
hardware configuration in Main.
October 2010 49