uda1341.c

来自「mp4的源码,主要包括loader,usb driver,mp3 decoder」· C语言 代码 · 共 120 行

C
120
字号
/***********************************************
copyright by Haia Tech
www.haia2004.com
************************************************/

#include "2410addr.h"
#include "uda1341.h"
                                                                                                                                                       

void init_uda1341()
{ 
   //init dma
	rDCON2= 0x2c480008	//IISSDO DMA,whole service mode,burst transfer 16 half word,demond mode,CURR_TC interrupt
	rDISRC2=(S16)pcm;		//address for sourse half word
	rDIDES2= IISFIFO; //address for destination  half word
	rDIDESC2= 0x02;		//no increase,destination is in APB
	rINTMSK &= (0<19);	//enable dma2 interrupt
	   
   //init iis
	rIISCON= 0x31;		//enable transmit and receive DAM and start
	rIISMOD= 0xdd;		//MSATER MODE 16bit 384fs 32fs left-justied
	rIISPSR= 
	rIISFCON=(0xf<<12); // transmit FIFO DMA,receive FIFO DMA

   //reset 
   write_addr(2);
   write_data(0xff);
   //set volume
   set_volume(20);
   
}


void write_address(U8 addr)		//address mode ,addr=0,1,2
{
    unsigned char i;
    unsigned int portb;
    if(addr>2)
    	return;
    //CS=0
    portb=0xffb;       
	rGPBDAT=rFPBDAT & portb;
    for(i=0;i<8;i++)
    {
      //SCLK=0;
      portb&=0xfef;
	  rGPBDAT=portb;
      if((addr<<i)&0x8000)
      {
        //SDIN=1;
        portb|=0x008; 
	    rGPBDAT=portb;
      }
      else 
      {
        //SDIN=0;
        portb&=0xff7;
	    rGPBDAT=portb;
      }
      //SCLK=1;
      portb|=0x010;
	  rGPBDAT=portb;
      delay(100);
    }
    //SCLK=0;
    portb&=0xfef;
    rGPBDAT=portb;
    //CS=1;
    portb|=0xff;
    rGPBDAT=portb;
}

void write_data(U8 dat)		//data mode
{
    unsigned char i;
    unsigned int portb;
    //CS=0
    portb=0xffb;      
	rGPBDAT=rFPBDAT & portb;
	for(i=0,i<6,i++);		//delay Tstp 
    //CS=1;
    portb|=0xff;
    rGPBDAT=portb;

    for(i=0;i<8;i++)
    {
      //SCLK=0;
      portb&=0xfef;
	  rGPBDAT=portb;
      if((dat<<i)&0x8000)
      {
        //SDIN=1;
        portb|=0x008; 
	    rGPBDAT=portb;
      }
      else 
      {
        //SDIN=0;
        portb&=0xff7;
	    rGPBDAT=portb;
      }
      //SCLK=1;
      portb|=0x010;
	  rGPBDAT=portb;
      delay(100);
    }
    //SCLK=0;
    portb&=0xfef;
    rGPBDAT=portb;
}

void set_volume(U8 volume) //volume<64
{
	if(volume<64)
	{
		write_addr(0);
		write_data(volume);
	}
	else	return;
}

⌨️ 快捷键说明

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