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

📄 play.c

📁 一个基于ATmega64、VS1003、SD卡的mp3播放程序
💻 C
字号:
#include "includes.h"
#include "FAT.c"
#include "PLAY.h"
//***************************************************
//函数名称:Play_File(unsigned long Cluster,unsigned long Size)
//函数功能:播放文件
//输入:Cluster:文件起始簇号 Size:文件大小(单位:字节)
//输出:无
//说明:无
//***************************************************
unsigned char Play_File(unsigned long Cluster,unsigned long Size)
{
	unsigned int i,j,temp,time,vol;
	unsigned char k,flag=0;
	unsigned long Sectors;
	Sectors=Size>>9;
	temp=Size&0x1ff;
	PORTD|=0x01;
	do
	{
		for(i=0;i<Sectors_Per_Cluster;i++)//跳出当前曲目的播放(下一曲)
		{
			if((PING&0x10)==0)//如果按钮按下则跳出
			{
				for(time=35000;time>0;time--);
				if((PING&0x10)==0)
				{
					while((PING&0x10)==0);
					return 0;
				}
			}
			else if((PING&0x08)==0&&flag==0)//音量减
			{
				for(time=35000;time>0;time--);
				if((PING&0x08)==0)
				{
					flag=1;
					vol=VS1003B_ReadCMD(0x0b);
					if(vol<0x7878)vol+=0x0808;
					else vol=0x8080;
					VS1003B_WriteCMD(0x0b,vol);
				}
			}
			else if((PING&0x04)==0&&flag==0)//音量加
			{
				for(time=35000;time>0;time--);
				if((PING&0x04)==0)
				{
					flag=1;
					vol=VS1003B_ReadCMD(0x0b);
					if(vol>0x0808)vol-=0x0808;
					else vol=0x0000;
					VS1003B_WriteCMD(0x0b,vol);
				}
			}
			else if((PING&0x02)==0)//跳到下一目录
			{
				for(time=35000;time>0;time--);
				if((PING&0x02)==0)
				{
					while((PING&0x02)==0);
					NextDir=1;
					return 0;
				}
			}
			else if((PING&0x0C)==0x0C)flag=0;//没有键按下,清除音量调节标志
			SD_Read_One_Sector(Root_Entries+((System_ID==FAT16)?32:0)+(Cluster-2)*Sectors_Per_Cluster+i);
			if(Sectors--)
			{
				for(j=0;j<512;j+=32) 
				{
					while((VS1003B_PIN & (1<<VS1003B_DREQ))==0);
					for(k=0;k<32;k++)
					{
						VS1003B_WriteDAT(Sector_Buffer[j+k]);
					}
				}
			}
			else 
			{
				for(j=0;j<temp;j+=32) 
				{
					while((VS1003B_PIN & (1<<VS1003B_DREQ))==0);
					for(k=0;k<32&&(j+k)<temp;k++)
					{
						VS1003B_WriteDAT(Sector_Buffer[j+k]);
					}
				}
				PORTD&=0xFE;
				return 0;
			}

		}
		Cluster=Get_Next_Cluster(Cluster);
		PORTD^=0x01;
	}
	while(Cluster<=((System_ID==FAT16)?0xFFEF:0xFFFFFFEF)&&Cluster>=3);
	PORTD&=0xFE;
	return 1;
}

⌨️ 快捷键说明

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