Pages

Tuesday, August 22, 2017

FAT16 Library for CCS C compiler

This is a FAT16 file system library for CCS PIC C compiler which can be used with any PIC microcontroller that has enough RAM and ROM spaces. Although, the CCS C compiler has a good FAT16/32 library but it requires large amount of RAM, so this is an other library not the one which comes from the compiler. This library is for READING files only, creating folders, files or editing text files are not supported. I build this small library in order to make PIC microcontrollers with limited RAM and ROM such as PIC16F877A and PIC12F series to make them read files from FAT16 formatted SD cards. With this library I was able to read any file from FAT16 SD card.
About CCS C FAT16 library:
  • FAT16 read files.
  • If the MMC/SD card has Master Boot Record (MBR), the library will work with the first active partition.
  • Only short file name is supported (file name + extension < 13 character).
  • Only one file can be opened at a time, if a 2nd file is opened the first file will be automatically closed.
  • The user can set buffer size starting from 1 byte. Bigger buffer size --> higher speed.
  • Letter case insensitive.
  • Library functions read files from the root directory only.
  • This library requires MMC/SD card driver to communicate with the media.
Library functions:
This library is small and easy to use, it has 4 functions only:
fat16_init():
Initializes the MMC/SD card and reads the FAT16 boot sector to extract necessary data. Return 0 if OK and 1 if an error occurred (for example problem with MMC/SD initialization).
fat16_open_file(int8* fname):
Opens file stream. fname is file name (short file name). Returns 0 if OK and 1 if error (example: file not found, long file name ....).
fat16_read_byte(int8* data):
Reads a byte from the opened file where data is buffer to store read byte to. Returns 0 if OK, 1 if error or end of file is reached.
fat16_read_data(int32 size, int8* data):
This function reads one byte or more which can be set by size where data is the data buffer. Returns 0 if OK, 1 if error or end of file is reached.

Library Download:
DOWNLOAD

Examples:
Read text file from SD card with FAT16 file system using PIC16F877A
Display BMP images from SD card on ST7735 TFT screen
Read and display text file from FAT16 microSD card using PIC18F4550
Read text files from FAT16 SD card with PIC16F887