From Swordfish Wiki

SwordfishUser: SDFileSystemSampleCode2

Sample Code 2 - Writing and overwriting a file using FSeek

Device = 18F4620
Clock =  40
Config OSC = HSPLL

#option SD_SPI = MSSP
#option SD_SPI_SPEED = spiOscDiv4
#option SD_SUPPORT_SUB_DIRECTORIES = False
Include "SDFileSystem.bas"
Include "USART.bas"
Include "Convert.bas"

Dim DoNotRemoveLED As PORTD.0

Dim XYSet As LongWord

Sub WriteFooter()
   SD.Write("    </Coordinates>", 13, 10)
   SD.Write("  </Document>", 13, 10)
   SD.Write("</kml>", 13, 10)
End Sub

Output(DoNotRemoveLED) 
DelayMS(100)

USART.SetBaudrate(br38400)

USART.Write("Insert SD/MMC:", 13, 10)
Repeat
Until SD.Init() = errOK

DoNotRemoveLED = 1

USART.Write("Formatting:", 13, 10)
SD.QuickFormat

USART.Write("WRITING HEADER & FOOTER...", 13, 10)
SD.NewFile("TESTFILE.XML")
SD.Write("<?xml version=", 34, "1.0", 34, " encoding=", 34, "UTF-8", 34, "?>", 13, 10)
SD.Write("<kml>", 13, 10)
SD.Write("  <Document>", 13, 10)
SD.Write("    <Coordinates>", 13, 10)
WriteFooter()
USART.Write("HEADER & FOOTER WRITTEN", 13, 10)
USART.Write("CLOSING FILE...", 13, 10)
SD.CloseFile
USART.Write("FILE CLOSED", 13, 10)

USART.Write("OPENING FILE...", 13, 10)
SD.OpenFileRW("TESTFILE.XML")
USART.Write("FILE OPENED", 13, 10)

DoNotRemoveLED = 0

XYSet = 0

Repeat
   If XYSet Mod 100 = 0 Then
      USART.Write("*")
      DelayMS(3000)
   EndIf
   DoNotRemoveLED = 1
   USART.Write(".")
   SD.FSeek(SD.FileSize - 41) 
   SD.Write("      ", DecToStr(XYSet), ",", DecToStr(XYSet), 13, 10)
   WriteFooter()
   SD.SaveFile
   DoNotRemoveLED = 0
   Inc(XYSet)
Until False
Retrieved from https://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.SDFileSystemSampleCode2
Page last modified on March 21, 2008, at 10:52 AM