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

📄 isd1700.c

📁 ISD1700系列语音芯片驱动
💻 C
字号:
/***************************************************************************************************
//完成ISD1700控制驱动
***************************************************************************************************/
#include "head.h"
#if 1
unsigned char SR0L,SR0H,SR1;//各个状态寄存器的状态
unsigned char PU,CMD_REE,RDY;//特殊标志为的状态
unsigned  char	Ring_num;//选择要播放的音乐曲目号
const unsigned int Rings_Addr[Max_Rings+1]={0,Ring1,Ring2};//各段录音对应的地址
/************************************************************************************
*   按照ISD1700方式初始化SPI
****************************************************************************************/
void spi_init_ISD1700(void)
{
	 SPCR = 0x7f; //setup SPI
	 SPSR = 0x00; //setup SPI
}
/************************************************************************************
*   读ISD1700   状态寄存器
****************************************************************************************/
void Read_ISD1700_Status(void)
{
	EN_ISD1700(1);
	SR0L=Read_SPI_Byte(0x05);
	SR0H=Read_SPI_Byte(0x00);
	SR1=Read_SPI_Byte(0x00);
	EN_ISD1700(0);
	PU=SR0L&0x04;
	CMD_REE=SR0L&0x01;
	RDY=SR1&0x01;
}
/************************************************************************************
*   清楚中断标志
****************************************************************************************/
void Clear_int(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x04);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
/************************************************************************************
*   上电
****************************************************************************************/
void POWER_UP(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x01);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
/************************************************************************************
*   掉电
****************************************************************************************/
void POWER_Down(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x07);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
/************************************************************************************
*   复位
****************************************************************************************/
void REST_ISD1700_CM(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x03);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
#if 0
/************************************************************************************
*   读ISD1700   APC 状态寄存器
****************************************************************************************/
void Read_APC(void)
{
	EN_ISD1700(1);
	Read_SPI_Byte(0x44);
	Write_SPI_Byte(0x00);
	Read_SPI_Byte(0x00);
	Read_SPI_Byte(0x00);
	EN_ISD1700(0);
}
void Check_men(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x49);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
void Play_Set(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x50);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
#endif
/************************************************************************************
*  写APC寄存器
****************************************************************************************/
void Write_APC(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x65);
	Write_SPI_Byte(0x88);
	Write_SPI_Byte(0x08);
	EN_ISD1700(0);
}
/************************************************************************************
*  停止放音
****************************************************************************************/
void Stop_Music(void)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x02);
	Write_SPI_Byte(0x00);
	EN_ISD1700(0);
}
/************************************************************************************
*  绝对地址放音
*   addr放音起始地址
****************************************************************************************/
void Play_Addr(unsigned int	addr)
{
	EN_ISD1700(1);
	Write_SPI_Byte(0x80);
	Write_SPI_Byte(0x00);
	Write_SPI_Byte(addr);
	Write_SPI_Byte(addr>>8);
	Write_SPI_Byte(END_ADDR);
	Write_SPI_Byte(END_ADDR>>8);
	EN_ISD1700(0);
}
/************************************************************************************
*  初始化ISD1700
****************************************************************************************/
unsigned char ISD1700_init(void)
{	
		spi_init_ISD1700();
		POWER_UP();
		delay_mS(100);
		Read_ISD1700_Status();
		Tx_string("SR0L=");
		Print_A_num(SR0L);
		Tx_char(0x0d);
		
		Tx_string(" SR0H=");
		Print_A_num(SR0H);
		Tx_char(0x0d);
		
		Tx_string(" SR1=");
		Print_A_num(SR1);
		Tx_char(0x0d);
		
		if(SR0L&0x10)
		{
			Clear_int();
		}
		if(PU&&(!CMD_REE)&&(RDY))
		{
			Write_APC();
			Tx_string(" ISD1700 OK!");
			//Music_TO_Speaker();
			//Play_Set();
			return 1;
		}
		else
		{
			POWER_Down();
			Tx_string("ISD1700Err");
			return	0;
		}
}
/************************************************************************************
*  打印到com数据
****************************************************************************************/
void Print_A_num(unsigned  char c)
{
	if((c>>4)>0x09)
	{
		Tx_char((c>>4)+0x41-10);
	}
	else
	{
		Tx_char((SR0H>>4)+48);
	}
	if((c&0x0f)>0x09)
	{
		Tx_char((c&0x0f)+0x41-10);
	}
	else
	{
		Tx_char((c&0x0f)+48);
	}
}
/************************************************************************************
*  放音
*   n   音乐其实地址
****************************************************************************************/
void Play_Mucis(unsigned int n)
{
	Music_Play(phone_state&HF_state);
	spi_init_ISD1700();
       if(!Music_Time_Over)
	{
	        Stop_Music();
               delay_mS(20);
       }
	Clear_int();
	delay_mS(10);
	Play_Addr(n);
	Music_Time_Over=0;
}
/************************************************************************************
*  检查放音是否结束
****************************************************************************************/
unsigned char  Check_Over(void)
{
	spi_init_ISD1700();
	Read_ISD1700_Status();
	return SR0L&0x10;
}
/************************************************************************************
*  停止正在播放的录音
****************************************************************************************/
void Stop_Play_Music(void)
{
	spi_init_ISD1700();
	Stop_Music();
}
#endif

⌨️ 快捷键说明

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