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

📄 main.c

📁 这是EBF533试验板的源代码和使用说明手册
💻 C
字号:
#include "ccblkfn.h"
#include "sysreg.h"

#include <sys\exception.h>
#include <cdefBF533.h>

#include "Aic23b_regdef.h"

#include "I2C.h"

#define SPIDelay 10000
#define Sample8K 0
#define Sample48K 1

unsigned short sports1error;


void DelayTime(unsigned int Value)
{
	unsigned int i=0;
	for(i=0;i<Value;i++)
		{;
		}
}

void Init_PLL(void)
{
    	int iIMASK_Value;
		
	sysreg_write(reg_SYSCFG, 0x32);
	//Initialize System Configuration Register

	// set VCO/CCLK = 1, and VCO/SCLK = 5 (take effect immediately)
	*pPLL_DIV = 0x0005;

	// prepare PLL changes (set CLKIN/VCO = 22; 
	//takes effect after PLL programming sequence)
	*pPLL_LOCKCNT = 0x0200;
	// time for PLL to stabilize
	*pPLL_CTL = 0x2c00;
	// set VCO/CLKIN = 22

	// execute PLL programming sequence
	*pSIC_IWR = 0x00000001;
	// enable only PLL wakeup interrupt
	iIMASK_Value	= cli();
	// disable interrupts
	idle();
	// wait for PLL wakeup interrupt
	sti(iIMASK_Value);	
}//end Init_PLL 

void Init_Flags(void)
{
	*pFIO_INEN = 0x0080;
	*pFIO_DIR = 0x000c;
	*pFIO_FLAG_C = 0x0008;//open audio output power opamp
	//*pFIO_EDGE		= 0x0000;
	//*pFIO_MASKA_D	= 0x0080;
}

void Init_Interrupts(void)
{
	// assign core IDs to interrupts
	*pSIC_IAR0 = 0xffff6fff;
	*pSIC_IAR1 = 0xffffff5f;
	*pSIC_IAR2 = 0xffffffff;
}

void Init_SPI(void)
{
	*pSPI_BAUD = 60;
	//baud rate = sysclk /(2*SPI_BAUD)

	*pSPI_CTL = 0x1101;
	//16bits
	*pSPI_FLG = 0x0040;
	//PF6 is SPI select out
}

void Init_Sports1(void)
{	
	*pSPORT1_TCR2 = 0x001f;

	*pSPORT1_TCR1 = 0x4000|0x0400|0x0001|0x2000;

	*pSPORT1_RCR2 = 0x001f;

	*pSPORT1_RCR1 = 0x4000|0x0400|0x0001|0x2000;
}

void Init_Sports0(void)
{	
	*pSPORT0_TCR2 = 0x001f;

	*pSPORT0_TCR1 = 0x4000|0x0400|0x0001|0x2000;

	*pSPORT0_RCR2 = 0x001f;

	*pSPORT0_RCR1 = 0x4000|0x0400|0x0001|0x2000;
}

/*******************************************************/
/*This function initialize the tlv320aic23b audio codec                    */
/*
Select line in input.

Line in left and right volume are set to default 0dB,
and simultaneous update is disabled.
Headphone output volume are set to 0x70(-9dB),
and simultaneous update & zero-cross detect is disabled.

Sidetone is disabled.
Bypass is disabled.
Microphone is normal.

DAC soft mute is disabled.
De-emphasis is disabled.
ADC high-pass filter is enabled.

Master mode,16bits.
DAC left/right swap is disable.
MSB is available on 1st BCLK rising edge after LRCIN rising edge
DSP format,frame sync followed by two data words.

Sample Rate Normal mode.
48K.
Clock input divider is 0.
Clock output divider is 0.
*/
/*******************************************************/
unsigned char Init_AIC23B_I2C(void)
{
	if(!I2C_Init(AIC23B_IDENT_W))
		{return false;}

	if(!I2C_Write_Word(PWDC|0x00ff))
		{return false;}
	
	if(!I2C_Write_Word(LLVC|0x1d))
		{return false;}
	if(!I2C_Write_Word(RLVC|0x1d))
		{return false;}
	if(!I2C_Write_Word(LHVC|0x70))
		{return false;}
	if(!I2C_Write_Word(RHVC|0x70))
		{return false;}
	
	if(!I2C_Write_Word(AAPC|DAC))
		{return false;}
		
	if(!I2C_Write_Word(AAPC|DAC|INSEL))
		{return false;}
		
	if(!I2C_Write_Word(DAPC))
		{return false;}
	
	if(!I2C_Write_Word(DAIF|MS|FOR|LRP))
		{return false;}
	if(!I2C_Write_Word(SARC))
		{return false;}
	if(!I2C_Write_Word(DIAC|ACT|RES))
		{return false;}

	if(!I2C_Write_Word(PWDC))
		{return false;}

	return true;
}



/*
void AIC23B_PWON(void)
{
	while((*pSPI_STAT&0x0001)!=1){;}
	*pSPI_TDBR = (PWDC);
	Delay(SPIDelay);
}

void AIC23B_PWOFF(void)
{
	while((*pSPI_STAT&0x0001)!=1){;}
	*pSPI_TDBR = (PWDC|0x00ff);
	Delay(SPIDelay);
}

void AIC23B_LineinVol(unsigned char LeftLineinVol,unsigned char RightLineinVol)
{	
	if(!((LeftLineinVol>0x1f)|(RightLineinVol>0x1f)))
		{	
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (LLVC|LeftLineinVol);
		//volume range from 0x00 to 0x1f
		Delay(SPIDelay);
		
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (RLVC|RightLineinVol);
		//volume range from 0x00 to 0x1f
		Delay(SPIDelay);
		}
}

void AIC23B_HPoutVol(unsigned char LeftHPVol,unsigned char RightHPVol)
{
	if(!((LeftHPVol>0x7f)|(LeftHPVol<0x30)|(RightHPVol>0x7f)|(RightHPVol<0x30)))
		{	
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (LHVC|LeftHPVol);
		//volume range from 0x30 to 0x7f
		Delay(SPIDelay);
		
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (RHVC|RightHPVol);
		//volume range from 0x30 to 0x7f
		Delay(SPIDelay);
		}
}

void AIC23B_SampleRate(unsigned char SampleRate)
{
	if(SampleRate == Sample8K)
		{
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (SARC|0x000c);
		//8K sample
		Delay(SPIDelay);
		}
	else if(SampleRate == Sample48K)
		{
		while((*pSPI_STAT&0x0001)!=1){;}
		*pSPI_TDBR = (SARC);
		//48K sample
		Delay(SPIDelay);
		}
}
*/
EX_INTERRUPT_HANDLER(SPORTS1_ERROR)
{
	unsigned short i=0;
	sports1error = *pSPORT1_STAT;
	i++;
}

EX_INTERRUPT_HANDLER(SPORTS0_RX)
{
	*pSPORT0_TX32 = *pSPORT0_RX32;
}

void main()
{	
	
	unsigned short counter;
	
	//	Init_PLL();
	Init_Interrupts();
	//Init_SPI();
	//Init_Flags();
	Init_Sports0();
	
	register_handler(ik_ivg12, SPORTS0_RX);
	
	register_handler(ik_ivg13, SPORTS1_ERROR);

	*pSIC_IMASK = 0x00000200;
	
	
	//Init_AIC23B();
	if(!Init_AIC23B_I2C())
		{
			while(1);
		}
	

	
	while(1);

	
	
}









⌨️ 快捷键说明

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