📄 新建 文本文档.txt
字号:
/* Copyright (C) 1996-2005 Brilliant Ideal Electronics. All rights reserved.
MP3_Player+USB_Disk V3.0 Edit by JMBIE STUDIO 2005.03
*/
//#include <string.h>
//#include "AT89C51SND1_REG.H"
#include "FILE_SYS.H"
//#include "MP3_PLAYER.H"
//#include "UDISK_DEF.H"
#include "..\inc\includes.h"
bool ReadRTC_PCF8563(void);
unsigned char xdata Sector_Buf[512]; //文件缓冲区。
long int idata Current_Cluster, DataRead = 0, DataRemain = 0, Sector_Offset = 0x21d;
unsigned int idata TotalCluster, BootSector, RsdSector, SectorofFatSize, TotalCapacity, RootEntry, SecPerClus;
unsigned int idata TotalSector, BytesPerSec, FirstDataSec;
unsigned char FAT_TYPE;
unsigned long idata CurrentSector;
uint uiOffsetInCluster; //每簇内扇区偏移量计数。
unsigned char xdata Song_Buff[220]; //Not more than 22
#define c_Key_Mode_SelectSong 0 //选择歌曲
#define c_Key_Mode_AdjustVol 1 //调整音量
#define c_Key_Mode_AdjustTone 2 //调整音调
uchar ucModeStatus; //记录按键处理状态机当前工作模式
uint8 SD_read_sector(uint32 addr,uint8 *Buffer);
#define ReadSector_SD(x,y) SD_read_sector(x,y)
void VS1003B_Fill2048Zero();
void ReadPage(unsigned int block, unsigned int page, unsigned char *pPage)
{
//SD_ReadBlock(block*32l+page, pPage);
SD_read_sector(block*32l+page, pPage);
}
//extern unsigned char Song_Buff_Buff[];
void Init_FAT_Info(void)
{
ReadPage(Begin_Cluster, 0, Sector_Buf);
if (!(Sector_Buf[0] == 0xeb && Sector_Buf[2] == 0x90))
{
BootSector = Sector_Buf[454] + Sector_Buf[455] * 256 + Sector_Buf[456] * (256 * 256) + Sector_Buf[457] * (256 * 256 * 256);
}
else
{
BootSector = 0;
}
ComShowString(c_COM1,"BootSector is:");
ComSendText(c_COM1,&BootSector,2);
ReadPage(Begin_Cluster, BootSector, Sector_Buf);
ComShowString(c_COM1,"DBR is:");
ComSendText(c_COM1,Sector_Buf,512);
RsdSector = Sector_Buf[14] + Sector_Buf[15] * 256; //保留扇区数
SecPerClus = Sector_Buf[13]; //每簇扇区数
ComShowString(c_COM1,"Sector per Cluster");
ComSendText(c_COM1,&SecPerClus,2);
BytesPerSec = Sector_Buf[12] * 256 + Sector_Buf[11]; //每扇区字节数
TotalSector = (Sector_Buf[20] * 256 + Sector_Buf[19]); //总的扇区数。
TotalCapacity = TotalSector * BytesPerSec;
TotalCluster = TotalSector / SecPerClus; //总簇数
SectorofFatSize = ((Sector_Buf[22] + Sector_Buf[23] * 256)); //Fat Size
RootEntry = (Sector_Buf[18] * 256 + Sector_Buf[17]); //根目录项数。
FirstDataSec = BootSector + RsdSector + (SectorofFatSize * 2) + ((RootEntry * 32 + (BytesPerSec-1)) / BytesPerSec);
ComShowString(c_COM1,"first Data Sec");
ComSendText(c_COM1,&FirstDataSec,2);
if (TotalCluster > 65525)
{
FAT_TYPE = FAT32;
if (TotalSector == 0)
{
TotalSector = (Sector_Buf[32] + Sector_Buf[33] * 256 + Sector_Buf[34] * 256 * 256 + Sector_Buf[35] * 256 * 256 * 256);
}
TotalCapacity = TotalSector * BytesPerSec;
TotalCluster = TotalSector / SecPerClus;
SectorofFatSize = (Sector_Buf[36] + Sector_Buf[37] * 256 + Sector_Buf[38] * 256 * 256 + Sector_Buf[39] * 256 * 256 * 256);
if (SectorofFatSize > (TotalCluster * 16 / 512))
{
SectorofFatSize = ((Sector_Buf[22] + Sector_Buf[23] * 256));
}
RootEntry = (Sector_Buf[44] * 256 + Sector_Buf[43]);
FirstDataSec = BootSector+RsdSector + (SectorofFatSize * 2) + ((RootEntry * 32 + (BytesPerSec-1)) / BytesPerSec);
ComShowString(c_COM1,"first Data Sec");
ComSendText(c_COM1,&FirstDataSec,4);
}
else if ((TotalCluster > 0) && (TotalCluster < 4085))
{
FAT_TYPE = FAT12;
}
else
{
FAT_TYPE = FAT16;
}
}
unsigned char GetMP3List(void)
{
unsigned char i = 0, j = 0, l = 0;
int k = 0;
unsigned char MP3[3] = {'M', 'P', '3'};
//unsigned char WMA[3] = {'W', 'M', 'A'};
unsigned char TXT[3] = {'T', 'X', 'T'};
unsigned char MID[3] = {'M', 'I', 'D'};
unsigned char WAV[3] = {'W', 'A', 'V'};
Init_FAT_Info();
k = BootSector + RsdSector + 2 * SectorofFatSize;
ReadPage(0 + k / 32, k % 32, Sector_Buf);
while (Sector_Buf[0] != 0)
{
for (j=0; j<16; j++)
{
if (!Sector_Buf[j * 32]) break;
if (Sector_Buf[j * 32] == 0xE5) continue;
if (!memcmp(MP3, &Sector_Buf[j * 32 + 8], 3)) //file find
{
for (i=0; i<11; i++)
{
Song_Buff[l * 11 + i] = Sector_Buf[j * 32 + i];
}
l++;
}
/*if (!memcmp(WMA, &Sector_Buf[j * 32 + 8], 3)) //file find
{
for (i=0; i<11; i++)
{
Song_Buff[l * 11 + i] = Sector_Buf[j * 32 + i];
}
l++;
}*/
if (!memcmp(TXT, &Sector_Buf[j * 32 + 8], 3)) //file find
{
for (i=0; i<11; i++)
{
Song_Buff[l * 11 + i] = Sector_Buf[j * 32 + i];
}
l++;
}
if (!memcmp(MID, &Sector_Buf[j * 32 + 8], 3)) //file find
{
for (i=0; i<11; i++)
{
Song_Buff[l * 11 + i] = Sector_Buf[j * 32 + i];
}
l++;
}
if (!memcmp(WAV, &Sector_Buf[j * 32 + 8], 3)) //file find
{
for (i=0; i<11; i++)
{
Song_Buff[l * 11 + i] = Sector_Buf[j * 32 + i];
}
l++;
}
}
k++;
ReadPage(0 + k / 32, k % 32, Sector_Buf);
}
ucModeStatus = c_Key_Mode_SelectSong; //初始化控制状态为歌曲选择
return (l);
}
int ReadSector(unsigned char *Name, unsigned char *databuff)
{
int i, k, Page;
if (DataRead == 0) //首次读
{
// ComShowString(c_COM1,"Start Read");
Page = BootSector + RsdSector + 2 * SectorofFatSize;
// ReadPage(0 + Page / 32, Page % 32, databuff);
// ComShowString(c_COM1,"Read Boot Direction");
ReadSector_SD(Page,databuff);
// ComShowString(c_COM1,"Read Value is:");
// ComSendText(c_COM1,databuff,512);
while (databuff[0] != 0)
{
for (i=0; i<16; i++)
{
if (!memcmp(Name, &databuff[i * 32], 11))
{
//获取首簇号
Current_Cluster = databuff[32 * i + 27] * 256 + databuff[32 * i + 26];
//获取数据长度。
for (k=31; k>27; k--)
{
DataRemain = (DataRemain << 8) | databuff[i * 32 + k];
}
CurrentSector = (Current_Cluster - 2) * SecPerClus + FirstDataSec;
// ComShowString(c_COM1,"Song Start Sector is :");
// ComSendText(c_COM1,&CurrentSector,4);
uiOffsetInCluster = 0;
// ReadPage(CurrentSector / 32, CurrentSector % 32, databuff);
// ReadSector_SD(Page,databuff);
ReadSector_SD(CurrentSector,databuff);
DataRead += 512;
DataRemain -= 512;
if (DataRemain < 0)
{
DataRead = 0;
return (DataRemain + 512);
}
else
{
return (512);
}
}
}
Page++;
// ReadPage(0 + Page / 32, Page % 32, databuff);
ReadSector_SD(Page,databuff);
}
return (0);
}
else //后续读操作。
{
// ComShowString(c_COM1,"Continue Read");
uiOffsetInCluster++;
if(uiOffsetInCluster <SecPerClus)
{
CurrentSector++;
}
else
{
Current_Cluster++;
CurrentSector = (Current_Cluster - 2) * SecPerClus + FirstDataSec;
uiOffsetInCluster = 0;
}
// ReadPage(CurrentSector / 32, CurrentSector % 32, databuff);
ReadSector_SD(CurrentSector,databuff);
DataRead += 512;
DataRemain -= 512;
if (DataRemain < 0)
{
DataRead = 0;
return (DataRemain + 512);
}
else return (512);
}
}
//-------------------------------------------------------------------
#define VOLUME 1
#define EFFECTION 2
#define SELECTSONG 3
#define PLAY 1
#define STOP 0
int RDCOUNT = 0;
unsigned char data MP3_Framehead[4];
unsigned char data CurrentFun = SELECTSONG;
unsigned char data PlayState = STOP;
unsigned char data NowPlaying = 0;
unsigned char data NumofSong = 0;
unsigned char data MP3InitFlag= 1;
unsigned char data ChangeSong = 0;
unsigned char VS1003B_Init();
void VS1003B_SoftReset();
char PlayInit(unsigned char *SongName)
{
SongName = SongName;
VS1003B_Init();
VS1003B_SoftReset();
#if 0
int i = 0, j = 0, f = 0;
int k = 0;
unsigned int total_size;
RDCOUNT = ReadSector(SongName, Sector_Buf); //Read 512 Bytes at first
if(RDCOUNT==0)
return 0;
/* when the first 3 bytes are 49 44 33 the next can be 03,this means ID3 V2.3 */
if (Sector_Buf[0] == 0x49)
if ((Sector_Buf[1] == 0x44) && (Sector_Buf[2] == 0x33))
{
/********** search the 7th-10th bytes,use the formular to calculate ***********/
total_size = (Sector_Buf[6] & 0x7F) * 0x200000 + (Sector_Buf[7] & 0x7F) * 0x4000 + (Sector_Buf[8] & 0x7F) * 0x80 + (Sector_Buf[9] & 0x7F);
while (total_size > 512)
{
ReadSector(SongName, Sector_Buf);
total_size -=512;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -