• Pic® Basic

  • SD_File_System


    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_System

    Example 1

          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
              DelayMS 200
              HSerOut ["INSERT SD OR MMC",13]
                  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]
              HSerOut ["FILE OPEN",13]
              While SD_EOF < 1
                  Response = SD_Read_Byte_From_File
                  HSerOut [Response]
              HSerOut [13]
              HSerOut ["FINISHED",13]