About the Interface Design of MCU AT89S52 and CF Card

Publisher:落霞与孤鹜Latest update time:2013-03-15 Source: dzscKeywords:AT89S52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    The CF card is read and written through the 8051 microcontroller.

  2. How to operate the CF card

  The operation of CF card is similar to the operation of computer hard disk. There are two ways to address its sectors: physical addressing (CHS) and logical addressing (LBA). Physical addressing uses cylinder, head and sector number to represent a specific sector. The starting sector is track 0, head 0, zone 1, followed by zone 2, etc. Logical addressing addresses the entire CF card uniformly. The relationship between logical block addressing and physical addressing is:

  LBA address = (cylinder number × number of heads + head number) × number of sectors + number of sectors minus 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 limitation of CHS that cannot address large capacities.

  3. CF card file management

  The file management system of the CF card is the same as that of the hard disk. It divides the storage space of the CF card into five parts: master boot record sector (MBR), DOS boot area (DBR), file allocation table (FAT), file directory table (FDT) and data.

  Master Boot Record (MBR)

  The master boot record sector (MBR) is located at 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 mark 0x55AA. The disk characteristics are located at 0x01B8, specifying the disk operating system.

  DOS Boot Region (DBR)

  The starting sector of the DOS boot area (DBR) is at cylinder 0, head 1, sector 1. The logical sector 0 of the disk is called the DOS boot sector, also known as the BOOT area. It consists of the following 5 parts:

  Jump instruction, which takes up 3 bytes, will jump to the boot code, and its content varies 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 Parameter Block) occupies 19 bytes starting from the 12th byte.

  DOS boot program. The DOS boot program is a 480-byte BOOT code that is responsible for completing the three system files of DOS.

  This part varies with different DOS versions.

  End flag word, the end flag occupies 2 bytes and its value is AA55.

  The parameters recorded in the BPB table can help programmers determine the capacity of the disk, the location and size of the file allocation table FAT, and the location and size of the file directory table FDT. Therefore, the structure of the BPB table is discussed using the FAT32 partition format as an example.

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

  File Allocation Table (FATl)

  The file allocation table (FAT) is a table used by the file management system to allocate physical disk space to each file. It tells the operating system where the file is stored on the disk. The file allocation table (FAT) consists of a set of table identifiers and cluster mappings (formerly known as table entries). An identical mirror copy is stored continuously after the main FAT table. The table identifier includes the disk media descriptor (1 byte) and the padding byte, which occupies a total of two clusters of cluster mapping area (this is probably why the FAT file system cluster number starts with 2). The padding byte is generally FF. The padding byte of FAT32 also contains a "dirty bit", that is, a disk check (FAT-ChkDsk/NTFS-AutoChk) is performed when the system starts. In the FAT cluster map, 0000 indicates an empty cluster, FFFF indicates the end of the cluster chain, FFF7 indicates a bad cluster, and the remaining values ​​indicate the cluster number of its subsequent clusters. The storage strategy of FAT12 and FAT32 is similar to that of FAT16. For example, the end cluster of FAT12 is FFF, the bad cluster of FAT32 is 0FFFFFF7, etc. (Note that the upper 4 bits of FAT32 are reserved). The file allocation table (FAT2) is a complete backup of FAT1.

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

  3. Interface design between AT89S52 and CF card

  There are three working modes for CF cards: I/O mode, memory mode and IDE mode. The default mode of CF cards is memory mode, which is the most commonly used. If you use memory mode, you do not need to configure any registers. The circuit connection of each mode is different. In I/O mode and memory mode, you can use 8-bit access mode or 16-bit access mode. This article uses 8-bit memory mode, and its interface circuit schematic is shown in Figure 1.

  The P0 port of AT89S52 is the data line connected to DO-D7 of CF, A0-A10 of CF card is the address line, and P3.6 and P3.7 are 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', you can access data 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', the attribute register of the CF card is accessed; when REG is '1', the CF card reads and writes data in the memory mode. RDY/BSY is the status pin of the CF card. When it is "0", the CF card is busy, and when it is "1", the CF card can be operated. The schematic diagram is shown in the figure: [page]

  Due to limited space, only one sector writing code is written (the sector reading code is basically the same) as follows:

  ; Write a sector

  WRITE: MOV DPTR, #SECTR_CNT

  MOV A, #1

  MOVX @DPTR, A

  MOV DPTR, #SECTR_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 describes the reading and writing methods of CF card, and adopts the universal MCS-51 series single-chip microcomputer as the system controller, which has good portability. According to this circuit, it can be applied to other single-chip microcomputers to read and write CF cards. CF cards are used as storage media with large capacity, small size and low price. They can be applied to MP3 players, digital cameras, mobile storage and other fields. This experiment has been debugged on the circuit board, and the computer serial port can read and write CF cards, and data can be recovered from CF cards.

Keywords:AT89S52 Reference address:About the Interface Design of MCU AT89S52 and CF Card

Previous article:Application of single chip microcomputer measurement and control technology in the development of flat plate thermal conductivity meter
Next article:Design of wireless communication device based on 51 single chip microcomputer and nRF905

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号