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

📄 main.c

📁 基于stm32的MP3播放器
💻 C
字号:
#include "stm32f10x_lib.h"
#include"COMM.H"
#include "delay.h" 	   
#include "sys.h"
#include "usart.h" 

//#include "tftlcd.h"
//注意,如果加载非法的JPEG图片文件,可能导致数据溢出,
//从而篡改全局变量!!!!!!!!	  
	    
	  
#define SD_TYPE_MMC     0
#define SD_TYPE_V1      1
#define SD_TYPE_V2      2
#define SD_TYPE_V2HC    4
 
extern u16 POINT_COLOR;
extern u8 SD_Type;	   
extern DWORD FirstDirClust;    //第一个目录簇号
extern DWORD FirstDataSector;  // 数据的第一个扇区
extern WORD BytesPerSector;	   // 每扇区的字节数
extern WORD FATsectors;		// The amount sector a FAT occupied
extern WORD SectorsPerClust;	// 每簇扇区数
extern DWORD FirstFATSector;	// The first FAT sector
extern DWORD FirstDirSector;	// The first Dir sector
extern DWORD RootDirSectors;	// The sector number a Root dir occupied 
extern DWORD RootDirCount;		// The count of directory in root dir
extern BYTE  FAT32_Enable;

extern unsigned char FAT_Init(void); 
    

void FAT_Info(void)
{	
	u32 sd_size=0;
	sd_size=SD_GetCapacity();  
	printf("SD Card Type:");
	switch(SD_Type)
	{
		case 0:printf("SD_TYPE_MMC\n");break;
		case 1:	printf("SD_TYPE_V1\n");break;
		case 2:	printf("SD_TYPE_V2\n");break;
		case 4:printf("SD_TYPE_V2HC\n");break;	 
	}
	delay_ms(10);

	if(FAT32_Enable)printf("File System:FAT32\n");
	else printf("File System:FAT16\n");

	printf("SD Size:%dMb\n",sd_size>>20);//显示SD卡容量
	delay_ms(10);
	printf("FirstDirClust:%d\n",FirstDirClust);delay_ms(10);
	printf("FirstFATSector:%d\n",FirstFATSector);delay_ms(10);

	printf("FATsectors:%d\n",FATsectors);delay_ms(10);
	printf("BytesPerSector:%d\n",BytesPerSector);delay_ms(10);
	printf("FirstDataSector:%d\n",FirstDataSector);delay_ms(10);
	printf("RootDirSectors:%d\n",RootDirSectors);delay_ms(10);
	printf("RootDirCount:%d\n\n",RootDirCount);delay_ms(10);

	printf("FATsectorsL:%d\n",FATsectors&0xffff);delay_ms(10);	 
	printf("FATsectorsH:%d\n",FATsectors>>16);delay_ms(10); 
	printf("SectorsPerClust:%d\n",SectorsPerClust);delay_ms(10);		 	   
}
									   
//extern FileInfoStruct F_Info[8];
extern u8 FSIZE;  
//extern Pen_Holder Pen_Point;//定义笔实体
			   
  																	  		  	  			 		 
int main(void)
{	
	u32 index=0;
	u8 t;	 		   		  	  	  
	Stm32_Clock_Init();//时钟配置   
	delay_init(72);	   //延时配置 
	uart_init();	   									    				   	  
	TFT_Init();	  //初始化TFTLCD	 
	init1820();   //初始化温度传感器
	Vs1003_Init();//初始化VS1003的IO口	 
	Mp3Reset();   //复位VS1003
	IIC_Init();	    	  
	//注意rtc必须在touch之前初始化!!!
	//因为备份区域的读写在rtc里面使能的
	rtc_init();  //初始化实时时钟	 
	touch_init();//触摸屏初始化	   
	TFT_CLEAR(WHITE);//清屏touch_adjust();//屏幕校准			 
	SD_Init();	 
	Alarm_Init();//闹钟初始化
	RGBLED_Init();//RGB彩灯初始化
					 
	while(FAT_Init())//初始化文件系统失败
	{
		TFT_ShowString(56,120,"FAT Init Failed!");//SD FAIL
		TFT_ShowString(56,136,"Plesase Check...");//等待插入SD卡    
		delay_ms(100); 
		SD_Init();	
	}						
	TFT_CLEAR(WHITE);//清屏			 			  			   
	POINT_COLOR=BRED; 	  
	FAT_Info();   	  				     
	while (1)           
  	{  	     
		while(SysInfoGet(0x00)==0)//得到系统文件失败
		{
			TFT_ShowString(50,120,"SYSTEM File LOST!");//SD FAIL
			TFT_ShowString(56,136,"Plesase Check...");//等待插入SD卡 
			delay_ms(500); 
			while(FAT_Init())
			{
//RESTART:				
				TFT_ShowString(50,120,"  SD Card LOST!  ");//SD FAIL
				TFT_ShowString(56,136,"Plesase Check...");//SD FAIL
				SD_Init();//重新初始化文件系统
				delay_ms(500);
			}
		}	    
		Load_Sys_ICO();//加载系统主界面图标													 
		
		index=0;
		Select_Menu(0,0,1);//默认选中第一个	   
		Pen_Point.Key_Sta=Key_Up;//释放显示期间的触发		 
		t=0;
		while(1)  //不断显示
		{
			if((Pen_Point.Key_Sta==Key_Down||NPEN)&&Pen_Point.Key_LSta)t=Touch_To_Num(0);//得到按键值	  
			if(PEN)//按键松开了,状态改变(状态机)
			{
				Pen_Point.Key_LSta=1;	 
				Pen_Point.Key_Sta=Key_Up;
			}    						   
			if(t)
			{ 
				Pen_Point.Key_LSta=0;	   
				Select_Menu(0,t-1,1);//选中这个
				if(index!=t-1)Select_Menu(0,index,0);//取消上一次的
				else //此次选择和上次一样,进入该功能
				{
					
					switch(index)
					{
						case 0://音乐模式	    
						 	TFT_CLEAR(WHITE);//清屏  
							Mus_Viewer();//音乐浏览
							Load_Sys_ICO();//重新加载系统菜单 
							Select_Menu(0,index,1);//选中上次选中的
							break; 
						case 1://浏览图片		 
						 	TFT_CLEAR(WHITE);//清屏 
							Pic_Viewer();//图片浏览
							Load_Sys_ICO();//重新加载系统菜单 
							Select_Menu(0,index,1);//选中上次选中的
							break;
						case 4:	  //时间模式	 
							Time_Viewer();
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break; 
						case 5:	  //设置模式	 				    
							Set_Viewer();
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break;     
						case 6://浏览TXT文件	   
							TFT_CLEAR(WHITE);//清屏					    
							Txt_Viewer();
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break; 
						case 8:// 重新启动FAT	  
							RGBLED_Play();
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break;
							//goto RESTART;
						case 7://收音机模式		  
							Radio_Play();								 
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break;
						case 2://游戏模式	  
							Game_Play();
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的
							break;
						case 3://闹钟模式   
							Alarm_Viewer();	
							Load_Sys_ICO();//重新加载系统菜单
							Select_Menu(0,index,1);//选中上次选中的 
							break;							 
					}
				} 
				index=t-1; 									   
				t=0;
			}
			delay_ms(10);	  
		} 	  		  					 
  	}     
}	 

⌨️ 快捷键说明

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