Controlling CF card storage and design research using C8051F020 microcontroller

Publisher:温文儒雅Latest update time:2024-01-09 Source: elecfansKeywords:C8051F020 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

With the rapid development of computer application technology, mobile storage devices have been widely used. Among them, CF (Compact Flash) card was born in 1994. It is the earliest flash memory card launched and has the highest penetration rate among many products. Because CF cards have the characteristics of low price, small size, large storage capacity, and high speed, they are widely used in currently very popular consumer electronic products such as digital cameras, PDAs, and notebook computers. CF cards are also widely used in other fields. As described in this article, CF cards are used in dynamic EEG systems to store EEG signals.


Since the EEG signal stored in the CF card must be read from the PC, the EEG signal must be stored in the corresponding file format. The following will introduce the use of C8051F020 microcontroller to control CF card file storage, and introduce its software and hardware design in detail.


1 Interface circuit between C8051F020 and CF card

C8051F020 is a fully integrated mixed-signal system-level MCU chip. It uses Cygnal's patented high-speed, pipeline structure and the CIP-51 microprocessor core that is fully compatible with the MCS-51 instruction set. It has 64 digital I/O pins. There is 64KB of Flash memory that can be programmed in the system, 4 352B of on-chip RAM, and on-chip watchdog timers, VDD monitors and temperature sensors. The on-chip JTAG debugging circuit allows installation on the final application system. The product MCU performs non-intrusive, full-speed, in-system debugging; its MCU can operate with a voltage of 2.7" 3.6V within the industrial temperature range (-45℃-+85℃); port I/O, RST and JTAG pins are compatible with 5V input signal voltage.


CF card has three working modes to choose from: I/O mode, memory mode and IDE mode. The default mode of CF card is memory mode, which is also the most commonly used. If using memory mode there is no need to configure any registers. The circuit connections are different for each mode. In I/O mode and memory mode, 8-bit access mode or 16-bit access mode can be used. This article uses an 8-bit memory mode, and its interface circuit is shown in Figure 1.

Controlling CF card storage and design research using C8051F020 microcontroller

The C8051F020's external data memory interface (EMIF) can be used to access off-chip memory and memory-mapped I/O devices. If the PRTSEL bit of the EMIF configuration register EMIOCF is set to '1', the EMIF can be located at ports 7, 6, 5, and 4; if the EMD2 bit is set to '1', the EMIF can work in a non-multiplexed mode; set EMDl~0 Set to '01' to make EMIF work in fragmentation mode without block selection. In this way, the P7 port is the data line D0"D7, the P6 port is A0"A7, the P5 port is A8"A15, and P4.6 and P4.7 are the read (RD) and write (WE) lines respectively.

Since C8051F020 is an 8-bit microcontroller, it is more convenient to access the CF card in 8-bit mode. By setting -CE2 to '1', data can be accessed by accessing D0 and D7 of the CF card. And -CEl can be used as the chip select signal of the CF card, and the CF card can be strobed by setting -CEl to '0'. That is, -CEl is connected to the high-order address P5.7 of C8051F020 to select the CF card. When the CF card is inserted into its socket, both CDl and CD2 are connected to ground (CND); P1.1 and P1.2 of C8051F020 are connected to CDl and CD2, and can determine whether the CF card is inserted into the CF card socket by detecting P1.1 and P1.2. The CF card works in memory mode, -OE and -WE are connected to the read (P1.6) and write (P1) of C8051F020 respectively. .7) Line. When REG is '0', access the attribute register of the CF card; when REG is '1', the CF card reads and writes data in memory mode.

2 C8051F020 reads and writes data from CF card

Some register addresses related to data reading and writing in the memory mode of the CF card with the circuit shown in Figure 1 are shown in Table 1.

Controlling CF card storage and design research using C8051F020 microcontroller

One sector of the CF card is 512B. These data are read from the 0th register in Table 1, and the minimum read and write data is 1 sector each time, but it can also be set to read from the 2nd register. Out, read and write several sectors at a time.

The process of C8051F020 reading sector data from the CF card is: first read the status word of the 7th register. If it is 50H, it means there is no error and the CF card is ready; then it reads the status word of the 2nd, 3rd, 4th, 5th, and 5th registers respectively. Write corresponding data to the 6 registers to specify the sectors that need to be read and written; finally write 20H or 21H to the 7th register, read the data after the read status word is 58H, and the process is shown in Figure 2.

Controlling CF card storage and design research using C8051F020 microcontroller

The command for C8051F020 to write data to the designated sector on the CF card is 30H or 31H. The operation is similar to reading data, except that after writing the data, the process cannot be completed until the data in the CF card is stable and enters an idle state.

When reading and writing the CF card, the sector locations that the CF card needs to access are written to the 2nd, 3rd, 4th, 5th, and 6th registers respectively. There are two writing modes: CHS (Cylinder/Head/Sector) mode. and LBA (Logical Block Address) mode. Its mode is determined by setting the 6th bit LBA of the 6th register: that is, if LBA=0, it is CHS mode; if LBA=I, it is LBA mode.

The conversion from CHS mode to LBA mode is as follows:

Controlling CF card storage and design research using C8051F020 microcontroller

Where LBA is the logical block address, Cn is the cylinder number, HpC is the number of heads per cylinder, Hn is the number of heads, Sn is the sector number, and SpH is the number of sectors per head (cluster).

3 CF card file storage

The FAT (File Allocation Table) file system was produced from the late 1970s to the early 1980s and is a file system supported by Microsoft's MS-DOS operating system. There are currently three types of FAT file systems: FATl2, FATl6 and FAT32. The difference between them is the number of bits occupied by each record (Entry) in the actual FAT structure on the disk. FATl2 occupies 12 bits (1.5 bytes), FATl6 occupies 16 bits (2 bytes), and FAT32 occupies 32 bits (4 bytes). The data in each record is arranged in order of low byte first and high byte last.

When formatting a CF card, you must first understand a series of information such as the capacity of the CF card. By writing the command ECH to the CF card, you can read out one sector, which contains information about some parameters of the CF card, such as capacity, default number of cylinders, default number of heads, and bytes of each sector. number, the number of sectors per track and the total number of sectors on the CF card, etc. This provides important data for formatting the CF card.

In the formatted CF card, the FAT file system consists of the following four parts:

Area 0: Reserved area (boot area).

Zone 1: FAT zone.

Area 2: Root directory area (a floating FDT table exists in FAT32).

Area 3: File, directory and data area (hereinafter referred to as data area).

The boot area contains important information of the entire FAT file system, namely BPB (BIOS Parameter Block). The following are several important data structures of BPB:

Controlling CF card storage and design research using C8051F020 microcontroller

In FAT32 format, BPB﹒ RootEntCnt is '0', so RootDirSec is always '0'.

If BPB. If FATSzl6 is not '0', the first sector address of the data area can be calculated according to the following formula.

FirstDataSec="BPB". ResvdSecCnt+(BPB.NumFATs*BPB.FATSzl6)+RootDirSec (4)

Therefore, the number of sectors occupied by the data area:

DataSec="BPB". TotSecl6-FirstDataSec (5)

The first sector address of the root directory (under FATl2, FATl6):

FirstRootDirSec=”BPB”. ResvdSecCnt+(BPB.NumFATs*BPB.FATSzl6)

If BPB. FATSzl6 is '0', then BPB. FATSz32 must not be '0', then:

FirstDataSec="BPB". ResvdSecCnt+fBPB. NumFATs*BPB. FATSz32)+RootDirSec (6)

DataSec="BPB". TotSec32-FirstDataSec (7)

FirstRootDirSec=”BPB”. ResvdSecCnt+(BPB.NumFATs*BPB.FATSz32) (8)

If the CF card has multiple partitions, the parameters calculated by equations (3) to (8) are only relative to the current partition, and the number of clusters occupied by the data area is:

CntofClus="DataSec"/BPB. SecPerClus (9)

When formatting the CF card, some parameters in the FAT data structure are determined according to the size of the CF card capacity, and then the total number of clusters in the data area is calculated according to equation (9), and the FAT format is determined based on the size of the total number of clusters. Generally speaking, if CntofClus<4 084 clusters, it can be formatted in FAT12 form; if ≥4 084 clusters and <65 524 clusters, it can be formatted in FAT16 form; if ≥65 524 clusters, it can be formatted in FAT32 form. .

If a cluster number N is given (N≥2), the first sector number corresponding to the cluster in the data area is:

FirstSecofClus=((N-2)*BPB.SecPerClus)+FirstDataSec (10)

Equation (10) expresses the corresponding relationship between FAT and data area, as shown in Figure 3. The position of each record in the FAT area corresponds to a cluster of data in the data area. At the same time, this record stores the next cluster serial number, so that a file forms a linked list in the FAT area. As for the storage location of the serial number of each cluster in FAT, it can be determined according to the formatting form (FATl2, FAT16, FAT32). Assume that each record occupies i bytes, then the Nth record is at the position N×i.

Controlling CF card storage and design research using C8051F020 microcontroller

The end character of the file is 0xFFF under FATl2, 0xFFFF under FATl6, and 0x0FFFFFFF under FAT32. If a damaged cluster is encountered during writing, the damaged flag is written in the corresponding location (0xFF5 under FATl2, 0xFFF7 under FATl6, 0x0FFFFFF7 under FAT32), and the damaged cluster is skipped in the { table. When deleting a file, write all '0's in the linked list of the file in the FAT area to free up space. In this way, the corresponding data area in the linked list can be allocated by a new file. A FAT directory entry or file entry usually occupies 32 bytes and stores information related to the directory or file. Its data structure is as follows:

Controlling CF card storage and design research using C8051F020 microcontroller

Whether the 12-byte name in this data structure is a directory name or a file name is determined by the member Attr. If it is a directory, Attr can be set to 10H; if it is a j file, Attr can be set to 20H, or it can be a combination of several attributes; if it is a long file name, Attr can be set to OFH. Detailed long file names can be found in the literature.

[1] [2]
Keywords:C8051F020 Reference address:Controlling CF card storage and design research using C8051F020 microcontroller

Previous article:Application of Haisuxin 8051 microcontroller TM52F1376 in electronic voting machines
Next article:OLED display implementation design based on C8051F023 microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号