Site icon Ercan Koçlar

SD Card ( SD Mode) and Fat32 – MikroC Library

fat32-sd-kart-kapak

fat32-sd-kart-kapak

This post is also available in: Türkçe (Turkish)


 


In this lesson, we will see the use of SD cards (SD Mode) and the microc library I wrote for FAT32. But first I’ll start with the SD card. The SD card and FAT32 are written in the same way for the same library, so we will first go through file operations with FAT32 after learning how to install and use the SD card circuit.

What you will read in this lesson is the only using part of the library that is the result of 22-months study.

SD Card(SD Mode)

SD Mod

SPI Mod

All pins are used for connection (can only be driven using Data0 if wanted) Only 3 pins are used for connection
Data transfer rate is at least 50 Mhz Data transfer speed is ? Mhz
All data ports (Data0, Data1, Data2, Data3) are used to transfer data. Data and commands are transferred from the same single pin.
The commands and all other operations are very fast because they are made from separate pins. Since data, commands and responses are made on the same pin, it is very slow.
It supports very high speed modes like UHS. It certainly does not support modes like UHS.
CRC provides control, thus the integrity of the data is guaranteed. There is no CRC check, the data can be recorded as corrupted.
SD mode driver codes are sold at high prices (I wrote it for free!) SPI mode driver codes can be found free of charge.

SD Card Pins and Functions

The pins of the SD card are visible.

SD Card Drive Circuit

Circuit diagram

Circuit diagram required for SD mode – SD card

Necessary materials

1. 4 pieces 47K resistor
2. 1 x IP4252CZ8 Passive Filter
3. 1 x SD Card Socket
4. Perforated Pertinaks

IP4252CZ8
MikroSD Card socket

 

 

 

 

 

 

 

Making the Circuit

SD Card  IP4252CZ8 passive filter
SD Card SD Mode Driver Circuit

SD Card SD Mode Software

Some of the SD cards that the SD card library has been tested are visible.

Functions

1-General Purpose Main Functions

 

– SD_CLOCK Function

Function : void SD_CLOCK(unsigned char dongu_sayisi)

Purpose :Creates the heartbeat of the SD card. Each command on the SD card is processed with a clock pulse every bit of each command.

Parameters:

Usage : 

SD_CLOCK(80);//80 clock signals are sent.

Feedback: It does not return any value since it is a void type.

 

SD_SDMOD_ANALIZ Function

Founction : unsigned char SD_SDMOD_ANALIZ(unsigned char SD_VERI_YOLU_GENISLIGI)

Purpose :It is used primarily to identify the SD card. First it wakes up the sd card and sends it some commands to gather information about it. There are two options in the parameter that it has.

Parameters:

Usage:

SD_SDMOD_ANALIZ(4); // 4 bit mode enabled

Feedback:

SD_MOD_VERI_YAZMA_RUTINI_4BIT Function

Function : unsigned char SD_MOD_VERI_YAZMA_RUTINI_4BIT()

Purpose : When the 4-bit mode is selected for the SD card, the software calls this function for all write operations.

Parameter : no.

Usage:

SD_MOD_VERI_YAZMA_RUTINI_4BIT(); // The data write routine to be used when 4-bit mode is enabled.

Feedback:

 

SD_MOD_VERI_YAZMA_RUTINI_1BIT Function

Function : unsigned char SD_MOD_VERI_YAZMA_RUTINI_1BIT()

Purpose : When 1 bit mode is selected for the SD card, the software calls this function for all write operations.

Parameter : no

Usage:

SD_MOD_VERI_YAZMA_RUTINI_1BIT(); // When 1 bit mode is enabled, only data0 is used in the data writing routine to be used.

Feedback:

 

SD_MOD_VERI_OKUMA_RUTINI_4BIT  Function

Function : unsigned char SD_MOD_VERI_OKUMA_RUTINI_4BIT()

Purpose : When the 4-bit mode is selected for the SD card, the software calls this function for all read operations.

Parameter : no

Usage:

SD_MOD_VERI_OKUMA_RUTINI_4BIT();//The data reading routine to be used when 4-bit mode is enabled.

Feedback:

 

SD_MOD_VERI_OKUMA_RUTINI_1BIT  Function

Function : unsigned char SD_MOD_VERI_OKUMA_RUTINI_1BIT()

Purpose : When 1 bit mode is selected for the SD card, the software calls this function for all read operations.

Parameter : no

Usage:

SD_MOD_VERI_OKUMA_RUTINI_1BIT();//The data read routine to be used when 1 bit mode is enabled.

Feedback:

 

2- Sector Writing Functions

 

SD_MOD_TEK_BLOK_YAZ Function

Function : unsigned char SD_MOD_TEK_BLOK_YAZ(unsigned long BLOK_ADRESI)

Purpose :The address of the data loaded into the data buffer is written to the given block. Writes single block.

Parameter:

Usage:

//data transfer to the buffer
//If there are random values in empty sequences, they are transferred as they are.
SD_DATA_TAMPONU[0]=121545;
SD_DATA_TAMPONU[1]=415464;
SD_DATA_TAMPONU[2]=2342342;
SD_DATA_TAMPONU[3]=23432432;
//the write command is given after loading the data to the buffer
SD_MOD_TEK_BLOK_YAZ(3);//write the data to the 3th block

Feedback:

2A – Multiple Writing Functions

 

SD_COKLU_BLOK_YAZ_BASLAT Function

Function  : unsigned char SD_COKLU_BLOK_YAZ_BASLAT(unsigned long BLOK_ADRESI,unsigned long YAZILACAK_BLOK_SAYISI)

Purpose :Starts multiple writes. By specifying the address to start writing and how many blocks to write, the SD card allows you to pre-erase those areas and save time.

Parameter:

Feedback:

SD_COKLU_BLOK_YAZ_VERIGONDER Function

Function : unsigned char SD_COKLU_BLOK_YAZ_VERIGONDER()

Purpose :It sends the loaded data to the buffer.

Parameter : no

Feedback :

SD_COKLU_BLOK_YAZ_BITIS Function

Function : unsigned char SD_COKLU_BLOK_YAZ_BITIS()

Purpose :Ends multiple writing.

Parameter : no

Feedback :

Multiple Writing Functions Usage Mode:

SD_COKLU_BLOK_YAZ_BASLAT(10,5);//preparing for multiple writing
// set the value of i to 5 for writing 5 blocks.
for(İ=0;i<5;i++)
  {
     
     SD_COKLU_BLOK_YAZ_VERIGONDER();data update operation // (any function that updates the data in the temporary buffer)
  }
SD_COKLU_BLOK_YAZ_BITIS();//writing has been ended

 

3-Sector Reading Functions

 

SD_MOD_TEK_BLOK_OKUMA Function

Function : unsigned char SD_MOD_TEK_BLOK_OKUMA(unsigned long BLOK_ADRESI)

Purpose :It reads a single block from the SD card and loads the data into the buffer.

Parameter : 

Usage:

SD_MOD_TEK_BLOK_OKUMA(0);// the first block is read.

Feedback:

3A-Multiple Reading Functions

 

SD_COKLU_BLOK_OKUMA_BASLAT Function

Function : unsigned char SD_COKLU_BLOK_OKUMA_BASLAT(unsigned long BLOK_ADRESI)

Purpose :Gives the SD card the block address to read and prepares the card to read.

Parameter :

Feedback:

SD_COKLU_BLOK_OKUMA_VERIOKU  Function

Function : unsigned char SD_COKLU_BLOK_OKUMA_VERIOKU()

Purpose :From the specified address, block block data from the SD card is written into the data buffer.

Parameter : no

Feedback :

SD_COKLU_BLOK_OKUMA_BITIS Function

Function : unsigned char SD_COKLU_BLOK_OKUMA_BITIS()

Purpose :Informs the SD card that reading has ended.

Parameter : no

Feedback :

Multiple Reading Functions Usage Mode:

SD_COKLU_BLOK_OKUMA_BASLAT(100);//multiple reading starting addresses were reported.
// This value is given for reading 30 blocks.
for(İ=0;i<30;i++)
  {
     SD_COKLU_BLOK_OKUMA_VERIOKU();data use operation; // data should be used in each read. Otherwise the newly read data will overwrite the old ones.
       
  }
SD_COKLU_BLOK_OKUMA_BITIS();//reading has been ended

 

4- Sector Erase Functions

 

SD_MOD_SEKTOR_SIL Function

Function : unsigned char SD_MOD_SEKTOR_SIL(unsigned long BASLANGIC_ADRESI,unsigned long BITIS_ADRESI)

purpose :Deletes all intervening sectors, including the specified start and end sectors.

Parameter:

Usage:

SD_MOD_SEKTOR_SIL(12224,12224);//12224. erases sector
SD_MOD_SEKTOR_SIL(100,1000);//It erases all sectors from 100th sector to 1000th sector.

Feedback :

5-Command Functions

Examination of the commands sent to the SD card and the answer on the oscilloscope.

CMD0 Command

Function : void CMD0()
Purpose : Reset the SD card to initial position.

 

CMD8 Command

Function : unsigned char CMD8()
Purpose :Identifies the SD card and determines what voltage range it will operate on.

 

CMD55 Command

Function  : unsigned char CMD55(unsigned int RCA_ADRESI)
Purpose :The SD card is sent before the ACMD commands in the system.

 

ACMD41 Command

Function : unsigned char ACMD41()
Purpose : determines the information such as the voltage range of SD card, card type, and so on.

 

CMD2 command

Function : unsigned char CMD2()
Purpose : Reads CID parameters of SD card

 

CMD3 command

Function : unsigned char CMD3()

Purpose :Generates ID for SD card. RCA code.

 

CMD9 command

Function : unsigned char CMD9(unsigned int RCA_ADRESI)

Purpose : Retrieves the CSD information of the SD card.

 

CMD7 command

Function : unsigned char CMD7(unsigned int RCA_ADRESI)

Purpose : The RCA selects the card to which the address is written, others are idle.

 

ACMD6 command

Function : unsigned char ACMD6()

Purpose : Makes the data width 4 bits.

 

CMD17 command

Function  : unsigned char CMD17(unsigned long ADRES)

Purpose :It makes a single block reading.

 

CMD18 command

Function : unsigned char CMD18(unsigned long ADRES)

Purpose :Makes multiple reading.

 

ACMD23 command

Function : unsigned char ACMD23(unsigned long BLOK_SAYISI)

Purpose : Makes pre-deleting before multiple writing.

 

CMD24 command

Function : unsigned char CMD24(unsigned long ADRES)

Purpose : writes single block

 

CMD25 command

Function : unsigned char CMD25(unsigned long ADRES)

Purpose :It writes multiple blocks.

 

ACMD22 command

Function : unsigned char ACMD22()

Purpose :Gives the correct number of blocks written.

 

CMD32 command

Function : unsigned char CMD32( unsigned long ADRES)

Purpose :Declares the start address of the delete operation.

 

CMD33 command

Function : unsigned char CMD33(unsigned long ADRES)

Purpose :Specifies the ending address of the deletion.

 

CMD38 command

Function : unsigned char CMD38()

Purpose :Perform deletion.

 

CMD12 command

Function : unsigned char CMD12()

Purpose :Stops writing or reading data under all conditions.

 

CMD13 command

Function : unsigned char CMD13(unsigned int RCA_ADRESI)

Purpose :Tell the card’s status.

 

CMD16 command

Function : unsigned char CMD16()

Purpose : The block length is set to 512 bytes.

 

CMD56 command

Function : unsigned char CMD56(unsigned char ISLEV)

Purpose : If the function is 1, it reads. If the function is 0, it writes.


Information Tables About SD Card

1-CID Table ( Card IDentification)

Name Width Area
Manufacturer ID 8 bit [127:120]
OEM/Application ID 16 bit [119:104]
Name of the product 40 bit [103:64]
Product Revision 8 bit [63:56]
Product Serial Number 32 bit [55:24]
Reserved Area 4 bit [23:20]
Production date 12 bit [19:8]
CRC7 Code 7 bit [7:1]
It is always 1 out of use. 1 bit [0:0]

 

2-CSD Table (Card-Specific Data)

Name Original Zone Names Width Area
CSD stucture CSD_STRUCTURE 2 bit  [127:126]
Reserved Area 6 bit [125:120]
Data Reading Rate -1 TAAC 8 bit  [119:112]
Data Read Speed – 2 CLK cycles NSAC 8 bit  [111:104]
Max. Data Transfer Rate TRAN_SPEED 8 bit [103:96]
Card Command Class CCC 12 bit [95:84]
Max. Data Reading Block Width READ_BL_LEN 4 bit [83:80]
Part Block Reading Active READ_BL_PARTIAL 1 bit [79:79]
Non-aligned Block Writing WRITE_BLK_MISIALIGN 1 bit [78:78]
Non-aligned Block Reading READ_BLK_MISIALIGN 1 bit [77:77]
DSR Embedded DSR_IMP 1 bit [76:76]
Reserved Area 2 bit [75:74]
Device Size C_SIZE 12 bit [73:62]
Max. Reading Current
@VDD min
VDD_R_CURR_MIN 3 bit [61:59]
Max. reading current@VDD max VDD_R_CURR_MAX 3 bit [58:56]
Max. writing current @VDD min VDD_W_CURR_MIN 3 bit [55:53]
Max. writing current @VDD max VDD_W_CURR_MAX 3 bit [52:50]
Device Size Factor C_SIZE_MULT 3 bit [49:47]
Single Block Erase Enabled ERASE_BLK_EN 1 bit [46:46]
Erasable Sector Size SECTOR_SIZE 7 bit [45:39]
Write Protected Group Size WP_GRP_SIZE 7 bit [38:32]
 Writing Protected Group Enabled WP_GRP_ENABLE 1 bit [31:31]
Reserved area 2 bit [30:29]
Writing Speed Factor R2W_FACTOR 3 bit [28:26]
Max. Writeable Data Block Length WRITE_BL_LEN 4 bit [25:22]
Part Block Writing Active WRITE_BL_PARTIAL 1 bit [21:21]
Reserved Area 5 bit [20:16]
File Format Group FILE_FORMAT_GRP 1 bit [15:15]
Copy Flag COPY 1 bit [14:14]
Permanent Writing Protection PERM_WRITE_PROTECT 1 bit [13:13]
Temporary Writing Protection TMP_WRITER_PROTECT 1 bit [12:12]
File Format FILE_FORMAT 2 bit [11:10]
 Reserved area 2 bit [9:8]
 CRC CRC 7 bit [7:1]
Not used – always 1 1 bit [0:0]

Application of Functions

 

1-Making Pin Identification

//sd card
sbit SD_DATA0 at RB0_bit;
sbit SD_DATA1 at RB1_bit;
sbit SD_DATA2 at RB2_bit;
sbit SD_DATA3 at RB3_bit;
sbit SD_CLK at RB5_bit;
sbit SD_CMD at RB4_bit;


sbit SD_DATA0_Direction at TRISB0_bit;
sbit SD_DATA1_Direction at TRISB1_bit;
sbit SD_DATA2_Direction at TRISB2_bit;
sbit SD_DATA3_Direction at TRISB3_bit;
sbit SD_CLK_Direction at TRISB5_bit;
sbit SD_CMD_Direction at TRISB4_bit;

 

2- SD Card Identification and Preparation for Using

void  main()
{
    ADCON1=7;//It is the port setting related to PIC. There is nothing to do with the SD card.
    CMCON=7;// It allows the comparators related to PIC to be turned off.

    SAP1024_INIT(240,128,6);//The GLCD library to be used in the project is the invocation code.

    SD_SDMOD_ANALIZ(4);// It analyzes the SD card and prepares it for use. It is reported here that 4 data ports can be used by writing 4.

}

 

3- Writing Data to SD Card Sectors

Informing about sectors of SD card
void  main()
{
   unsigned char denetim=120;

   ADCON1=7;
   CMCON=7;

   SAP1024_INIT(240,128,6);//glcd  screen identification code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0); //  sd card analysis
   
   //Data is loaded into the buffer.
   SD_DATA_TAMPONU[0]=0x7777772E;//www.
   SD_DATA_TAMPONU[1]=0x65726361;//erca
   SD_DATA_TAMPONU[2]=0x6E6B6F63;//nkoc
   SD_DATA_TAMPONU[3]=0x6C61722E;//lar.
   SD_DATA_TAMPONU[4]=0x636F6D20;//com 
   
   do{denetim=SD_MOD_TEK_BLOK_YAZ(4);}while(denetim==0); // Data are written to 4th sector.

   SAP1024_YAZI_YAZMA(1,1,"bitti");//The GLCD is printed out on the screen.

}
Waste data in SD card sector
void  main()
{
   unsigned char denetim=120,i;

   ADCON1=7;
   CMCON=7;

   SAP1024_INIT(240,128,6);//glcd screen identification code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0); //  sd card analysis
   
   //Data is loaded into the buffer.
   SD_DATA_TAMPONU[0]=0x7777772E;//www.
   SD_DATA_TAMPONU[1]=0x65726361;//erca
   SD_DATA_TAMPONU[2]=0x6E6B6F63;//nkoc
   SD_DATA_TAMPONU[3]=0x6C61722E;//lar.
   SD_DATA_TAMPONU[4]=0x636F6D20;//com 

   //Unused buffers are equal to zero.
   for(i=5;i<128;i++)
     {
       SD_DATA_TAMPONU[i]=0;
     }
   
   do{denetim=SD_MOD_TEK_BLOK_YAZ(4);}while(denetim==0); // Data are written to 4th sector.

   SAP1024_YAZI_YAZMA(1,1,"bitti");//GLCD finished is printed on the screen

}
The rest of the industry has now been cleaned from the data.

4- Reading Data from SD Card Sectors

void  main()
{
  unsigned char denetim=120,i=0;
  unsigned char donusum[9];//created for the standard transforming library of mikroC.
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6);

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//SD card analysis and setup was done.
   do{denetim=SD_MOD_TEK_BLOK_OKUMA(4);}while(denetim==0);// The fourth sector was read and written to the data buffer.

   for(i=0;i<5;i++)// the sequence will be printed in line by line with GLCD.
     {
       LongWordToHex(SD_DATA_TAMPONU[i],donusum); //   The data in the data buffer was converted to hexadecimal. 
       SAP1024_YAZI_YAZMA(1,(i+1),donusum);// Evolved data was written in GLCD.
     }
}
Data read from sector 4 of the SD card
void  main()
{
    unsigned char denetim=120,i=0,j=0,k=1;
    unsigned char txt[2];// created to represent the read data as characters.
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6);

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//SD card analysis and setup was done.
   do{denetim=SD_MOD_TEK_BLOK_OKUMA(4);}while(denetim==0);// The 4th sector was read and written to the data buffer.

   txt[1]=0;// The last element in a string must be 0. Otherwise it will give an error.
            //because it continues to read string strings until the system sees 0.

   // The 32 bit data at our disposal will be divided into 4 parts. Each piece will be printed on the individual GLCD.
   // a column will be shifted each time to prevent the text from coming up.
   for(j=0;j<5;j++)
     {
       for(i=0;i<4;i++)
         {
           txt[0]=SD_DATA_TAMPONU[j]>>(24-(i*8));// Because the data buffer is 32 bits, I transferred the data by shifting. 
           SAP1024_YAZI_YAZMA(k,1,txt);//one column was shifted each time so that the characters do not overlap.
           k++;//column shifting variable
         }
     }
}
Reading the data in the sector of the SD card as character.

5- Deletion of Data in the Sector of SD Card

void  main()
{
  unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6);

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//SD card analysis and setup was done.
   do{denetim=SD_MOD_SEKTOR_SIL(4,4);}while(denetim==0);// 4th sector was deleted.
   SAP1024_YAZI_YAZMA(1,1,"bitti");//GLCD Printed over the screen
}
Data from the sector 4 of the SD card was deleted.

SD Card Result


FAT32 File System

Basic Disk System
Cluster Size Selection
Schematic view of the Fat32 system

FAT32 File System Software

Part of the local and foreign resources I use when writing the FAT32 library. All will be shared at the end of the course.

Functions

1- Initial Analysis and Format Functions

 

SD_FAT32_INIT Function

Function : unsigned char SD_FAT32_INIT()

Purpose :It reads the SD card and checks whether formatting is required.

Parameter : no

Usage :

SD_FAT32_INIT();//Reads the SD card to determine whether the card should be formatted and discarded.

Feedback :

SD_FAT32_FORMAT Function

Function : unsigned char SD_FAT32_FORMAT(unsigned char DISK_ETIKETI[11])

Purpose :

Parameter :

Usage :

SD_FAT32_FORMAT("eşröç      ");// Formatted and named. Supports Turkish characters.

Feedback :

2- Calculation Functions

2A- General Account Functions

 

SD_FAT32_TOPLAM_SEKTOR_SAYISI Function

Function : unsigned long SD_FAT32_TOPLAM_SEKTOR_SAYISI()

Purpose :It calculates the total number of sectors in the SD card.

Parametrer : no

Usage :

SD_FAT32_TOPLAM_SEKTOR_SAYISI();//It calculates the number of sectors in the SD card.

Feedback :

SD_FAT32_KOKDIZIN Function

Function : void SD_FAT32_KOKDIZIN()

Purpose :Calculates the root directory of the SD card.

Parameter : no

Usage :

SD_FAT32_KOKDIZIN();//Calculates the data start sector of the SD card. This is also the root directory number.

Feedback :

SD_FAT32_BPB_FATSz32 Function

Function : unsigned int SD_FAT32_BPB_FATSz32()

Purpose :Calculates the number of sectors per FAT zone.

Parameter : no

Usage :

SD_FAT32_BPB_FATSz32();//Number of sectors per FAT

Feedback :

BPB_RsvdSecCnt Function

Function : unsigned int BPB_RsvdSecCnt()

Purpose :Calculate reserve sectors.

Parameter : no

Usage :

BPB_RsvdSecCnt();

Feedback :

SD_FAT32_BOS_CLUSTER_SAYISI Function

Function : unsigned int SD_FAT32_BOS_CLUSTER_SAYISI()

Purpose :Calculates the number of free clusters.

Parameter : no

Usage :

SD_FAT32_BOS_CLUSTER_SAYISI();//FSI_Free_Count- Calculates the number of free clusters.

Feedback :

SD_FAT32_SD_ID Function

Function : unsigned long SD_FAT32_SD_ID()

Purpose: It reads the ID number of the SD card.

Parameter : no

Usage :

SD_FAT32_SD_ID();//BS_VOLID - SERIAL NUMBER READING

Feedback :

2B- FAT Zone Account Functions

 

FAT_BOLGE_DUZENLEME Function

Function : unsigned int FAT_BOLGE_DUZENLEME(unsigned int BASLANGIC_CLUSTER_NUMARASI)

Purpose :It detects empty and full locations in the FAT zone. Makes the necessary arrangement.

Parameter :

Usage :

FAT_BOLGE_DUZENLEME(100);

Feedback : 

FAT_BOLGE_OKUYUCU Function

Function : unsigned int FAT_BOLGE_OKUYUCU(unsigned int BASLANGIC_CLUSTER_NUMARASI)

Purpose :From the given cluster number, it reads all the clusters and returns their numbers.

Parameter :

Usage :

FAT_BOLGE_OKUYUCU(100);

Feedback : 

FAT_BOLGE_SILICI Function

Function: unsigned char FAT_BOLGE_SILICI(unsigned int BASLANGIC_CLUSTER_NUMARASI)

Purpose :Deletes all clusters in order by following the tail from the given start cluster.

Parameter:

Usage :

FAT_BOLGE_SILICI(100);

Feedback : 

FAT_SON_BOLGE_BULUCU Function

Function : unsigned long FAT_SON_BOLGE_BULUCU(unsigned int BASLANGIC_CLUSTER_NUMARASI)

Purpose :It keeps track of the given cluster number. Returns the last cluster number. Used to move to the end of the file

Parametrer :

Usage :

FAT_SON_BOLGE_BULUCU(100);

Feedback : 

FAT_BOLGE_TAYIN_EDICI Function

Function : void FAT_BOLGE_TAYIN_EDICI()

Purpose :When the file is created, it assigns the first cluster zone to the file.

Parameter : no

Usage :

FAT_BOLGE_TAYIN_EDICI();

Feedback :

FAT_BOLGE_TAYIN_EDICI_KLASOR Function

Function : unsigned long FAT_BOLGE_TAYIN_EDICI_KLASOR()

Purpose :Finds cluster location for the new folder and mark it leaves EOC region.

Parameter : no

Usage :

FAT_BOLGE_TAYIN_EDICI_KLASOR();

Feedback : 

3- File Transaction Functions

 

SD_FAT32_DOSYA_OLUŞTUR Function

Function : unsigned char SD_FAT32_DOSYA_OLUSTUR(unsigned char DOSYA_ADI[11])

Purpose : Create a new file

Parameter :

Usage :

SD_FAT32_DOSYA_OLUSTUR("ERCAN   TXT");

Feedback :

SD_FAT32_DOSYA_SEC Function

Function : unsigned char SD_FAT32_DOSYA_SEC(unsigned char DOSYA_ADI[11])

Purpose :Selects the file to process.

Parameter :

Usage :

SD_FAT32_DOSYA_SEC("ERCAN   TXT");

Feedback :

SD_FAT32_DOSYA_KLASOR_SIL Function

Function : void SD_FAT32_DOSYA_KLASOR_SIL()

Purpose :Deletes the selected file or folder.

Parameter : no

Usage :

SD_FAT32_DOSYA_KLASOR_SIL();

Feedback :

SD_FAT32_DOSYA_YENIDEN_ADLANDIR Function

Function : unsigned char SD_FAT32_DOSYA_YENIDEN_ADLANDIR(unsigned char DOSYA_ADI[11])

Purpose :Renames the selected file.

Parameter :

Usage :

SD_FAT32_DOSYA_YENIDEN_ADLANDIR("ERCAN2  TXT");

Feedback :

SD_FAT32_DOSYA_SONUNA_GIT Function

Function : void SD_FAT32_DOSYA_SONUNA_GIT()

Purpose :It goes to the end of the contents of the selected file.

Parameter : no

Usage :

SD_FAT32_DOSYA_SONUNA_GIT();

Feedback :

SD_FAT32_DOSYA_BASINA_GIT Function

Function : void SD_FAT32_DOSYA_BASINA_GIT()

Purpose : goes to the beginning of the content of the selected file.

Parameter : no

Usage :

SD_FAT32_DOSYA_BASINA_GIT();

Feedback :

SD_FAT32_DOSYA_TARIH_SAAT_AYARLA Function

Function : unsigned char SD_FAT32_DOSYA_TARIH_SAAT_AYARLA(unsigned int YIL,unsigned short AY,unsigned short GUN,unsigned char SAAT,unsigned char DAKIKA )

Purpose :Sets the date and time of the file. Due to the FAT32 system, the file year can not go back to 1980.

Parameter :

Usage :

SD_FAT32_DOSYA_ERISIM_TARIH_SAAT_AYARLA(2017,10,6,21,10);// 10 Ekim 2017 saat 21:10

Feedback :

SD_FAT32_DOSYA_DEGISIM_TARIH_SAAT_AYARLA Function

Function: unsigned char SD_FAT32_DOSYA_DEGISIM_TARIH_SAAT_AYARLA(unsigned int YIL,unsigned short AY,unsigned short GUN,unsigned char SAAT,unsigned char DAKIKA )

Purpose :Changes the last modification date of the file.

Parameter :

Usage :

SD_FAT32_DOSYA_DEGISIM_TARIH_SAAT_AYARLA(2017,10,6,21,10);// 10 October 2017 time 21:10

Feedback :

SD_FAT32_DOSYA_LISTELEME Function

Function : unsigned char SD_FAT32_DOSYA_LISTELEME(unsigned int DOSYA_NO)

Purpose :Files in the series;

Parameter :

Usage :

for(i=0;i<10;i++)
   {
     if(SD_FAT32_DOSYA_LISTELEME(i)!=255)
       {
        SAP1024_YAZI_YAZMA(1,(i+2-x),(YDosya_Bilgileri.dosya_adi));
        SAP1024_YAZI_YAZMA(15,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_tarih));
        SAP1024_YAZI_YAZMA(26,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_zaman));
        SAP1024_YAZI_YAZMA(31,(i+2-x),(YDosya_Bilgileri.dosya_boyutu));

       }
   }//note: The detail will be explained in the application section !!!
!

Feedback :

– SD_FAT32_DOSYA_LISTELEME_SONLANDIR Function

Function : void SD_FAT_32_DOSYA_LISTELEME_SONLANDIR()

Purpose :Used to end the listing process.

Parameter : no

Usage : 

SD_FAT_32_DOSYA_LISTELEME_SONLANDIR();

Feedback:

SD_FAT32_DOSYA_VERI_YAZ Function

Function : unsigned char SD_FAT32_DOSYA_VERI_YAZ()

Purpose : Writes the file (SD_DATA_TAMPON installed – remember from SD card) into the selected file.

Parameter : no

Usage :

SD_DATA_TAMPONU[0]=0X47DC4C41;
SD_DATA_TAMPONU[1]=0X59000000;
SD_DATA_TAMPONU[2]=0;

SD_FAT32_DOSYA_VERI_YAZ();

Feedback :

SD_FAT32_DOSYA_VERI_OKU Function

Function : void SD_FAT32_DOSYA_VERI_OKU(unsigned long DOSYA_SEKTOR_SAYISI)

Purpose : Reads sector-specific data from file. Because SD_DATA_TAMPONU is 512 bytes. This corresponds to one sector.

Parameter :

Usage :

SD_FAT32_DOSYA_VERI_OKU(0);//reads the first sector of the selected file.

Feedback :

4- Folder Transaction Functions

 

SD_FAT32_KLASOR_OLUSTUR Function

Function : unsigned char SD_FAT32_KLASOR_OLUSTUR(unsigned char KLASOR_ADI[8])

Purpose : Creates file

Parameter :The name of the folder to be created is written as 8 characters.

Usage :

SD_FAT32_KLASOR_OLUSTUR("ERCAN5  ");

Feedback :

SD_FAT32_KLASOR_ICERIK_YAZMA Function

Function : void SD_FAT32_KLASOR_ICERIK_YAZMA(unsigned long CLUSTER_SAYISI)

Purpose : It is used in SD_FAT32_KLASOR_OLUSTUR function. Writes information about the folder to the system.

Parameter :

Usage :

SD_FAT32_KLASOR_ICERIK_YAZMA(YEREL_CLUSTER);

Feedback :

SD_FAT32_KLASOR_SEC Function

Function : unsigned char SD_FAT32_KLASOR_SEC(unsigned char KLASOR_ADI[8])

Purpose :Selects the folder to process.

Parameter :

Usage :

SD_FAT32_KLASOR_SEC("ERCAN1 ");

Feedback :

SD_FAT32_KLASOR_YENIDEN_ADLANDIR Function

Function : unsigned char SD_FAT32_KLASOR_YENIDEN_ADLANDIR(unsigned char KLASOR_ADI[8])

Purpose :Renames the selected folder.

Parameter :

Usage :

SD_FAT32_KLASOR_YENIDEN_ADLANDIR("ERCAN9 ");

Feedback :

SD_FAT32_KOK_DIZINE_GIT Function

Function : void SD_FAT32_KOK_DIZINE_GIT()

Purpose :Root (root) goes to the directory. The operations to be performed are then performed in the root directory.

Parameter : no

Usage :

SD_FAT32_KOK_DIZINE_GIT();

Feedback :

SD_FAT32_BIR_DIZIN_YUKARI_GIT Function

Function : void SD_FAT32_BIR_DIZIN_YUKARI_GIT()

Purpose :It goes up one line.

Parameter : no

Usage :

SD_FAT32_BIR_DIZIN_YUKARI_GIT();

Feedback :

Application of Functions

1- Making SD Card Analysis

void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//it must be in the very beginning to run the SD card.

   if(SD_FAT32_INIT()==0)//analysis function
     {
       SAP1024_YAZI_YAZMA(1,1,"FORMAT ATILMALI");
     }
   else
     {
       SAP1024_YAZI_YAZMA(1,1,"FORMAT ATILMAMALI");
     }
 }
SD card analysis – “Format Atılmamalı” result.
0th sector of the SD card and the status in the PC
void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   do{denetim=SD_MOD_SEKTOR_SIL(0,0);}while(denetim==0);// 0th sector is deleted.
   
   SAP1024_YAZI_YAZMA(1,1,"bitti");
}
void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   if(SD_FAT32_INIT()==0)//analysis function
     {
       SAP1024_YAZI_YAZMA(1,1,"FORMAT ATILMALI");
     }
   else
     {
       SAP1024_YAZI_YAZMA(1,1,"FORMAT ATILMAMALI");
     }
 }
SD card analysis gave “format atılmalı” result
the 0th sector of the SD card and the status of the PC

2- Formatting SD Card in FAT32 Format

void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   SD_FAT32_INIT();// analysis function must be called
   do{denetim=SD_FAT32_FORMAT("DENEME 1   ");}while(denetim==0);//Formatting SD CARD 
   
   SAP1024_YAZI_YAZMA(1,1,"bitti");

}
After Formatting the situation of SD card and 0th sector of SD card in the PC
Examination of the root directory – The disk name is written in the root directory

NOTE: If you have problems with formatting, delete all sectors of the SD card (with the SD card sector erase function) and try again. In some cases residual data can lead to instability in the system.

3- File Operations

3A- File Creation

void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();//FAT32 analysis function must be called
  
   SD_FAT32_DOSYA_OLUSTUR("ERCAN4  TXT");//file creation function

   SAP1024_YAZI_YAZMA(1,2,"bitti");//added to let you know that the process is over
}
The file was created in the SD card.
In FAT32 system, records of files are kept in root directory.
void  main()
{
   unsigned char denetim=120;
   ADCON1=7;
   CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();//fat32 main function

   SD_FAT32_DOSYA_OLUSTUR("ERCAN4  TXT");//ercan4.txt created
   SD_FAT32_DOSYA_OLUSTUR("ERCAN4  TXT");//ercan4.txt created

   SAP1024_YAZI_YAZMA(1,2,"bitti");//Notified via GLCD that process is finished.
}
wanted to create a file with two identical names.

 

3B- Selecting and Deleting Files

void  main()
{
    unsigned char denetim=120;
    unsigned char txt[11];
    int ercan;
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code



   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();//main function
  
   SD_FAT32_DOSYA_OLUSTUR("ERCAN5  TXT");//another file has been created
   
   SD_FAT32_DOSYA_SEC("ERCAN4  TXT");//previously created file has been selected

   SD_FAT32_DOSYA_KLASOR_SIL();//selected file has been deleted

   SAP1024_YAZI_YAZMA(1,2,"bitti");//added to show that the process is over on GLCD
   
}
Selecting and deleting FAT32 files

 

3C- Rename a file

void  main()
{
    unsigned char denetim=120;
    unsigned char txt[11];
    int ercan;
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();// fat32 ana fonksiyonu

   SD_FAT32_DOSYA_SEC("ERCAN5  TXT");//I selected the file I created earlier

   SD_FAT32_DOSYA_YENIDEN_ADLANDIR("ERCAN10 TXT");//I changed the file name to ERCAN10

   SAP1024_YAZI_YAZMA(1,2,"bitti");//informs that process is over on GLCD
}
The file has been renamed to ERCAN10.txt.

 

3D- Changing the Date and Time of a File

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();// fat32 ana fonksiyonu

   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");// Which file to process is selected.
   
   SD_FAT32_DOSYA_TARIH_SAAT_AYARLA(2019,11,6,12,00); // The date is set on November 6, 2019 at 12:00.

   SAP1024_YAZI_YAZMA(1,2,"bitti"); //reports that the process is over on GLCD
}
FAT32 – modification of file creation date
void  main()
{
    unsigned char denetim=120;

    ADCON1=7;
    CMCON=7;

   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card
   
   SD_FAT32_INIT();// fat32 main function

   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");// Which file to process is selected.
   
   SD_FAT32_DOSYA_DEGISIM_TARIH_SAAT_AYARLA(2019,11,20,12,00); // The date was set on November 20, 2019 at 12:00.

   SAP1024_YAZI_YAZMA(1,2,"bitti");//reports that the process is over on GLCD

}
FAT32 – Setting the date of file modification.

 

3E- Data Writing to the File and Data Positioning

void  main()
{
    unsigned char denetim=120;
   
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();
   
   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");
    
   SD_FAT32_DOSYA_BASINA_GIT();//The new file is called when data is being written and old files are overwritten.
   
   //NOT: SD_DATA_TAMPONU it must be called before the data write function. No other function should be inserted.
   SD_DATA_TAMPONU[0]=0x05;//5 değeri
   SD_DATA_TAMPONU[1]=0x0A;//10 değeri
   SD_DATA_TAMPONU[2]=0x0F;//15 değeri
   SD_DATA_TAMPONU[3]=0x14;//20 değeri

   SD_FAT32_DOSYA_VERI_YAZ(); // data writing function
   
   SAP1024_YAZI_YAZMA(1,2,"bitti");//reports that the process has been finished on GLCD
}
The data to be written to FAT32 must be converted to string
void  main()
{
    unsigned char denetim=120;
   
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();
   
   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");
    
   SD_FAT32_DOSYA_BASINA_GIT();//called when data is written to the new file and overwriting the old files
   
   //NOT: SD_DATA_TAMPONU it must be called before the data write function. No other function should be inserted.
   //NOT2 : 0D0A found at the end of the data corresponds to the enter key in FAT32. So if you write this at the end of the data, the next data will be written on the bottom line in the file.
   SD_DATA_TAMPONU[0]=0x350D0A;//5
   SD_DATA_TAMPONU[1]=0x31300D0A;//10
   SD_DATA_TAMPONU[2]=0x31350D0A;//15
   SD_DATA_TAMPONU[3]=0x32300D0A;//20

   SD_FAT32_DOSYA_VERI_YAZ(); // data writing function
   
   SAP1024_YAZI_YAZMA(1,2,"bitti");//reports that the process has finished on GLCD
}
Fat32 – the translated data is visible in the text file
//*************A STRING CONVERSION FUNCTION START******************// 
void string_cevir(unsigned long veri )
    {
      char txt[11];
      unsigned char i=0,x=0,y=0,z=0;
           
      LongWordToStr(veri,txt);
      SD_DATA_TAMPONU[x]=0;
      
      for(i=0;i<strlen(txt);i++)
        {
          if(txt[i]!=0 && txt[i]!=0x20)
            {
               SD_DATA_TAMPONU[x]=SD_DATA_TAMPONU[x]|(1L*(txt[i])<<(24-y));
               y=y+8;

               if(y==32)
                 {
                   x++;
                   y=0;
                   SD_DATA_TAMPONU[x]=0;
                 }
             z++;//It helps to keep the number of meaningful data in the sequence.
            }
        }
      
      // data integrity is provided here
      SD_DATA_TAMPONU[x]=SD_DATA_TAMPONU[x]|(0x20202020>>((z%4)*8));
        
     if(x!=127){SD_DATA_TAMPONU[x+1]=0;} //son diziyi sıfıra eşitler artık veri kalmasını engeller
    }
//*************END OF TRANSLATION TO STRING FUNCTION******************// 

void  main()
{
    unsigned char denetim=120;
    
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 ana fonksiyonu
  
   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");//the file has been selected
   
   SD_FAT32_DOSYA_BASINA_GIT();//the positioning was done by going to the top of the file.
   string_cevir(26587);// the string function above main is called and the value to be converted is written
   SD_FAT32_DOSYA_VERI_YAZ();//data was written.

   SAP1024_YAZI_YAZMA(1,2,"bitti");//informs that the process is over on GLCD
}
Fat32 – filled with 0x20 to provide data integrity

 

3F- Writing data by going to the end of the file.

unsigned char x=0;//global value
unsigned char string_cevir(unsigned long veri,unsigned char satir_atla )
    {
      char txt[11];
      unsigned char i=0,y=0,z=0;

      LongWordToStr(veri,txt);//mikroc standard library
      SD_DATA_TAMPONU[x]=0;//the initial sequence is equal to zero.
      
      for(i=0;i<11;i++)
        {
          if(txt[i]!=0 && txt[i]!=0x20)
            {
               SD_DATA_TAMPONU[x]=SD_DATA_TAMPONU[x]|(1L*(txt[i])<<(24-y));// 8 bitlik veriler kaydırılarak yerleştiriliyor
               y=y+8;

               if(y==32)
                 {
                   if(x!=127) // if the data buffer is not reached at the end
                     {
                       //the new sequence is equal to zero.
                       x++;
                       SD_DATA_TAMPONU[x]=0;
                     }
                   else
                    {
                      return 255 ;//The process has been terminated because the data row is full
                    }
                   y=0;//the data shift variable is reset.
                 }
             z++;// calculates how many meaningful data are.
            }
        }
      
      if(satir_atla==1)//line jump enter command
        {
          SD_DATA_TAMPONU[x]=SD_DATA_TAMPONU[x]|(0x20202020>>((z%4)*8));// data integration department
          x++;
          SD_DATA_TAMPONU[x]=0x0D0A;//inserts an enter code if line skip is selected

        }
      x++;//shifting new array
}

void  main()
{
    unsigned char denetim=120;
    
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();
 
   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");
 
   x=0;// the global array value is reset before each new upload
   
   SD_FAT32_DOSYA_SONUNA_GIT();//the last written to the end of the file is not corrupted. 26587 is printed.

   //**In this section, loading is done to sequence. It can be uploaded individually if desired.
   //** If it returns 255 from string_cevr, it means SD_DATA_TAMPONU is full.

   string_cevir(145658,1); // turn string got bottom
   string_cevir(1234,1); // turn string got bottom
   string_cevir(458,0);// turn string continue along
   string_cevir(125,1);// turn string got bottom

   SD_FAT32_DOSYA_VERI_YAZ();//data is written

   SAP1024_YAZI_YAZMA(1,2,"bitti");//informs that the process is over on GLCD
 }
Fat32 – Data positioning was added to the end of the old file. The underscore pass code (0x0D0A) was applied.

 

3G- Reading Data from a File

void  main()
{
    unsigned char denetim=120,i=0;
    unsigned long veri;
    char txt[11];
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code

  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();
  
   SD_FAT32_DOSYA_SEC("ERCAN10 TXT");//the file to be processed is selected
   
   SD_FAT32_DOSYA_BASINA_GIT();// go to the beginning of the file. this rule never changes

   SD_FAT32_DOSYA_VERI_OKU(0);//0th sector of the file is read.
  

   for(i=0;i<12;i++)//I did 12 because we used 12 series in previous issues.
      {
        LongWordToHex(SD_DATA_TAMPONU[i],txt);//The MikRec standard library converts values as hexadecimal.
        SAP1024_YAZI_YAZMA(1,(i+1),txt);//it will show every row as a series on GLCD
      }
}
The data stored in the SD card is read and displayed on the GLCD.

 

3H-Listing the Files in Directory

void  main()
{
    unsigned char denetim=120,i=0,x=0;
    unsigned long veri;
    char txt[11];
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code

  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
    
   for(i=0;i<45;i++)
     {
       if(SD_FAT32_DOSYA_LISTELEME(i)!=255)//listing file function
         {
           SAP1024_YAZI_YAZMA(1,(i+2-x),(YDosya_Bilgileri.dosya_adi));//name of file
           SAP1024_YAZI_YAZMA(15,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_tarih));//file creation date
           SAP1024_YAZI_YAZMA(26,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_zaman));//file creation time
           SAP1024_YAZI_YAZMA(31,(i+2-x),(YDosya_Bilgileri.dosya_boyutu));//file size
         }
      else
         {
           x++;
         }

     }
   SD_FAT_32_DOSYA_LISTELEME_SONLANDIR();//the listing is terminated.
}
The files in the root directory were listed and seen on the GLCD.
The files and folders are listed by the order in which they are located

 

4-Folder Operations

 

4A-Folder Creation

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
   
   SD_FAT32_KLASOR_OLUSTUR("ERCAN5  ");//create a folder named ERCAN5 in the root directory
    
   SAP1024_YAZI_YAZMA(1,1,"bitti");//informs that process is over on GLCD
}
Fat32 – Folder was created

 

4B- Folder Selection Processes

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//The ERCAN5 folder we created is selected. Thus, the files to be newly created will be stored in this folder.
   
   SD_FAT32_KLASOR_OLUSTUR("ERCAN50 ");//Creates a new folder named ERCAN50.
   SD_FAT32_DOSYA_OLUSTUR("ERCAN50 TXT");//Creates a new file named ERCAN50.txt.
  
   SAP1024_YAZI_YAZMA(1,1,"bitti");//it informs us via GLCD that the process is over.
}
With the folder selection, a new folder is created in the selected folder.
void  main()
{
    unsigned char denetim=120,i=0,x=0;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code

  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//The ERCAN5 folder has been selected.
      
   for(i=0;i<45;i++)   
     if(SD_FAT32_DOSYA_LISTELEME(i)!=255)//The contents of the ERCAN5 folder will be listed
       {
        SAP1024_YAZI_YAZMA(1,(i+2-x),(YDosya_Bilgileri.dosya_adi));
        SAP1024_YAZI_YAZMA(15,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_tarih));
        SAP1024_YAZI_YAZMA(26,(i+2-x),(YDosya_Bilgileri.dosya_olusturma_zaman));
        SAP1024_YAZI_YAZMA(31,(i+2-x),(YDosya_Bilgileri.dosya_boyutu));
       }
     else
       {
        x++;
       }
    }
   SD_FAT_32_DOSYA_LISTELEME_SONLANDIR();//list ending function
}
By selecting a folder, the contents of the selected folder are listed and displayed on the GLCD.
void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//the ERCAN5 folder in the root directory was selected first
   
   SD_FAT32_KLASOR_SEC("ERCAN50 ");//The ERCAN50 folder in the ERCAN5 folder is selected
   
   SD_FAT32_DOSYA_OLUSTUR("SON     TXT");//SON.txt was created in the ERCAN50 folder
  
   SAP1024_YAZI_YAZMA(1,1,"bitti");//informs that the process is over on GLCD
}
A new file was created at the bottom of the list by selecting the nested folders.

 

4C- Going Up a Directory

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code

   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//ERCAN5 folder was selected
   SD_FAT32_KLASOR_SEC("ERCAN50 ");//ERCAN50 folder was selected 
     
   SD_FAT32_BIR_DIZIN_YUKARI_GIT();//a directory was moved up and returned to the ERCAN5 folder.
   
   SD_FAT32_DOSYA_SEC("ERCAN50 TXT");//ERCAN50.txt was selected
   SD_FAT32_DOSYA_KLASOR_SIL();//ERCAN50.txt was deleted
    
   SAP1024_YAZI_YAZMA(1,1,"bitti");//informs that the process is over on GLCD
}
The files in the previous folder were processed by going up one level from the bottom directory.

4D- Return to Root Directory

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run code
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//ERCAN5 folder was selected
   SD_FAT32_KLASOR_SEC("ERCAN50 ");//ERCAN50 folder was selected
      
   SD_FAT32_KOK_DIZINE_GIT();//Directly back to the root directory.
   
   SD_FAT32_KLASOR_SEC("ERCAN5  ");//ERCAN5 folder was selected

   SD_FAT32_DOSYA_KLASOR_SIL();//The ERCAN5 folder in the root directory has been deleted.
 
   SAP1024_YAZI_YAZMA(1,1,"bitti");//informs that the process is over on GLCD
}
turned back to the root directory from the lowest directory immediately.

4E- Renaming the folder

void  main()
{
    unsigned char denetim=120;
    ADCON1=7;
    CMCON=7;
    
   SAP1024_INIT(240,128,6); // GLCD run
  
   do{denetim=SD_SDMOD_ANALIZ(4);}while(denetim==0);//It must be in the beginning to run the SD card

   SD_FAT32_INIT();//fat32 main function

   SD_FAT32_KLASOR_SEC("ERCAN500");// ERCAN500 folder was selected

   SD_FAT32_KLASOR_YENIDEN_ADLANDIR("SON     ");//ERCAN500 folder was renamed as SON
  
   SAP1024_YAZI_YAZMA(1,1,"bitti");//informs that the process is over on GLCD
}
the folder was renamed

RESULT


Library Files


Documents Taken

 

 


This post is also available in: Türkçe (Turkish)

Exit mobile version