?? main.c
字號:
#include <stdio.h>
#include <string.h>
#include "..\Inc\AT8xC51SND1.h"
#include "..\Inc\GLOBAL.h"
#include "..\Inc\CHIPSOURCE.h"
#include "..\Inc\COMMON.h"
#include "..\Inc\IDEIO.h"
#include "..\Inc\FAT.h"
#include "..\Inc\MP3DECODER.h"
#include "..\Inc\LCD.h"
#include "..\Inc\USB.h"
//#include "mp3player.c"
#define DEFAULT_PARTITION 0
#define ISNUMBER(X) (X>='0'&&X<='9')?1:0
extern xdata BYTE CommandBuffer[128];
xdata struct DirEntryPointStr MP3PlayDirPoint;
xdata BYTE filename[128];
void InitDisk(void);
void ListDisk(void);
void InitDisk(void)
{
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
printf(" 初始化IDE...");
IDEInit(MainBuffer[0].DATA);
if (IDE.Devices) printf("ok!\n\n"); else {printf("error!\n\n");return;}
ListDisk();
}
void ListDisk(void)
{
if (IDE.Devices)
{
printf(" 發現 %bd 個IDE設備!\n",IDE.Devices);
printf(" 驅動器 總扇區數 總字節數\n");
printf(" ------ ------------ ---------------\n");
printf(" 1 %12lu %15lu\n",IDE.IDEDevice[0].TotalSectors,IDE.IDEDevice[0].TotalSectors*512);
if (IDE.Devices==2)
printf(" 1 %12lu %15lu\n",IDE.IDEDevice[1].TotalSectors,IDE.IDEDevice[2].TotalSectors*512);
printf("\n");
}
else
printf(" 錯誤!IDE設備未初始化,請先執行INIT DISK命令.\n\n");
}
void MountDisk(void)
{
data BYTE n;
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
if (CommandBuffer[11]=='1') n=1;
else if (CommandBuffer[11]=='2') n=2;
else {printf(" 格式:MOUNT DISK [1|2]\n\n"); return;}
if (IDE.Devices&n)
{
if (n==1) IDESetCurrentDevice(IDE_DEVICE_MASTER);
else IDESetCurrentDevice(IDE_DEVICE_SLAVE);
printf(" 當前驅動器:%bd\n 初始化FAT文件系統...",(IDE.Devices&0xf0)>>4);
FATInit();
FATSetStorageMedia(FAT_MEDIA_TYPE_HDD);
FATGetPartitions();
printf("ok!\n\n");
}
else printf(" 未找到驅動器\n\n");
}
void ListDrive(void)
{
BYTE Part,i;
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
printf(" 當前驅動器:%bd\n",(IDE.Devices&0xf0)>>4);
printf(" 總分區數:%bd\n",StorageMedia.TotalPartitions);
Part=StorageMedia.CurrentPartition;
for(i=0;i<StorageMedia.TotalPartitions;i++)
FATMountPartition(i);
if (Part!=255)
FATMountPartition(Part);
}
void MountDrive(void)
{
BYTE n;
BYTE temp[3];
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
n=strlen(CommandBuffer);
if ((n==13&&ISNUMBER(CommandBuffer[12]))||(n==14&&ISNUMBER(CommandBuffer[12])&&ISNUMBER(CommandBuffer[13])))
{
for(n=12;n<15;n++)
temp[n-12]=CommandBuffer[n];
n=(BYTE)atoi(temp);
if (n>=0&&n<StorageMedia.TotalPartitions)
{
FATMountPartition(n);
printf(" 當前分區:%bd\n\n",StorageMedia.CurrentPartition);
}
else
printf(" 分區號錯誤!\n\n");
}
else {printf(" 格式:MOUNT DRIVE [分區號]\n\n"); return;}
}
void Dir(void)
{
BYTE filename[128];
struct DirEntryPointStr temp;
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
if (StorageMedia.CurrentPartition==255) {printf("未加載任何分區,請先用MOUNT DRIVE命令加載分區.\n"); return;}
temp=FAT.DirEntryPoint;
do
{
FATGetFileName(filename,&(FAT.DirEntryPoint));
if (FATIsDirectory(&(FAT.DirEntryPoint))) printf("[%s]\n",filename);else printf("%s\n",filename);
}while(FATNextEntry(&(FAT.DirEntryPoint)));
FAT.DirEntryPoint=temp;
}
void Cd(void)
{
BYTE i=3;
BYTE filename[128];
struct DirEntryPointStr temp;
if (MP3.Playing) {printf("播放狀態該功能禁用!\n");return;}
if (StorageMedia.CurrentPartition==255) {printf("未加載任何分區,請先用MOUNT DRIVE命令加載分區.\n"); return;}
temp=FAT.DirEntryPoint;
while(CommandBuffer[i]) {CommandBuffer[i-3]=CommandBuffer[i];i++;}
CommandBuffer[i-3]=0;
do
{
FATGetFileName(filename,&(FAT.DirEntryPoint));
if (strcmp(filename,CommandBuffer)==0) {i=0; break;}
}while(FATNextEntry(&(FAT.DirEntryPoint)));
if (i)
printf("目錄\"%s\"未找到.",CommandBuffer);
else
if (FATIsDirectory(&(FAT.DirEntryPoint))) {FATChangeDirectory(&(FAT.DirEntryPoint));return;}
else printf("\"%s\"不是一個目錄.",CommandBuffer);
FAT.DirEntryPoint=temp;
}
void Play(void)
{
BYTE i=3;
BYTE filename[128];
struct DirEntryPointStr temp;
if (StorageMedia.CurrentPartition==255) {printf("未加載任何分區,請先用MOUNT DRIVE命令加載分區.\n"); return;}
temp=FAT.DirEntryPoint;
while(CommandBuffer[i]) {CommandBuffer[i-5]=CommandBuffer[i];i++;}
CommandBuffer[i-5]=0;
do
{
FATGetFileName(filename,&(FAT.DirEntryPoint));
if (strcmp(filename,CommandBuffer)==0) {i=0; break;}
}while(FATNextEntry(&(FAT.DirEntryPoint)));
if (i)
printf("文件\"%s\"未找到.",CommandBuffer);
else
if (!FATIsDirectory(&(FAT.DirEntryPoint)))
{
MP3PlayDirPoint.ParentDirEntryClus=FAT.DirEntryPoint.ParentDirEntryClus;
MP3PlayDirPoint.CurrentDirEntryClus=FAT.DirEntryPoint.CurrentDirEntryClus;
MP3PlayDirPoint.CurrentClus=FAT.DirEntryPoint.CurrentClus;
MP3PlayDirPoint.CurrentOffset=FAT.DirEntryPoint.CurrentOffset;
MP3.File=FATOpenFile(&MP3PlayDirPoint);
LoadMP3Data(MP3.File);
printf(" 播放\"%s\"\n",CommandBuffer);
return;
}
else printf("\"%s\"是一個目錄.",CommandBuffer);
FAT.DirEntryPoint=temp;
}
void Stop(void)
{
MP3.Playing=0;
FATCloseFile(MP3.File);
}
void Pause(void)
{
CLEAR_BIT_6(AUDCON1);
}
void GoOn(void)
{
SET_BIT_6(AUDCON1);
}
void Bass(void)
{
BYTE i,temp[4];
for(i=5;i<9;i++)
temp[i-5]=CommandBuffer[i];
if (strcmp(temp,"ON")==0)
{
SET_BIT_6(MP3CON);
printf(" 重低音開\n");
}
else if(strcmp(temp,"OFF")==0)
{
CLEAR_BIT_6(MP3CON);
printf("重低音關\n");
}
}
void Volume(BYTE m)
{
BYTE n,temp[3];
n=strlen(CommandBuffer);
if ((n==6&&ISNUMBER(CommandBuffer[5]))||(n==7&&ISNUMBER(CommandBuffer[5])&&ISNUMBER(CommandBuffer[6])))
{
for(n=5;n<8;n++)
temp[n-5]=CommandBuffer[n];
n=(BYTE)atoi(temp);
printf("vol:%bd\n",n);
if (n>=0&&n<32)
{
if (m==0)
{
MP3VOL=n;
printf("左聲道音量:%bd\n",MP3VOL);
}
else if(m==1)
{
MP3VOR=n;
printf("右聲道音量:%bd\n",MP3VOR);
}
else
{
MP3VOL=n;
MP3VOR=n;
printf("左聲道音量:%bd 右聲道音量:%bd\n",MP3VOL,MP3VOR);
}
}
}
}
void main(void)
{
data BYTE cmd;
// xdata BYTE function=0;
P5=0;
EA=1;
memset((void *)&IDE,0,sizeof(struct IDEStr));
memset((void *)&StorageMedia,0,sizeof(struct StorageMediaStr));
StorageMedia.CurrentPartition=255;
//初始化
InitPLL();
InitUART();
InitKEY();
// InitTimer0();
InitMP3Decoder(&MP3PlayDirPoint,filename);
PrintLogo();
while(1)
{
cmd=AcceptCmd();
switch(cmd)
{
case 0: Help(); break;
case 1: InitDisk(); break;
case 2: ListDisk(); break;
case 3: MountDisk(); break;
case 4: ListDrive(); break;
case 5: MountDrive(); break;
case 6: Dir(); break;
case 7: Cd(); break;
case 8: Play(); break;
case 9: Stop(); break;
case 10: Pause(); break;
case 11: GoOn(); break;
case 12: Volume(0); break;
case 13: Volume(1); break;
case 14: Volume(2); break;
case 15: Bass(); break;
}
}
FATInit();
FATSetStorageMedia(FAT_MEDIA_TYPE_HDD);
FATGetPartitions();
printf("Total Partitions:%bd\n",StorageMedia.TotalPartitions);
FATMountPartition(DEFAULT_PARTITION);
if (FATErrorCode==0)
printf("Mount Partition %bd OK\n",DEFAULT_PARTITION);
else
{
printf("Mount Partition %bd Error\n");
while(1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -