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

📄 mp3player.c

📁 diy硬盘mp3的程序
💻 C
字号:
#include <iom128v.h>
#include "fat.h"
#include "ata.h"
#include "vs1001.h"
#include "remote.h"
#include "main.h"
#include "generic.h"
#include "usb.h"
#include <string.h>
#include <stdio.h>
#include <macros.h>

//******************************************************************
//*	MAIN Global Variable
//******************************************************************
unsigned char SectorBuffer[512];
unsigned char RemoteTextLine[5][40];
volatile unsigned char Key = 0;
volatile unsigned char IsPlaying = FALSE;

//*************************************
// void main(void)
//*************************************
void main(void)
{
InitRemote();
InitUSB();
WDR();
WDTCR = 0x0f; // Watch Dog enable
VS1001Init(HARD);
init_ata(0);
Reg_Test();
InitFat();
VS1001_SetVolume(50,50);
Sine_Sweep();
SEI();

DirBrowser(2);
}

//*************************************
// void DirBrowser(unsigned long Cluster)
//*************************************
void DirBrowser(unsigned long Cluster)
{
extern unsigned char text[255];
extern struct FileInfo File;
unsigned long LastCluster;
unsigned char ch;
unsigned int MaxFile;
int FilePtr = 0;
int Page = 0;

Key = 0xff;
FilePtr = 0;
Page = 99;
MaxFile = GetDir(Cluster,FilePtr,999,FALSE);

while(1)
		{
		while (Key == 0) 
			  {
			  WDR();
			  _StackCheck();
			  IsPlaying = FALSE;
			  }
		
		IsPlaying = TRUE;
		// Down
	
		if ((Key == 0x01) || (Key == 0x81) || (Key == 0xff))
		   {
		   if (Key == 0x01) FilePtr++;
           if (Key == 0x81) FilePtr += SONGPAGE;
		   if (FilePtr >= MaxFile) FilePtr--;
		   if ((FilePtr / SONGPAGE) != Page)
                {
				Page = FilePtr / SONGPAGE;
                GetDir(Cluster,Page*SONGPAGE,SONGPAGE,TRUE); 
				RemoteSendScreen(DIR,(FilePtr%SONGPAGE));
				}
		   else
                {
				RemoteSendLine((FilePtr%SONGPAGE));
                }
			Key = 0;
			}
				
		// Up
		
		if ((Key == 0x02) || (Key == 0x82))
		   {
		   if (Key == 0x02) FilePtr--;
           if (Key == 0x82) FilePtr -= SONGPAGE;
		   if (FilePtr < 0) FilePtr = 0;
		   if ((FilePtr / SONGPAGE) != Page)
                {
				Page = FilePtr / SONGPAGE;
                GetDir(Cluster,Page*SONGPAGE,SONGPAGE,TRUE); 
				RemoteSendScreen(DIR,(FilePtr%SONGPAGE));
				}
		   else
                {
				RemoteSendLine((FilePtr%SONGPAGE));
                }	
			Key = 0;
			}	
			
		// Left		
	
		if (Key == 0x04) 
		   {
		   Cluster = 2;	 // Root Dir
		   
		   Key = 0xff;
		   FilePtr = 0;
		   Page = 99;
		   MaxFile = GetDir(Cluster,FilePtr,999,FALSE);
		   }				
			
		// Right		

		if (Key == 0x08) 
		   {
		   GetDir(Cluster,FilePtr,1,FALSE);
	   
		   if ((File.Attr & ATTR_DIRECTORY) == ATTR_DIRECTORY)
		   	  {
			  Key = 0xff;
		   	  FilePtr = 0;
		   	  Page = 99;
			  Cluster = File.FirstClust;
		   	  MaxFile = GetDir(Cluster,FilePtr,999,FALSE);
			  }
		   else 
		   	  {
		   	  Page = 99;
		   	  FilePtr--;
		   	   	while(1)
		   	   		{
			   		Key = 0;
			   		FilePtr++;
		   	   		if (FilePtr >= MaxFile) FilePtr--;
		   	   		if ((FilePtr / SONGPAGE) != Page)
		   	   	  	   {
			  	  	   Page = FilePtr / SONGPAGE;
			  	  	   GetDir(Cluster,Page*SONGPAGE,SONGPAGE,TRUE); 
				  	   RemoteSendScreen(PLAY,(FilePtr%SONGPAGE));
			  	  	   }
			   		RemoteSendLine((FilePtr%SONGPAGE));
			   		GetDir(Cluster,FilePtr,1,FALSE); 
			   		PlayMP3();
			   		if (Key == 0x01) FilePtr = FilePtr;
			   		if (Key == 0x02) FilePtr -=2;
			   		if (Key == 0x04) break;
			   		if (Key == 0x08) break;
			   		}
		      GetDir(Cluster,Page*SONGPAGE,SONGPAGE,TRUE); 
		   	  RemoteSendScreen(DIR,(FilePtr%SONGPAGE));
		   	  Key = 0;
			  }
		   }	
		}
}

//*************************************
// void _StackOverflowed(char c)
//*************************************
void _StackOverflowed(char c)
	{
	CLI();
	while(1);
	}

//*************************************
// int PlayMP3(void)
//
// return 0 -> Error
// return 1 -> successfull play
//*************************************
int PlayMP3(void)
{
extern unsigned char SectorBuffer[512];
unsigned long LBA,i,j,NextCluster,TimeOut,ByteSend,Percent;
extern struct FileInfo File;
extern struct BootRecord Boot;

VS1001Init(SOFT);
Key = 0;
ByteSend = 0;
NextCluster = File.FirstClust;
while (1)
 	  {
	  LBA = Clust2LBA(NextCluster);
	  for (i=0;i<Boot.SecPerClust;i++)
	  	  {
		  ata_read_sector_byte(0, LBA+i, 0, 512, (unsigned char*)&SectorBuffer);
		  for (j=0;j<Boot.BytesPerSec;j=j+32)
			  {
			  TimeOut = 0;
			  while (!(PORT_MP3_IN & DREQ))
			  		{
					WDR();
					if (Key != 0) return Key;
					TimeOut++;
					if (TimeOut > 100000) 
					   {
					   VS1001Init(HARD); // VS1001 is jam
					   return 0x01; // Next Song
					   }
					}	
			  VS1001_Stream(&SectorBuffer[j],32);
			  }
		  }
	  ByteSend += (Boot.BytesPerSec * Boot.SecPerClust);
	  Percent = (ByteSend / (File.FileSize / 100));
	  NextCluster = GetNextCluster(NextCluster);
	  if (NextCluster > CLUST_RSRVD) break;
	  }
return 0x01; // Next Song
}

⌨️ 快捷键说明

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