Sd card code


Closed Thread
Results 1 to 18 of 18

Thread: Sd card code

  1. #1
    Join Date
    May 2010
    Posts
    21

    Default Sd card code

    i would like to request code using pic basic for sd card reader......

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

  3. #3
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Smile sd card reader

    thanks....

  4. #4
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    can i request for sd card reader code in PBP version 2.6??

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    As far as I can see the code I linked to previously IS for v2.6 - at least that's what it says, second line of code:
    Code:
    'Name        : sdfs3.pbp
    'Compiler    : PICBASIC PRO Compiler 2.6 (PBPL only)
    'Assembler   : MPASM
    'Target PIC  : PIC16F4550
    <table style="width: 141px; height: 21px;"><tbody><tr><td class="number">
    </td><td class="content">
    </td></tr></tbody></table>

  6. #6
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    sorry..it's my bad..it's PBP 2.5 version that i used...
    thanks..

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The link provided works for 2.5 also. PBPL is the key.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Thumbs up sd card reader

    thanks....

  9. #9


    Did you find this post helpful? Yes | No

    Default

    does this also support SDHC cards?

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    SDFS was modified for FAT32 and can be found here
    http://www.picbasic.co.uk/forum/show...7887#post77887
    It works for me as is but is not being maintained.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    i have try to compile the source code that you gave, but there are a lot of error...one of them are Redefinition of LABEL SD_CS.i would like to know what are the meaning of this error?? i have google but it not helping....

    thanks

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looks like you tried compiling SDFS.BAS as a stand alone, it is an "include".
    Did you read "sdreadme.txt"?
    Did you write any code to use the include? If so, post it.
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    this is the code....
    Code:
        Define    OSC    20    ' 20 MHz oscillator
    
    ' Alias PIC pins and registers for SD/MMC card
    SD_WE        Var    PORTA.4    ' SD card write protect
    SD_WE_TRIS    Var    TRISA.4    ' SD card write protect direction
    SDI        Var    PORTB.0    ' SPI data in
    SDI_TRIS    Var    TRISB.0    ' SPI data in direction
    SCL        Var    PORTB.1    ' SPI clock
    SCL_TRIS    Var    TRISB.1    ' SPI clock direction
    SD_CS        Var    PORTB.3    ' SD card chip select
    SD_CS_TRIS    Var    TRISB.3    ' SD card chip select direction
    SD_CD        Var    PORTB.4    ' SD card detect
    SD_CD_TRIS    Var    TRISB.4    ' SD card detect direction
    SDO        Var    PORTC.7    ' SPI data out
    SDO_TRIS    Var    TRISC.7    ' SPI data out direction
    
    
    ' Include the SD/MMC subroutines (found in http://melabs.com/resources/samples/pbp/sdfs3.zip)
        Include "SDFS.PBP"
        SDC_UseHardSPI = TRUE    ' Use hardware SSP port for SPI.
    
        ADCON1 = 15        ' All I/O pins digital
        Pause 100
    
        ' FSInit initializes the card and reads all the preliminary information from it
        Gosub FSInit
        Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
        If (FAT_error != 0) Then Stop
    
        ' Display card directory
        Gosub FINDfirst        ' Find first file on card
        While (FAT_error = 0)
            Serout2 PORTC.6, 84, [Str FAT_FileName\11, $d, $a]
            Gosub FINDnext    ' Find next file on card
        Wend
    
    ' This section defines a specific short (8.3) filename
    '  Note that spaces are use in empty elements and must be upper case for Windows
        FAT_FileName[0] = "T"
        FAT_FileName[1] = "E"
        FAT_FileName[2] = "S"
        FAT_FileName[3] = "T"
        FAT_FileName[4] = "1"
        FAT_FileName[5] = " "
        FAT_FileName[6] = " "
        FAT_FileName[7] = " "
        FAT_FileName[8] = "T"
        FAT_FileName[9] = "X"
        FAT_FileName[10] = "T"
    
    ' Set file time to 8:30:10 and date to 1/1/2008
        FAT_seconds = 5
        FAT_minutes = 30
        FAT_hours = 8
        FAT_day = 1
        FAT_month = 1
        FAT_year = 28
    
    ' Open a file for write
        FAT_mode = "w"        ' Write mode
        Gosub FSfopen        ' Open file pointed to by Byte array FAT_FileName
        Serout2 PORTC.6, 84, ["Open for write: ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Write to file
        FAT_src[0] = "A"
        FAT_src[1] = "B"
        FAT_src[2] = "C"
        FAT_count = 3
        Gosub FSfwrite
        Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Close file
        Gosub FSfclose
        Serout2 PORTC.6, 84, [ "Close ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Open a file for read
        FAT_mode = "r"        ' Read mode
        Gosub FSfopen        ' Open file pointed to by Byte array FAT_FileName
        Serout2 PORTC.6, 84, ["Open: ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Read and display the whole file
        FAT_count = 1        ' Read 1 byte to buffer at a time
        Gosub FSfread
        While (FAT_error = 0)
            Serout2 PORTC.6, 84, [FAT_dest[0]]
            FAT_count = 1    ' Read 1 byte to buffer at a time
            Gosub FSfread
        Wend
        Serout2 PORTC.6, 84, [ "Read: ", Dec FAT_error, $d, $a]
    
    ' Delete a file
    '    Gosub FSremove        ' Delete file pointed to by Byte array FAT_FileName
    '    Serout2 PORTC.6, 84, ["Remove: ", Dec FAT_error, $d, $a]
    '    If (FAT_error != 0) Then Stop
    
    ' Rename a file
    ' FAT_FileName2 is new name
    '    FAT_FileName2[0] = "T"
    '    FAT_FileName2[1] = "E"
    '    FAT_FileName2[2] = "S"
    '    FAT_FileName2[3] = "T"
    '    FAT_FileName2[4] = "2"
    '    FAT_FileName2[5] = " "
    '    FAT_FileName2[6] = " "
    '    FAT_FileName2[7] = " "
    '    FAT_FileName2[8] = "T"
    '    FAT_FileName2[9] = "X"
    '    FAT_FileName2[10] = "T"
    '    Gosub FSrename        ' Rename file pointed to by Byte array FAT_FileName
    '    Serout2 PORTC.6, 84, ["Rename: ", Dec FAT_error, $d, $a]
    '    If (FAT_error != 0) Then Stop
    
        End

  14. #14
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    this are the code
    Attached Files Attached Files

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I ran your code, it looks like the file SDFS3 that cam with the download, and it compiled fine.
    The only way I can reproduce your error is to try compiling SDFS.

    Using PBPL
    target is 18F4550

    What other errors are you getting?
    Dave
    Always wear safety glasses while programming.

  16. #16
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    i don't have the PBPL box in my widow..here are the picture..
    Attached Images Attached Images  

  17. #17
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default sd card reader

    i have use the new version of MCS..i'm using the 3.0.0.5 version. but i'm facing a new problem which is this " The Microchip assembler (MPSM) only allows up to 62 character to be used for path and filename".....

  18. #18
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Then simply change the location (path) and/or filename of your sourcefile so that the complete path and filename is less than 62 characters - simple as that.

    As an example, having your source files in project folder in a PIC folder in MyDocuments is bad as the full path might be:
    C:\Documents and Settings\Nurulhaiza\My Documents\PIC\MySDFSProject\Source.pbp which is 78 characters. Moving it to C:\PIC\MySDFSProject\Source.pbp will work as the path and filename now is 31 characters.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts