⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.h

📁 avr+TFT+SD卡实现数码相框功能
💻 H
字号:
//*****************************************************************************
//
// File Name	: 'fat.h' 
// Title		: FAT32 File System
// Author		: Andy Zhu - Copyright (C) 2008.7
// Created		: 2008.07.20
// Revised		: 2008.07.20
// Version		: 0.1
// Target MCU	: Atmel AVR mega128
//
//*****************************************************************************
#ifndef __fat_h__
#define __fat_h__

#define ATTR_READ_ONLY	0x01
#define ATTR_HIDDEN		0x02
#define ATTR_SYSTEM		0x04
#define ATTR_VOLUME_ID 	0x08
#define ATTR_DIRECTORY	0x10
#define ATTR_ARCHIVE 	0x20

typedef struct BPB_STRUCT		//BIOS Parameter Block(53个字节)
{
	unsigned int BPB_BytesPerSec;	//每扇区字节数,offset 0x0B,一般512字节
	unsigned char BPB_SecPerClus;	//每簇扇区数,offset 0x0D
	unsigned int BPB_ResSec;	//保留扇区数,offset 0x0E
	unsigned char BPB_NumOfFAT;		//该分区上FAT的副本数,offset 0x10
	//unsigned int RootEntries;	//只有FAT12/FAT16 使用此字段。
								//对FAT32分区而言,本字段必须设置为0。offset 0x11
	//unsigned int SmallSector;	//小扇区数(Small Sector)(只有FAT12/FAT16 使用此字段)
								//对 FAT32分区而言,本字段必须设置为0。offset 0x13
	//unsigned char MediaDescriptor;//媒体描述符,0xF8表示硬盘,0xF0表示高密度的3.5寸软盘,offset 0x15
	//unsigned int SectorsPerFAT; 	//每FAT扇区数.只被 FAT12/FAT16 所使
									//用,对 FAT32分区而言,本字段必须设置为0。offset 0x16
	unsigned int BPB_SecPerTra;	//每道扇区数,offset 0x18
	unsigned int BPB_NumOfHead;		//磁头数,offset 0x1A
	unsigned long int BPB_HidSec;	//隐藏扇区数,offset 0x1C
	unsigned long int BPB_LarSec;	//FAT32分区中总的扇区数,offset 0x20
	unsigned long int BPB_SecPerFAT;//每FAT扇区数(只被FAT32使用)该分区每个FAT所占的扇区数。offset 0x24
	unsigned int BPB_ExtendedFlag;		//扩展标志(Extended Flag)(只被FAT32使用),offset 0x28
	unsigned char BPB_FileSystemVersion[2];	//文件系统版本,只供FAT32使用,高字节是主要的修订
										//号,而低字节是次要的修订号。offset 0x2A
	unsigned long int BPB_RootClusNum;//根目录簇号,(只供FAT32使用) 根目录第一簇的簇号。offset 0x2C
	unsigned int BPB_FileSysInforSecNum;	//文件系统信息扇区号,(只供FAT32 使用) FAT32分区的保留区中的
										//文件系统信息(File System Information, FSINFO)结构的扇区号。
										//offset 0x30
	unsigned int BPB_BackupBootSector;		//备份引导扇区(只供FAT32使用)为一个非零值,这个非零值表示该分区保存引导扇区的
										//副本的保留区中的扇区号。offset 0x32
}BPB_STR;

typedef struct EX_BPB_STRUCT	//扩展BPB区
{
	unsigned char PhysicalDriveNumber;	//物理驱动器号,offset 0x40
	unsigned char ExtendedBootSignature;//扩展引导标签,必须要0x28或0x29,offset 0x42
	unsigned long int VolumeSerialNumber;//分区序号,在格式化磁盘时所产生的一个随机序号,offset 0x43
	unsigned char VolumeLabel[11];		//卷标,"NO NAME",offset 0x47
	unsigned char SystemID[8];			//系统ID, FAT32文件系统中一般取为"FAT32",offset 0x52
}EX_BPB_STR;

typedef struct DBR_STRUCT
{
	unsigned char JMP_INSTURCTION[3];	//跳转指令
	unsigned char OEM_ID[8];			//厂商标志和OS版本号
	BPB_STR BPB_infor;			//BIOS Parameter Block(53个字节)
}DBR_STR;

typedef struct	//短文件的32字节
{ 
  	//char DIR_Name[8];  					//文件名 				offset:0x00
  	//char DIR_ExtName[3];  				//扩展名 				offset:0x08
	unsigned char DIR_FullName[11];				//文件全名(包括扩展名)
  	unsigned char DIR_Attr;				//文件属性 				offset:0x0B 典型值:存档(0x20)、卷标(0x08)。
	unsigned char DIR_NTRes;			//系统保留 				offset:0x0c
	unsigned char DIR_CrtTimeTenth;		//创建时间的10毫秒位 	offset:0x0d
	unsigned int DIR_CrtTime;			//文件创建时间			offset:0x0e
	unsigned int DIR_CrtDate;			//文件创建日期			offset:0x10
	unsigned int DIR_LstAccDate;		//文件最后访问日期		offset:0x12
	//unsigned int DIR_FstClusHI;			//文件起始簇号的高16位 	offset:0x14
	unsigned int DIR_WrtTime;			//文件的最近修改时间	offset:0x16
	unsigned int DIR_WrtDate;			//文件的最近修改日期	offset:0x18
	//unsigned int DIR_FstClusLO;			//文件起始簇号的低16 位	offset:0x1A
	unsigned long int DIR_FileSize;		//文件的长度			offset:0x1C
	unsigned long int DIR_FstClus;		//文件起始簇号			
}DIR_SHORT_STR;

uint32_t 	FirstSecNum;			//逻辑扇区0
uint32_t 	FirstRootDirSecNum;	//根目录决定扇区数
BPB_STR 	FAT32_BPB_infor;
DIR_SHORT_STR		FAT32_DIR_infor;
//-------------------------------------------------------------------
unsigned long int Look_for_DBR(void);
void GetFileInfor(unsigned char *DIR_BUF,DIR_SHORT_STR *pDIR);
void Get_FAT_BPB_Infor(void);
unsigned long int Calculate_FirstRootDirSecNum(void);
unsigned long int FAT_Get_File_FirCluNum(char *pFileDir);
unsigned char FileNameMatch(char *TagName,char *FileName);
//-------------------------------------------------------------------
#endif //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -