In the new year I decided to improve not only the skills, but also foreign languages I will try.
To write something on the card you have in the beginning to recognize card type and recognize the file type. To do this, run one after the other two sub-programs. "Sdinit" and "Sdinitfs". If at the end of the variable "Sdstatus = 0" means that we can write bytes one after another. Therefore, a temporary variable that rewrite the text you want to save the buffer Overlay I created.
I'm not a specialist and the first time I write something on the card with the use of the library. Surely you can do better.
Dim Temp_string AsString*20 Dim Temp_bufor(20)AsByteAt Temp_string Overlay Dim Send AsByte , Send_len AsByte , Datas AsByte Dim Something_must_be_saved AsByte'for this example 'init card Lcd"Init SD" Gosub Sdinit
If Sdstatus =0Then Gosub Sdinitfs
End If Home Wait1 If Sdstatus =0Then Lcd"Okay! " Else Lcd"No Card" End If
'### DOUBLE SPEED of SPI It is in the declarations but I preferred it to have a test on top
Spsr.0 =1' Double speed (results in f osc / 2)
Spcr.1 =0' f osc / 4
Spcr.0 =0 '### --------------- ### Wait1 EnableInterrupts Lowerline:Lcd"Waiting..."
'***************************************************** '*********************** START *********************** 'main loop Do
If Something_must_be_saved =1ThenGosub Save_to_sd
Loop End '************************ END ************************ '***************************************************** $include"KokkeKat_FAT-free_SD_lib_code.bas"
'zapis na karte
Save_to_sd:
If Sdstatus =0Then
Gosub Sdreadfsinfo
Sdentrynames ="LOGGED "'name of file on card (11 characters)
Sdstartdirclusterd =0 ' I have RTC 'Sdyear = Year 'Sdmonth = Month 'Sdday = Day 'Sdhours = Hour 'Sdminutes = Minute 'Sdseconds = Second
Gosub Sdpreparetoappend 'find file and last record
Sdclosefile =0' Always make sure that Sdclosefile = 0 before writing
Sdbyterw =32' Write "Space" Gosub Sdwritebyte 'this saves one single byte to card
'# For Datas =1To3 'written in a single line will be three consecutive text variables SelectCase Datas
Case1: Temp_string = Time_string
Send_len =20 Case2: Temp_string = Rezultat_string
Send_len =20 Case3: Temp_string = Temp_str
Send_len =Len(temp_str)'variables such as different lengths (example) EndSelect
For Send =1To Send_len 'variables such as different lengths (example) If Sdclosefile =0Then
Sdbyterw = Temp_bufor(send) Gosub Sdwritebyte 'this saves one single byte to card Else 'Handle partition full End If
Next If Sdclosefile =0Then
Sdbyterw =32' Write "Space" Gosub Sdwritebyte 'this saves one single byte to card Else ' Handle partition full End If Next '#
'from this point enter and mark the end of the line If Sdclosefile =0Then
Sdbyterw =13' Write "Enter" Gosub Sdwritebyte
Else ' Handle partition full End If
If Sdclosefile =0Then
Sdbyterw =10' Write "LF" next line Gosub Sdwritebyte
Else ' Handle partition full End If
Gosub Sdfinalizeafterwriting ' After writing the last byte, close the file Gosub Sdwritefsinfo ' Save the updated fsinfo variables back
End If
Return
On the need to create the file. For example LOGGED.txt. Then rename it so that it does not have an extension. "LOGGED" (11 characters - insert spaces). If you want to use the "normal" name is required unless additional 254B
...and this example of the output and write on the card. You can see three separate variables in one line
Nie 28-12-2014 23:45 401040140234201 Fiat
Nie 28-12-2014 23:46 401040140340240 Ford
Nie 28-12-2014 23:46 403040340340341 Opel
Pon 29-12-2014 00:03 401040140234201 Fiat
Pon 29-12-2014 00:05 401040140340240 Ford
Pon 29-12-2014 00:05 403040340340341 Opel
With PCF8583 + 100year calendar + SelCall Decoder + Kokkekat + LCD program takes ~16KB
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum