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

📄 enhanced.c

📁 基于avr单片机系统硬盘mp3设计
💻 C
字号:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//					    FAT32 File IO Library for AVR 
//								  V0.1c
// 	  							Rob Riglar
//							Copyright 2003,2004 
//
//   					  Email: rob@robriglar.com
//
//			    Compiled with Imagecraft C Compiler for the AVR series
//-----------------------------------------------------------------------------
//
// This file is part of FAT32 File IO Library.
//
// FAT32 File IO Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// FAT32 File IO Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FAT32 File IO Library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
void fopen_cluster(UI32 StartCluster);
byte fgetc(void);
byte feof(void);
void fscanf(char *args, char *string);
void ReadMP3_3(UI32 StartCluster);
void ReadPLS(void);

//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct {
word i;
UI32 clustortemp;
UI32 currentsectornumber;
word bytenum;
byte UsedBefore;
byte eof;
} MP3System;

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

byte fgetc(void)
{
 	   // Databyte declaration
	   byte datareturn;

	   // If first byte required then load the sector that contains it
	   if (MP3System.bytenum==0)
	   {
	   	      if (SectorReaderV2(MP3System.clustortemp, MP3System.currentsectornumber)) MP3System.eof = 1;
	   }

	   // Copy data from sector buffer
	   datareturn = currentsector[MP3System.bytenum];

	   // Increase pointer in current sector for next load
	   MP3System.bytenum++;

	   // If pointer reaches end of sector, reset and increase sector number
	   if (MP3System.bytenum==512) 
	   {
	   	  	   MP3System.bytenum=0;
			   MP3System.currentsectornumber++;
	   }

	   // Return Data
	   return datareturn;
}


void fopen_cluster(UI32 StartCluster)
{
 	 // Reset MPEG Stream Counters
 	 MP3System.currentsectornumber = 0;
	 MP3System.bytenum = 0;
	 MP3System.clustortemp = StartCluster;
	 MP3System.eof = 0;
	 
	 // Reset FAT Buffer
	 FATBufferV2.firstuse = 1;
	 FATBufferV2.firstsector = 1;
}

//-----------------------------------------------------------------------
// feof: Returns 1 when end of file
//-----------------------------------------------------------------------
byte feof(void)
{
 	 return (MP3System.eof);
}

// ----------------------------------------------------------------
// fscanf: Read a line from a file
// ----------------------------------------------------------------
void fscanf(char *args, char *string)
{
	byte datalast = 0;
	byte datacurrent= 0;
	int stringpntr=0;

	// -------------------------------------------------
	// Find a string
	// -------------------------------------------------
	if (args=="%s")
	{
		while (datacurrent!=0xFF)
			{
			datacurrent = fgetc();
			if ((datalast==0x0D) && (datacurrent==0x0A)) 
				{
				stringpntr--;
				//stringpntr--;
				break;
				}
			string[stringpntr++] = datacurrent;
			datalast = datacurrent;
			}
		string[stringpntr] = '\0';
	}
	// -------------------------------------------------
	// other find types go here
	// -------------------------------------------------
}

//-----------------------------------------------------------------------------
// ReadSector: Version 2
//-----------------------------------------------------------------------------
void ReadMP3_3(UI32 StartCluster)
{
byte data;
byte exist=0;

	fopen_cluster(StartCluster);
	
	
	do
	{
	if (DREQStatus) 
	   {
	   data = fgetc();
	   exist = 1;
	   }
	   while ((DREQStatus)) ControlCheck();

	   if (exist==0) data = fgetc();
	   MP3SendByte( data );
	   exist=0;
	}
	while ( !feof() );

}

void ReadPLS(void)
{
char string[100];
	char dirpath[100];
	char filename[50];
	UI32 startcluster;


	printf("PlaylistCluster opened 0x%x",fopen("C:\\NEWPLS.TXT"));
	printf("\r\n");	 
    do
	{
	fscanf("%s", string);
 
 	// Split full path into filename and directory path
	split_path(string, dirpath, filename);

	// Find last subdirs start cluster
	startcluster = recursive_dirfind(dirpath);

	// Using dir cluster address search for filename
	startcluster = MatchName(startcluster, filename);
	
	printf("%s",filename);
	printf(" |0x%lx|\r\n",startcluster);
	}
	while (string!=0);
}

⌨️ 快捷键说明

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