CCS C FAT example – ex_fat – with PIC18F4550

The CCS C compiler has a good example of using PIC microcontroller with SD card in FAT file format, this file is located in the examples folder (C:\Program Files\CCS\Examples), its full name is ex_fat.c (fat_ex_shell.c ). This topic shows how this example works, circuit diagram and Proteus ISIS simulation.

As written in the head of the file ex_fat.c:
This is a neat little shell utility that resembles a DOS or UNIX type shell in order to manipulate files on the FAT file system. This is mostly for demonstration purposes on how to use some of the basic functionality of the FAT library.

In this project I’m going to use MMC/SD card and FAT library provided in the page below, without the two files we’ll not be able to compile project source file (C code), the name of the two files (with the extension) respectively are: mmcsd_m.c and fat_m.c. After downloading just add the two files to the project folder or CCS C drivers folder:
SD Card driver and FAT Library for CCS C compiler

Related Project:
The following project may have some help!
Read and write files from and to SD card with PIC18F4550 – CCS C

Hardware Required:

  • PIC18F4550 microcontroller   —> datasheet
  • FAT32 formatted SD card (MMC, SD, SDHC, micro SD ….)
  • microSD card module
  • USB-to-serial UART module (FT232RL, Arduino UNO ….)
  • 8MHz crystal oscillator
  • 2 x 22pF ceramic capacitors
  • Breadboard
  • 5V source
  • Jumper wires
  • PIC MCU programmer (PICkit 3, PICkit 4 …)

The Circuit:
Example circuit schematic is shown below.

CCS C ex_fat example circuit with PIC18F4550

All grounded terminals are connected.

In this project the microcontroller runs with an external crystal oscillator of 8MHz and MCLR pin is configured as a digital input pin (in the software).

The microSD card is placed in the module (adapter).

The USB-to-serial UART module such as FT232RL is used to connect the microcontroller with the laptop (PC), in order to send and receive data between the microcontroller and the serial software (CCS IDE serial monitor, Arduino IDE serial monitor, hyper terminal …).

As a hint, instead of the microSD card module we can use AMS1117-3V3 to supply the SD card and three voltage dividers for SS (CS), SCK and MOSI lines; each voltage divider consists of two resistors: 2.2k ohm and 3.3k ohm. MISO line is directly connected between the MCU and the SD card. Related project link above shows a similar circuit diagram.

CCS C code:
The following C code was tested with version 5.051, it gives some warnings which can be ignored.
I made some modifications to the original to work with the PIC18F4550 microcontroller and the circuit diagram shown above.

With the 8MHz crystal oscillator and by enabling PLL2 the microcontroller speed becomes 48MHz which is the highest speed of the PIC18F4550 microcontroller.

As a reminder, to be able to compile the C code below without errors, add the files mmcsd_m.c and fat_m.c to project folder, their download links are in the page below:
SD Card driver and FAT Library for CCS C compiler

Rest of code is described through comments.

The video below shows the simulation of the ex_fat example using Proteus ISIS simulation software, the real hardware circuit also gave me the same result. Note that the simulation circuit connections are not the same as the real hardware circuit connection, real hardware circuit schematic diagram is shown above.
To open the SD card image file use an image software such as UltraISO, WinImage ….

Reference:
CCS C compiler example ex_fat.c

SD Card file is FAT32 image file, it can be downloaded from the link below:
SD Card FAT32 image

Proteus simulation file download link:
EX_FAT with PIC18F4550


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

2 thoughts on “CCS C FAT example – ex_fat – with PIC18F4550”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top