//放音
void playsound(unsigned char *buffer, int length)
{
int count,i;
char flag;
rGPBDAT = rGPBDAT & ~(L3M|L3C|L3D) |(L3M|L3C); //L3开始传输:L3M=H, L3C=H
//配置UDA1341
WriteL3(0x14 + 2,1);
//状态模式(000101xx+10)
WriteL3(0x60,0);
//0,1,10, 000,0 : 状态0,复位
WriteL3(0x14 + 2,1);
//状态模式 (000101xx+10)
WriteL3(0x10,0);
//0,0,01, 000,0 : 状态0, 384fs,IIS,no DC-filtering
WriteL3(0x14 + 2,1);
//状态模式 (000101xx+10)
WriteL3(0xc1,0);
//1,0,0,0, 0,0,01:状态1,
//Gain of DAC 6 dB,Gain of ADC 0dB,ADC non-inverting,
//DAC non-inverting,Single speed playback,ADC-Off DAC-On
//配置s3c2440的IIS寄存器
//预分频器为3,所以CDCLK=PCLK/(3+1)=16.928kHz
rIISPSR = 3<<5|3;
//无效DMA,输入空闲,预分频器有效
rIISCON
= (0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1);
//PCLK为时钟源,输出模式,IIS模式,每个声道16位,CODECLK=384fs,SCLK=32fs
rIISMOD
= (0<<9)|(0<<8)|(2<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0);
rIISFCON = (0<<15)|(1<<13);
//输出FIFO正常模式,输出FIFO使能
flag=1;
count=0;
//开启IIS
rIISCON |= 0x1;
while(flag)
{
if((rIISCON & (1<<7))==0)
//检查输出FIFO是否为空
{
//FIFO中的数据为16位,深度为32
//当输出FIFO为空时,一次性向FIFO写入32个16位数据
for(i=0;i<32;i++)
{
*IISFIFO=(buffer[2*i+count])+(buffer[2*i+1+count]<<8);
}
count+=64;
if(count>length)
flag=0;
//音频数据传输完,则退出
}
}
rIISCON = 0x0;
//关闭IIS
}
void Main(void)
{
//配置MPLL
//fs=44.1kHz,CODECLK=384fs=16.9344MHz
//不改变CLKDIVN,所以PCLK=FCLK/8
//MPLLCON:MDIV=150,PDIV=5,SDIV=0,所以FCLK=541.7143MHz,PCLK=67.714MHz//上面的解释是fs=44.1时,而我的文件fs=22.05,所以令SDIV=1
rMPLLCON = (150<<12) | (5<<4) | 1;
//配置L3接口总线,GPB23MODE, GPB33DATA, GPB43CLOCK
rGPBCON = 0x015550;
//输出
rGPBUP
= 0x7ff;
//上拉无效
rGPBDAT = 0x1e4;
//配置IIS接口
rGPEUP = rGPEUP & ~(0x1f) | 0x1f;
//上拉无效,GPE[4:0] 1 1111
rGPECON = rGPECON & ~(0x3ff) | 0x2aa;
Uart_Init(33857000,115200);//根据PCLK设置波特率
Uart_Printf("\nNOW PLAY THE WindowsXP");
Uart_Printf("\nsample=%d",*(U32 *)(WindowsXP_Wav+0x18));//输出采样频率
playsound(WindowsXP_Wav+44,sizeof(WindowsXP_Wav)-44);//在数据开始处开始播放
rMPLLCON = (150<<12) | (5<<4) | 0;//为下面播放44.1KHZ文件设置
Uart_Init(33857000*2,115200);//PCLK设置波特率
Uart_Printf("\nNOW PLAY THE What_are_words");
Uart_Printf("\nsample=%d",*(U32 *)(What_are_words+0x18));
playsound(What_are_words+44,sizeof(What_are_words)-44);//该文件是44.1KHZ
while(1)
{
;
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |