Interface circuit design between AT89S52 microcontroller and CF card

Publisher:DelightfulGazeLatest update time:2023-08-01 Source: elecfansKeywords:AT89S52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction
With the rapid development of computer application technology, mobile storage devices have been widely used. Among them, CF (Compact Flash) card is widely used in many mobile storage devices such as digital cameras, PDAs, notebook computers and other currently very popular consumer electronic products due to its advantages such as low price, small size, large storage capacity and high speed. . And CF cards are also widely used in other fields. The content described in this article is to read and write the CF card through the 8051 microcontroller.

2. How to operate the CF card
The operation of the CF card is similar to that of the computer's hard disk. There are two ways of addressing sectors: physical addressing (CHS) and logical addressing (LBA). Physical addressing uses columns. The surface, head and sector number represent a specific sector. The starting sector is track 0, head 0, area 1, followed by area 2, etc. Logical addressing uniformly addresses the entire CF card. The relationship between logical block addressing and physical addressing is: LBA address = (cylinder number × number of heads + number of heads) × number of sectors + number of sectors - 1

In actual use, using LBA addresses for addressing can greatly simplify the programming workload, avoid conversion and switching between cylinders, heads, and sectors, and break through the CHS's limitation of large-capacity inability to be addressed.


3. CF card file management
The CF card file management system is the same as the hard disk file management. It divides the CF card storage space into five parts: Master Boot Record Sector (MBR), DOS Boot Sector (DBR) , file allocation table (FAT), file directory table (FDT) and data.


Master Boot Record Sector (MBR)
The Master Boot Record Sector (MBR) is on cylinder 0, head 0, sector 1. The master boot record records the most important structural information of the disk. The master boot record is created when the hard disk is partitioned (Fdisk). The master boot record includes a small piece of execution code (master boot code), disk characteristics and hard disk partition table. The two bytes at the end of the master boot record must be the boot boot flag 0x55AA. The disk signature is located at 0x01B8, which specifies the disk operating system.


DOS boot sector (DBR)
The starting sector of the DOS boot sector (DBR) is cylinder 0, head 1, sector 1. The logical 0 sector of the disk is called the DOS boot sector, also known as the BOOT area. It consists of the following 5 parts:
    Jump instruction. The jump instruction occupying 3 bytes will jump to the boot code, and its content changes with the DOS version.
    Manufacturer identification and DOS version number. This part occupies a total of 8 bytes, and its content varies with the DOS version.
    BPB (BIOS Paramenter Block, BIOS parameter block). BPB occupies 19 bytes starting from the 12th byte.
    DOS bootloader. The DOS boot program is a BOOT code that occupies 480 bytes and is responsible for loading the three system files of DOS. The contents of this section vary with DOS versions.

End flag word, the end flag occupies 2 bytes, and its value is AA55.
The relevant parameters recorded in the BPB table can help programmers determine the disk capacity, the location and size of the file allocation table FAT, and the location and size of the file directory table FDT. Therefore, the FAT32 partition format is used as an example to discuss the structure of the BPB table.

The offset is 0BH, 0CH records the number of bytes in each sector, and 0DH records the number of sectors in each cluster. 0EH and OFH record the number of reserved sectors, 10H records the number of FAT tables, 15H disk media descriptors, 18H the number of sectors in each track, 24H the number of sectors in each FAT table, 2CH~2FH the starting number of the root directory.

File Allocation Table (FATl)
File Allocation Table FAT (File Allocation Tabel) is a table used by the file management system to allocate disk physical space to each file. It tells the operating system where the file is stored on the disk. A file allocation table (FAT) consists of a collection of table identifiers and cluster maps (formerly known as entries). An identical mirror copy is stored continuously behind the main FAT table. The table identifier includes the disk media descriptor (1 byte) and padding bytes, which occupies the cluster mapping area of ​​two clusters in total (this is probably why the cluster number of the FAT file system starts with 2). The padding bytes are generally FF. ,The padding bytes of FAT32 also contain "dirty bits", that is, a disk check (FAT-ChkDsk/NTFS-AutoChk) is performed when the system starts. In FAT cluster mapping, 0000 represents an empty cluster, FFFF represents the end of the cluster chain, FFF7 represents a bad cluster, and the remaining values ​​represent the cluster number of its subsequent cluster. The storage strategies of FAT12 and FAT32 are similar to FAT16. For example, the end cluster of FAT12 is FFF, the bad cluster of FAT32 is 0FFFFFF7, etc. (note that the high 4 bits of FAT32 are reserved). File Allocation Table (FAT2) is a full backup of FAT1.

File Directory Table (FDT) In the file directory table, each file occupies 32 bytes (occupies two lines when read with PC-TOOLS or DEBUB). The meaning of each byte is as follows: 0-7 bytes: File name; 8-10 bytes: extension; 11 bytes, indicating file attributes; 12-21 A total of 10 bytes are reserved fields, not used; 22-23 is the time when the file was created; 24-25 is the file creation time The date; 26-27 is the first cluster number occupied by the file, that is, the starting cluster; 28-31 is the length of the file with a total of 4 bytes.


3. Interface design between AT89S52 and CF card.
CF card has 3 working modes to choose from: I/0 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/0 mode and memory mode, 8-bit access mode can be used, or 16-bit access mode can be used. This article uses an 8-bit memory mode, and its interface circuit schematic is shown in Figure 1.

The P0 port of the AT89S52 is connected to the DO-D7 of the CF for the data line, the A0-A10 of the CF card are the address lines, and P3.6 and P3.7 are the read (RD) and write (WE) lines respectively. Since AT89S52 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--D7 of the CF card. And -CEl can be used as the chip select signal of the CF card. By setting -CEl to '0' to select the CF card, that is, -CEl is connected to P2.6 of AT89S52 to select the CF card. 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. RDY/BSY is the CF card status pin. When it is "0", the CF card is busy. When it is "1", the CF card can be operated. The schematic is shown in the figure:

Due to space limitations, only the code for writing one sector will be written (the code for reading a sector is basically the same) as follows:
;Write one sector
WRITE: MOV DPTR, #SETR_CNT
          MOV A, #1
          MOVX @DPTR, A
          MOV DPTR, #SETR_NO
          MOV A, SECTRNO
          MOVX @DPTR, A
          MOV DPTR, #CYLINDER_LOW
          MOV A, CYLINDERL
          MOVX @DPTR, A    
MOV DPTR, #CYLINDER_HI
          MOV A, CYLINDERH
          MOVX @DPTR, A
          MOV DPTR, #DRV_HEAD
          MOV A, DRVHEAD
          ANL A, #0FH
          ORL A, #0E0H
          MOVX @DPTR, A
          MOV DPTR, #COMMAND
          MOV A, 30H    
          MOVX @DPTR, A
WRITE512:MOV R6,#0  
          MOV R7,#2
WRITE: MOV DPTR,#DATA_REG
        MOV A,#31H
          MOVX @ DPTR,A
      DJNZ R6,WRITE
      DJNZ R7,WRITE
      RET


4. Conclusion
The interface circuit designed in this paper explains the reading and writing methods of CF card, and uses the general MCS-51 series microcontroller as the system controller, which has good portability. According to this circuit, it can be applied to other microcontrollers to read and write CF cards. CF cards are used as storage media. They have large capacity, small size and low price. They can be used in MP3 players, digital cameras, mobile storage and other fields. This test is in The circuit board has passed the debugging, and cooperates with the computer serial port to read and write the CF card, and can perform data recovery on the CF card.


Keywords:AT89S52 Reference address:Interface circuit design between AT89S52 microcontroller and CF card

Previous article:Design of AT89S8252 microcontroller to realize contact IC card reading and writing control
Next article:Based on 51 microcontroller driving A4988 to realize counterclockwise rotation of stepper motor

Recommended ReadingLatest update time:2024-11-23 04:36

System Hardware Design of Temperature Monitoring System Based on AT89S52 Single Chip Microcomputer
System Structure The whole system consists of an acquisition board, a communication board and a PC monitoring program. The acquisition board uses the temperature monitoring chip DS18B20t21, the single-chip microcomputer chip AT89S52 and the Bluetooth chip BC4 as the core to complete the functions of monitoring the hos
[Microcontroller]
AT89S52 controls hybrid stepper motor C program
#include     //Include the serial communication header file (which contains reg52.h) #include stdio.h     //Include printf header file #define uint unsigned int #define uchar unsigned char sbit cp  = P2^0;    //Pulse input terminal sbit dir = P2^1;    //Direction control terminal sbit free = P2^2;    //Offline c
[Microcontroller]
Design of dual closed-loop speed control system for three-phase asynchronous motor based on TMS320LF2407A and AT89S52
Abstract: Aiming at the speed regulation requirements of three-phase AC asynchronous motor in a certain equipment, a current and speed dual closed-loop speed regulation control system is designed with TMS320LF2407A and AT89S52 as the core and adopting the magnetic field oriented control strategy. The hardw
[Industrial Control]
Design of dual closed-loop speed control system for three-phase asynchronous motor based on TMS320LF2407A and AT89S52
AT89S52 parallel port drives LCD12864 (ST7920 chipset)
1.8-bit parallel port program  ;/////////////////////////////////////////////////// ;AT89S52 and LCD12864 interface experiment ;LCD12864 controller is ST7920 chipset ;Use 12846 to display Chinese characters ;RS-P2.4,R/W-P2.5,E-P2.6 ;/RET-P2.3,PSB-P2.1,P0-DB0~DB7 ;////////////////////////////////////
[Microcontroller]
AT89S52 parallel port drives LCD12864 (ST7920 chipset)
DTMF signal decoding using AT89S52 single chip microcomputer
introduction DTMF signals were first used in telephone dialing systems, and are also widely used in frequency-coded remote control systems and data coding transmission. Most of the current DTMF decoders use general-purpose integrated devices (single-tone decoding circuits and combinational gate circuits) or
[Microcontroller]
Design and production of wireless answering and scoring system based on AT89S52 single chip microcomputer
The wireless answer scoring system uses AT89S52/51 single-chip microcomputer as the control core, which can wirelessly transmit and receive answer signals, and has the functions of identifying advanced violation signals, countdown function, key verification, digital tube display, etc. Its main functions include: 1) It
[Microcontroller]
Design and production of wireless answering and scoring system based on AT89S52 single chip microcomputer
Latest Microcontroller Articles
Change More Related Popular Components
Guess you like

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号