Systematic Management of Data Files in AT24C512

Publisher:BlossomSunriseLatest update time:2015-04-13 Source: eechinaKeywords:AT24C512 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The file system program source code is as follows:
. Common subroutines:
RD24C: Read the contents of the AT24C512 cell pointed to by DPTR and put it into the RAM cell pointed to by (R1, R0). R6 is the data length.
WR24C: Write the contents of the RAM cell pointed to by (R1, R0) to the AT24C512 cell pointed to by DPTR, R6 is the data length
WR_ONE: Write the contents of the RAM unit pointed to by DPTR to the AT24C512 unit pointed to by DPTR
 
TZDPTR: MUL AB; DPTR=DPTR+A*B
ADD A, DPL
                     MOV DPL, A
                     MOV A, DPH
                     ADDC A, B
                     MOV DPH, A
                     RET
 
AT24C512 system formatting: Initialize the directory area and page allocation area to 0EEEEH
AT_INIT: MOV DPTR, #AT24C
MOV R7, #80H
              MOV A, #0EEH
ATINIT1:MOVX @DPTR, A
              INC DPTR
              DJNZ R7, ATINIT1
              MOV R7, #54
ATINIT2:MOV DPTR, #AT24C
              MOV R1, DPH
              MOV R0, DPL
              MOV R6, #80H
              MOV A, R7
              MOV B, #80H
              MOV DPTR, #0
              LCALL TZDPTR
              PUSH 7
              LCALL WR24C
              POP 7
              DJNZ R7, ATINIT2
              RET
 
For ease of operation, the contents of the directory area and the page allocation area are read into the same address of RAM each time the computer is turned on. The procedure is as follows:
R_HEAD:CLR IE.7
              MOV R5, #0
RHEAD1:MOV A, R5
              MOV B, #80H
              MOV DPTR, #0
              LCALL TZDPTR
              MOV R1, DPH
              MOV R0, DPL
              MOV R6, #80H
PUSH 5
              LCALL RD24C
              POP 5
              INC R5
              CJNE R5, #54, RHEAD1
              SETB IE.7
              RET
 
The procedure for adding files is as follows:
YB_SAVE: MOV PAGE_NO,#0 AGES=number of pages required
                     MOV DPTR, #AT_FAT AGE_NO is the number of free pages
YBSAVE1: MOVX A, @DPTR ; AT_FAT is the starting address of the page allocation table
                     CJNE A, #0EEH, YBSAVE2
                     INC PAGE_NO
YBSAVE2: INC DPTR
                     INC DPTR
                     MOV A, PAGE_NO
                     CLR C
                     SUBB A, PAGES
                     JZ YBSAVE4
                     MOV A, DPH
                     CJNE A, #1BH, YBSAVE1; 1B00H is the end address of the page allocation table
YBSAVE3: LCALL ERRDSP; Display error message
                     RET
 
YBSAVE4: MOV R7, #0
YBSAVE5: MOV DPTR, #YB_BEG; YB_BEG is the starting address of the directory area
                     MOV A, R7
                     MOV B, #10
                     LCALL TZDPTR
       MOVX A, @DPTR
              CJNE A, #0EEH, YBSAVE16
              SJMP YBSAVE6
YBSAVE16: INC R7
              CJNE R7, #153, ​​YBSAVE5; can store up to 153 files
              SJMP YBSAVE3 ; Already full
      
YBSAVE6: CLR IE.7
PUSH 7; save the sequence number of the free directory area found
LCALL DO_DSP ; Display "Storing"
       MOV DPTR, #AT_FAT
YBSAVE7: MOVX A, @DPTR
                     CJNE A, #0EEH, YBSAVE8
       SJMP YBSAVE9
YBSAVE8: INC DPTR
       INC DPTR
       SJMP YBSAVE7
YBSAVE9: PUSH DPH; find the first free page and protect the address
       PUSH DPL
       MOV R1, DPH
       MOV R0, DPL
       MOV A, #0FFH
       MOVX @DPTR, A
       INC DPTR
       MOVX @DPTR, A ; temporarily treat it as the last page of the file
       PUSH DPH
       PUSH DPL
       PUSH 0
       PUSH 1
       LCALL WR_ONE
       POP 1
       POP 0
       POP DPL
       POP DPH
       INC DPTR
      
                     MOV R7, PAGES
       DEC R7
       MOV A, R7
       JZ YBSAVE13; If only one page is needed, the page allocation table modification ends
YBSAVE10: MOVX A, @DPTR
       CJNE A, #0EEH, YBSAVE11
       PUSH DPH
       PUSH DPL
       MOV DPH, R1; R1, R0 is the page allocation table address of the previous page
       MOV DPL, R0
       POP 0
       POP 1
       MOV A, R1
       MOVX @DPTR, A
       INC DPTR
       MOV A, R0
       MOVX @DPTR, A ;Write the new address to the address unit of the previous page
       PUSH 0
       PUSH 1
       PUSH 7
       LCALL WR_ONE; write the modification information to AT24C512
       POP 7
       POP 1
       POP 0
       MOV DPH, R1
       MOV DPL, R0
       INC DPTR
       INC DPTR
       SJMP YBSAVE12
YBSAVE11: INC DPTR
       INC DPTR
YBSAVE12: DJNZ R7, YBSAVE10
       MOV DPH, R1
       MOV DPL, R0
       MOV A, #0FFH
       MOVX @DPTR, A
       INC DPTR
       MOVX @DPTR, A ; write 0FFFFH, indicating the end of file allocation
       LCALL WR_ONE
YBSAVE13: POP 0
                     POP 1
      
       POP 0
       POP 1; R1R0 = DPTR = the first free page found
POP ACC; ACC=R7=free directory area number
       PUSH ACC
MOV DPTR, #YB_BEG+8
       MOV B, #10
       LCALL TZDPTR ; Determine the address of the directory free area
       MOV A,R1
Keywords:AT24C512 Reference address:Systematic Management of Data Files in AT24C512

Previous article:NAND FLASH sector management
Next article:Using Flash-based MCUs to store user data

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号