📄 fat16.lst
字号:
C51 COMPILER V7.50 FAT16 03/16/2006 09:11:14 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE FAT16
OBJECT MODULE PLACED IN fat16.OBJ
COMPILER INVOKED BY: C:\Program Files\keil\C51\BIN\C51.EXE fat16.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 * Copyright (c) 2004,北京博创兴业科技有限公司
3 * All rights reserved.
4 *
5 * 文件名称:fat16.c
6 * 文件标识:fat16
7 * 摘 要:fat操作的函数实现
8 *
9 * 当前版本:2.0
10 * 作 者:Kent
11 * 完成日期:2004年5月20日
12 *
13 * 取代版本:1.1
14 * 原作者 :Frank
15 * 完成日期:2003年8月10日
16 */
17 #include "Fat16.h"
18 #include "Flash.h"
19 #include "uart.h"
20 #include "string.h"
21
22 //数据结构与全局变量定义
23 extern unsigned char Page_Buf[];
24 extern unsigned char SONG[];
25
26 long int Current_Cluster, DataRead = 0, DataRemain = 0, Sector_Offset = 0x21d;
27
28
29 unsigned int TotalCluster, BootSector, RsdSector, SectorofFatSize, TotalCapacity, RootEntry, SecPerClus, T
-otalSector, BytesPerSec, FirstDataSec;
30 unsigned char FAT_TYPE;
31
32 void Init_FAT_Info(void)
33 {
34 1 //int i;
35 1
36 1 ///////////////////////////////////////////////////
37 1 //得到引导扇区所在扇区号,如果介质是不带分区的,则0扇区就是BootSector了。
38 1 ReadPage(Begin_Cluster, 0, Page_Buf);
39 1
40 1 if (!(Page_Buf[0] == 0xeb && Page_Buf[2] == 0x90))
41 1 { //通过判断EB ?? 90来看是否已经是BPB了
42 2 //带分区的介质
43 2 BootSector = Page_Buf[454] + Page_Buf[455] * 256 + Page_Buf[456] * (256 * 256) + Page_Buf[457] * (256 *
-256 * 256);
44 2 }
45 1 else
46 1 {
47 2 BootSector = 0;
48 2 }
49 1 ///////////////////////////////////////////////////
50 1
51 1 ////////////////////////////////////////////////
52 1 //得到保留扇区数,总扇区数,总扇区数/每簇扇区数得到簇数,是FAT类型的依据
53 1 ReadPage(Begin_Cluster, BootSector, Page_Buf);
C51 COMPILER V7.50 FAT16 03/16/2006 09:11:14 PAGE 2
54 1 RsdSector = Page_Buf[14] + Page_Buf[15] * 256;
55 1 SecPerClus = Page_Buf[13];
56 1
57 1 BytesPerSec = Page_Buf[12] * 256 + Page_Buf[11];
58 1
59 1 TotalSector = (Page_Buf[20] * 256 + Page_Buf[19]);
60 1 TotalCapacity = TotalSector * BytesPerSec;
61 1 TotalCluster = TotalSector / SecPerClus;//FAT16的簇总数=扇区总数/每簇扇区数
62 1
63 1 SectorofFatSize = ((Page_Buf[22] + Page_Buf[23] * 256));
64 1 RootEntry = (Page_Buf[18] * 256 + Page_Buf[17]);
65 1
66 1 FirstDataSec = BootSector + RsdSector + (SectorofFatSize * 2) + ((RootEntry * 32 + (BytesPerSec-1)) / Byt
-esPerSec);
67 1
68 1 if (TotalCluster > 65525)
69 1 { //FAT32的扇区总数和FAT表项长度
70 2 FAT_TYPE = FAT32;
71 2
72 2 if (TotalSector == 0)
73 2 {
74 3 TotalSector = (Page_Buf[32] + Page_Buf[33] * 256 + Page_Buf[34] * 256 * 256 + Page_Buf[35] * 256 * 256
-* 256);
75 3 }
76 2 TotalCapacity = TotalSector * BytesPerSec;
77 2 TotalCluster = TotalSector / SecPerClus;
78 2
79 2 SectorofFatSize = (Page_Buf[36] + Page_Buf[37] * 256 + Page_Buf[38] * 256 * 256 + Page_Buf[39] * 256 * 2
-56 * 256);
80 2 if (SectorofFatSize > (TotalCluster * 16 / 512))
81 2 {
82 3 SectorofFatSize = ((Page_Buf[22] + Page_Buf[23] * 256));
83 3 }
84 2 RootEntry = (Page_Buf[44] * 256 + Page_Buf[43]);
85 2 FirstDataSec = BootSector+RsdSector + (SectorofFatSize * 2) + ((RootEntry * 32 + (BytesPerSec-1)) / Byte
-sPerSec);
86 2
87 2 }
88 1 else if ((TotalCluster > 0) && (TotalCluster < 4085))
89 1 {//FAT12
90 2 FAT_TYPE = FAT12;
91 2 }
92 1 else
93 1 { //FAT16
94 2 FAT_TYPE = FAT16;
95 2 }
96 1 printuf("\nFAT : %x", SectorofFatSize >> 8);
97 1 printuf("%x\n", SectorofFatSize & 0xff);
98 1 printuf("\nDATA : %x", FirstDataSec >> 8);
99 1 printuf("%x\n", FirstDataSec & 0xff);
100 1 }
101
102 unsigned char GetMP3List(void)
103 {
104 1 unsigned char i = 0, j = 0, l = 0;
105 1 int k = 0;
106 1 unsigned char MP3[3] = {'M', 'P', '3'};
107 1 Init_FAT_Info();
108 1
109 1 k = BootSector + RsdSector + 2 * SectorofFatSize;
110 1 printuf("BootSector : %x", BootSector);
111 1 printuf("RsdSector : %x", RsdSector);
C51 COMPILER V7.50 FAT16 03/16/2006 09:11:14 PAGE 3
112 1 printuf("SectorofFatSize : %x", SectorofFatSize);
113 1
114 1 printuf("RootDIR : %x", (k & 0xff00) >> 8);
115 1 printuf("%x\n", k);
116 1
117 1 ReadPage(0 + k / 32, k % 32, Page_Buf);
118 1
119 1 while (Page_Buf[0] != 0)
120 1 {//遍历整个目录
121 2 for (j=0; j<16; j++)
122 2 {
123 3 if (!Page_Buf[j * 32]) break;
124 3 if (Page_Buf[j * 32] == 0xE5) continue;
125 3
126 3 if (!memcmp(MP3, &Page_Buf[j * 32 + 8], 3))
127 3 { //file find
128 4 for (i=0; i<11; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -