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

📄 isd4002.c

📁 ISD4002语音芯片的初始化及空能模块的源代码
💻 C
字号:
#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/signal.h>


#define SPI_on      SPCR|=0x40
#define SPI_off     SPCR&=0xbf


void delay()
{
	unsigned int i,j;
	for(i=0;i<3000;i++)
		for(j=0;j<300;j++);
}


void SPI_Init(void)
{
	DDRD=0x00;
	DDRA=0xff;
	DDRB=0xbf;
	SPCR=0x72; 
	SPSR=1;
}

void SPI_MasterTransmit(char cData)
{
	SPDR=cData;             
    while(!(SPSR&(1<<SPIF))); 
	//PORTA=SPDR;
	//delay();
}

/**********中断函数************/
SIGNAL(SIG_ADC)
{


}
/************ISD4002***********/
void ISD4002_powerup(void)
{
	PORTB|=0x10;
	delay();
	PORTB&=0xef;

	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0x20); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_play_adr(unsigned int adr)
{
	unsigned char adr_h,adr_l;
	
	adr_h=(unsigned char)((adr>>8)|0xe0);//&0x07)|0xe0);
	adr_l=(unsigned char)(adr);

	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(adr_l);
	SPI_MasterTransmit(adr_h); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_play(void)
{
	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0xf0); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_rec_adr(unsigned int adr)
{
	unsigned char adr_h,adr_l;
	
	adr_h=(unsigned char)((adr>>8)|0xa0);
	adr_l=(unsigned char)(adr);

	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(adr_l);
	SPI_MasterTransmit(adr_h); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_rec(void)
{
	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0xb0); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_mc_adr(unsigned int adr)
{
	unsigned char adr_h,adr_l;
	
	adr_h=(unsigned char)((adr>>8)|0xe8);
	adr_l=(unsigned char)(adr);

	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(adr_l);
	SPI_MasterTransmit(adr_h); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_mc(void)
{
	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0xf8); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_stop(void)
{
	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0x30); //00100 000 00000000

	PORTB|=0x10;
}

void ISD4002_end(void)
{
	
	PORTB|=0x10;
	delay();
	PORTB&=0xef;


	SPI_MasterTransmit(0x00);
	SPI_MasterTransmit(0x10); //00100 000 00000000

	PORTB|=0x10;
}


void ISD4002_delay()
{
	unsigned int i,j;
	for(i=0;i<200;i++)
		for(j=0;j<100;j++);
}


void main()
{

	unsigned int i;
	SPI_Init();

	ISD4002_powerup();ISD4002_delay();
	ISD4002_end();	  ISD4002_delay();
	ISD4002_powerup();ISD4002_delay();

	//PORTA=0xff;

	ISD4002_rec_adr(0x0000);
	ISD4002_rec();

	//while((PIND&0x08)==0x08){}

	delay();//delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();

	ISD4002_stop();
	
	PORTA=0xff;
	while(1)
	{
	ISD4002_play_adr(0x0000);
	ISD4002_play();

	//while((PIND&0x08)==0x08){}

	PORTA=0x00;
	delay();delay();//delay();delay();delay();//delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();

	ISD4002_stop();

	}
	
}




⌨️ 快捷键说明

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