📄 fat16.lst
字号:
C51 COMPILER V8.01 FAT16 05/10/2006 10:39:04 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE FAT16
OBJECT MODULE PLACED IN Fat16.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Fat16.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "hardware.h"
2
3 UCHAR xdata Page_Buf[512];
4
5 #define Root_Cluster (0) //MBR所在的簇号
6 #define Data_Cluster (1) //数据真正开始的扇区
7
8 #define BPB_Sector (0)
9 #define Hid_Sector (68)
10 #define Fat_Sector (BPB_Sector+Hid_Sector)
11 #define Fat_Size (254)
12
13 #define UNUSED_MARK (0xFF)
14 #define BAD_MARK (0x00)
15 #define LAST_BLOCK (0xFFFF)
16 #define FILE_NO_FOUND (512)
17 //#define BLOCK_SIZE (32*512)
18
19
20 code unsigned char BPB_Data[512] = {
21 0xeb, 0x3c, 0x90,// Offset_U8_BS_jmpBoot 0
22 'g', 'u', 'o', 'b', 'i', 'n', 'u', 'p',// Offset_U8_BS_OEMName 3
23 0x00, 0x02,// Offset_short int_BPB_BytsPerSec 11 //Count of bytes per sector. This value may take on on
-ly the //
24 //512 //following values: 512, 1024, 2048 or 4096. If maximum //
25 //compatibility is desired, only the value 512 should be used.//
26 1,// Offset_U8_BPB_SecPerClus 13 //Number of sectors per allocation unit. This value must be a //
27 //power of 2 that is greater than 0. The legal values are 1, //
28 // 2, 4, 8, 16, 32, 64,and 128. //
29 68, 0x00,// Offset_short int_BPB_RsvdSecCnt 14 //Number of reserved sectors in the Reserved region of t
-he //
30 //volume starting at the first sector of the volume.For FAT32 //
31 //volumes, this value is typically 32. //
32 0x02,// Offset_U8_BPB_NumFATs 16 //The count of FAT data structures on the volume. //
33 0x00, 0x02,// Offset_short int_BPB_RootEntCnt 17 //Is only useful for FAT12 and FAT16 volumes.
- //
34 // //For FAT32 volumes,this field must be set to 0. //
35 //通过调整文件项为03b0,从而使数据扇区刚好从Block2Sector0开始,但
36 //文件分区表中根目录区并为标记为已占用。数据实际从Block4Sector0开始
37 0xe0, 0xff,// Offset_short int_BPB_TotSec16 19 //For FAT12 and FAT16 volumes, this field contains the
-sector //
38 //count, and BPB_TotSec32 is 0 if the total sector count fits //
39 //(is less than 0x10000). //
40 0xf0,// Offset_U8_BPB_Media 21 //0xF8 is the standard value for fixed(non-removable) media. //
41 //For removable media, 0xF0 is frequently used. //
42 0xfe, 0x00,// Offset_short int_BPB_FATSz16 22 //This field is FAT12/FAT16 16bit count of sectors occup
-ied by//
43 // 1 FAT.On FAT32 volumes this field must be 0, and BPB_FATSz32//
44 //contains the FAT size count. //
45 0x3f, 0x00,// Offset_short int_BPB_SecPerTrk 24 //Sectors per track for interrupt 0x13. This field is o
-nly //
46 //relevant for media that have a geometry (volume is broken //
47 //down into tracks by multiple heads and cylinders) and are //
48 //visible on interrupt 0x13.This field contains the //
49 //"sectors per track" geometry value. //
C51 COMPILER V8.01 FAT16 05/10/2006 10:39:04 PAGE 2
50 0xff, 0x00,// Offset_short int_BPB_NumHeads 26 //Number of heads for interrupt 0x13. This field is rel
-evant //
51 //as discussed earlier for BPB_SecPerTrk. //
52 0, 0x00, 0x00, 0x00,// Offset_U32_BPB_HiddSec 28 //Count of hidden sectors preceding the partition tha
-t //
53 //contains this FAT volume. //
54 0x00, 0x00, 0x00, 0x00,// Offset_U32_BPB_TotSec32 32 //This field is the new 32-bit total count of sec
-tors on the //
55 //volume. This count includes the count of all sectors in all //
56 //four regions of the volume. This field can be 0; if it is 0,//
57 //then BPB_TotSec16 must be non-zero. For FAT32 volumes, this //
58 //field must be non-zero. For FAT12/FAT16 volumes, this field //
59 //contains the sector count if BPB_TotSec16 is 0 (count is //
60 //greater than or equal to 0x10000).//
61 0x00,// Offset_U8_BS_DrvNum 36 //This field is the FAT32 32-bit count of sectors occupied by //
62 //根据该值得到FAT的大小// //ONE FAT. BPB_FATSz16 must be 0. //
63
64 0x00,// Offset_U8_BS_Reserved 37 // Bits 0-3 -- Zero-based number of active FAT.Only valid //
65 // if mirroring is disabled. //
66 // Bits 4-6 -- Reserved. //
67 // Bit 7 -- 0 means the FAT is mirrored at runtime into //
68 // all FATs. //
69 // -- 1 means only one FAT is active;it is the one//
70 // referenced in bits 0-3. //
71 // Bits 8-15 -- Reserved. //
72 0x29,// Offset_U8_BS_BootSig 38 //High byte is major revision number. //
73 //Low byte is minor revision number. //
74 'N', 'A', 'M', 'E',// Offset_U32_BS_VolID 39 //This is set to the cluster number of the first cluster
-of //
75 //根据该值得到ROOT的地址// //the root directory, usually 2 but not required to be 2. //
76
77 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',// Offset_U2048_BS_VolLab 43 //Sector number of
-FSINFO structure in the reserved area of //
78 //the FAT32 volume.Usually 1. //
79 'F', 'A', 'T', '1', '6', ' ', ' ', ' ',// Offset_U256_BS_FilSysType 54 //If non-zero, indicates the sec
-tor number in the reserved //
80 //area of the volume of a copy of the boot record. //
81 //Executable Code
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
87
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93
94 0x00,//active partion
95 0x00,//head
96 0x00,//partion begin
C51 COMPILER V8.01 FAT16 05/10/2006 10:39:04 PAGE 3
97 0x00,//cylinder
98 0x00,//0x06,//is partion used
99 0x00,//end head
100 0x00,//partion end
101 0x00,//end cylinder
102 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00,//fist partion0x80
104
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,//second partion
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,//third partion
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,//forth partion
108
109 0x55, 0xAA // Offset_short int_Signature 510 //0x55AA
110
111 };
112
113 unsigned char Flash_Reset(void)
114 {
115 1 unsigned int i;
116 1
117 1 Flash_EN();
118 1 Flash_Com();
119 1 Flash_Write(0xFF);
120 1 Flash_WaitBusy();
121 1
122 1 Flash_Com();
123 1 Flash_Write(0x90);
124 1 Flash_Add();
125 1 Flash_Write(0x00);
126 1 Flash_Dat();
127 1 P2=0xFF;
128 1 Flash_Read(((UCHAR*)&i)[0]);
129 1 Flash_Read(((UCHAR*)&i)[1]);
130 1 Flash_DIS();
131 1
132 1 if(i==0xAD75)
133 1 return 1;
134 1 else
135 1 return 0;
136 1 }
137
138
139 /********************************************************/
140 /*功能:擦除FLASH的1Block(对应文件系统为1Cluster) */
141 /* 每一个簇为16KB,因此KM29U128共有1024个簇 */
142 /*输入:unsigned int cluster/block(需要擦除的Block Number)*/
143 /*返回:OK或FAIL */
144 /********************************************************/
145
146 unsigned char Erase_Block(unsigned int Block)
147 {
148 1 unsigned int blockPage = (Block << 5);
149 1 UCHAR i;
150 1
151 1 Flash_EN();
152 1 Flash_Com();
153 1 Flash_Write(0x60);
154 1 Flash_Add();
155 1 Flash_Write(((UCHAR*)&blockPage)[1]);
156 1 Flash_Write(((UCHAR*)&blockPage)[0]);
157 1 Flash_Com();
158 1 Flash_Write(0xD0);
C51 COMPILER V8.01 FAT16 05/10/2006 10:39:04 PAGE 4
159 1
160 1 Flash_Dat();
161 1 Flash_WaitBusy();
162 1
163 1 Flash_Com();
164 1 Flash_Write(0x70);
165 1 Flash_Dat();
166 1 P2=0xFF;
167 1 Flash_Read(i);
168 1 Flash_DIS();
169 1 if(i&0x01)
170 1 return 0;
171 1 else
172 1 return 1;
173 1 }
174
175 /*****************************************************************/
176 /*功能:读取FLASH的某个Block中的1page数据 */
177 /* 在文件系统中,有如下对应关系:Block=Cluster */
178 /* Page =Sector */
179 /*输入:unsigned int block,page,unsigned char *pPage(存放数据的地址)*/
180 /*****************************************************************/
181
182 void ReadPage(unsigned int block, unsigned int page, unsigned char *pPage)
183 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -