int main (void)
{
INT8U flag,part;
int i;
int j=0;
INT32U cluster,size=0;
struct FileInfoStruct FileInfo;
SystemCoreClockUpdate(); /* 时钟配置 */
uart0Init(9600,0,0,8,1);
printf("SD_SPI Test Star...\n");
gpioInit(); /* 管脚初始化 */
Led5Set(1); /* D5点亮 */
dacInit(); /* DAC 初始化 */
adcInit();
pitInit(); /* PIT 定时器初始化 */
spiInit(SPI0_BASE_PTR , Master); /* SPI0 主机模式初始化 */
flag=SD_Init();
if(flag!=0)
{
printf("SD_Init...Fall!");
while(1);
}
FAT_Init();
FAT_DisDir("\\");
while(1)
{
// 增添以按键来选择语音段播放功能
if(j==0) cluster=FAT_OpenFile("\\1.wav",&FileInfo);
if(j==1) cluster=FAT_OpenFile("\\2.wav",&FileInfo);
if(j==2) cluster=FAT_OpenFile("\\3.wav",&FileInfo);
if(j==3) cluster=FAT_OpenFile("\\4.wav",&FileInfo);
if(j==4) cluster=FAT_OpenFile("\\5.wav",&FileInfo);
if(j==5) cluster=FAT_OpenFile("\\6.wav",&FileInfo);
if(cluster==0 || FileInfo.Size == 0)
{
printf("File open err!\n");
return 0;
}
printf("File size is %d",FileInfo.Size);
FIFO_out = 0;
FIFO_in = 0;
NVIC_EnableIRQ(PIT_IRQn);
NVIC_SetPriority(PIT_IRQn,3);
__enable_irq();
size1=FileInfo.Size;
while(size<FileInfo.Size)
{
for(part=0;part<SectorsPerClust;part++)
{
FAT_LoadPartCluster(cluster,part,(uint8_t *)(Buffer+FIFO_in)); //读一个扇区
FIFO_in+=512;
if(FIFO_in==2048) FIFO_in=0;
do
{ //计算缓冲区出入口距离
i = FIFO_in - FIFO_out;
if(i<0) i+=2048; //小于0要加上2048,再比较。
} while(i>1024); //如果缓冲区接近溢出,先暂停等待。
}
cluster=FAT_NextCluster(cluster); //下一个扇区
size=size+SectorsPerClust*512;
}
j++;
if(j>=6) j=0;
while((FGPIOD_PDIR & 1<<6) == 1<<6);
myDelay(500);
myDelay(500);
size=0;
size2=0;
}
}
/********************************************************************
** Function name: PIT_IRQHandler
** Descriptions: PIT 8KHz
** input parameters: none
** output parameters: none
** Returned value: none
** Created by:
** Created date
**-------------------------------------------------------------------
** Modified by:
** Modified date:
********************************************************************/
void PIT_IRQHandler(void)
{
PIT_T标志寄存器0 |= PIT_T标志寄存器_TIF_MASK;
if(adcGetUint()<AD_Sample_Num/3)
// 根据ad采样大小 3个led灯显示音量大小程度
{
Led5Set(1);
Led6Set(0);
Led7Set(0);
}
else if(adcGetUint()<2*AD_Sample_Num/3)
{
Led5Set(1);
Led6Set(1);
Led7Set(0);
}
else
{
Led5Set(1);
Led6Set(1);
Led7Set(1);
}
Volume=Volume_Num*adcGetUint()>>16;
if(size2 < size1) dacTrigger(Buffer[FIFO_out]/(Volume_Num-Volume)); //语音输出
FIFO_out++; //输出buffer下标+1
size2++;
if(FIFO_out>2047) //达到最大值,重置下标
{
FIFO_out=0;
}
}
/********************************************************************
END FILE
********************************************************************/
|