The SD_File_System module is a macro library for use with Library Manager by JohnGB. This module has been written by Steven Wright (swright on PDS forum). The library module is offered on an as-is basis with no warranty as to its effectiveness, operation or reliability. Users use it at their own risk.
Feature summary
- Macros for accessing Secure Digital (SD) or Multimedia Memory Card (MMC) cards – SD_Init, SD_Sector, SD_Read and SD_Write.
- Macros for writing files to these cards in the FAT16 format – such files can be read directly by a PC, using a card reader. The commands include SD_Init_FS, SD_Check_For_File, SD_New_File, SD_Append_File, SD_Write_Byte_To_File, SD_Write_String_To_File, SD_Save_File and SD_Close_File. Also commands for reading files, including SD_Open_File and SD_Read_Byte_From_File. Also file and disk management commands, including SD_Delete_File, SD_Free_Space, SD_Disk_Size, SD_Dir and SD_Psuedo_Format.
Download module
Download: SD_File_SystemExample 1
Code:
Device = 18F4550
XTAL = 20
'-----------------------------------------------------------
ALL_DIGITAL = TRUE
'-----------------------------------------------------------
HSERIAL_BAUD = 115200 'Setup RS232 port
HSERIAL_RCSTA = 010000
HSERIAL_TXSTA = 100100
'-----------------------------------------------------------
Dim Response As Byte
Dim SD_IO As Byte
'-----------------------------------------------------------
Symbol SD_CS = PORTD.2 'SPI CS to SD CS (SD pin 1)
Symbol SD_DI = PORTD.5 'SPI DO to SD DI (SD Pin 2)
Symbol SD_CLK = PORTD.3 'SPI CLK to SD CLK (SD Pin 5)
Symbol SD_DO = PORTD.4 'SPI DI to SD DO (SD Pin 7)
'-----------------------------------------------------------
Include "SD_MMC_Read_File_Lib.pbp" 'Include managed library file
'-----------------------------------------------------------
GoTo Over_Sub 'Jump over the subroutines
'-----------------------------------------------------------
Over_Sub:
DelayMS 200
'-----------------------------------------------------------
Main_Prog:
HSerOut ["INSERT SD OR MMC",13]
Repeat
Response = SD_Init_FS
Until Response = 0
HSerOut ["OPENING FILE",13]
SD_File_Name = "TEST001" 'File Name, upper case only!
SD_File_Ext = "TXT" 'File Ext, upper case only!
Response = SD_Open_File
If Response = 1 Then
HSerOut ["FILE NOT FOUND",13]
Stop
EndIf
HSerOut ["FILE OPEN",13]
While SD_EOF < 1
Response = SD_Read_Byte_From_File
HSerOut [Response]
Wend
'-----------------------------------------------------------
Finish:
HSerOut [13]
HSerOut ["FINISHED",13]
Stop


Menu
Recent Articles


Using PDS with SPI GLCD based on ST7565R Controller
Graphic LCDs based on the ST7565 are cheaper then GLCDs with other controllers. SPI requires only four pins. If the circuit