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

📄 fat16.h

📁 用PIC24F128GA006做的CF与TFT液晶演示
💻 H
字号:
/******************************************************************************
 *
 *       PIC18 C18 Secure Digital and Multimedia Cards Interface
 *
 ******************************************************************************
 * FileName:        FAT16.h
 * Dependencies:    GenericTypeDefs.h
 *					_fat.def
 *					_FATDefs.h
 *					stddef.h
 * Processor:       PIC18
 * Compiler:        C18
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the 揅ompany? for its PICmicro?Microcontroller is intended and
 * supplied to you, the Company抯 customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN 揂S IS?CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
*****************************************************************************/

#ifndef  FAT16_DOT_H
#define  FAT16_DOT_H

#include "GenericTypeDefs.h"
#include "_fat.def"
#include "_FATDefs.h"
#include "stddef.h"

#define     NOFAT12SUPPORT

#ifdef USE_PIC18
	#include <p18cxxx.h>
#elif defined USE_PIC24
	#ifdef USE_PIC24F
		#include <p24fxxxx.h>
	#elif defined USE_PIC24H
		#include <p24hxxxx.h>
	#elif defined USE_PIC30
		#include <p30fxxxx.h>
	#elif defined USE_PIC33
		#include <p33fxxxx.h>
	#endif
#endif

#ifdef USE_PIC18
	#define NULL 0
#endif

#define FALSE	0
#define TRUE	1

#define FAIL    -1

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

#define APPEND "a"
#define WRITE "w"
#define READ "r"

#ifdef USE_PIC18
    typedef unsigned short long SWORD;
#else
	typedef struct
	{
		unsigned char array[3];
	} SWORD;	
#endif

typedef struct
{
    unsigned    write :1;           // set if the file was opened in a write mode 
	unsigned    FileWriteEOF :1;    // set if we are writing and have reached the EOF
}FileFlags;

#define FILE_NAME_SIZE	    11

typedef struct 
{
    DISK *      	dsk;            // disk structure
    WORD         	cluster;        // first cluster
    WORD         	ccls;           // current cluster in file
    WORD         	sec;            // sector in current cluster
    WORD         	pos;            // position in current sector
    DWORD         	seek;           // position in the file
    DWORD         	size;           // file size
    FileFlags   	Flags;
    WORD     		time;           // last update time
    WORD     		date;           // last update date
    char     		name[FILE_NAME_SIZE];       // Needed to make it WORD wide for external mem
    WORD     		entry;          // entry position in cur directory
    WORD     		chk;            // FILE structure checksum = ~( entry + name[0])
    WORD     		attributes;     // the bare bones attributes
    WORD     		dirclus;        // base cluster of directory
    WORD     		dirccls;        // current cluster
} FILE;


/***************************************************************************
* Prototypes                                                               *
***************************************************************************/

int FAT16Init(void);

FILE * fopen(const char * fileName, const char *mode);
//cmpt = ok, but need to implement static and dynamic file pointers

#ifdef USE_PIC18
	FILE * fopenpgm(const rom char * fileName, const rom char *mode);
	//cmpt = ok, but need to implement static and dynamic file pointers
	int removepgm (const rom char * fileName);
#else
	FILE * fopenpgm (const char * fileName, const char * mode);
	int removepgm (const char * fileName);
#endif


int fclose(FILE *fo);
//returns 0 on success. It returns EOF if any errors were detected.

int remove (const char * fileName);


void rewind (FILE *fo);

size_t fread(void *ptr, size_t size, size_t n, FILE *stream);
//On success fread returns the number of items (not bytes) actually read.
//On end-of-file or error it returns a short count or 0

size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
//On successful completion fwrite returns the number of items (not bytes) actually written.
//On error it returns a short count or 0.

int fseek(FILE *stream, long offset, int whence);
// return 0 if success. returns -1 on error

long ftell(FILE *fo);
// returns the current file pointer position on success.
// It returns -1L on error.

int feof( FILE * stream );

BYTE MediaInitialize(void);
BYTE SECTORread(DWORD sector_addr, BYTE* buffer);
#endif

⌨️ 快捷键说明

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