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

📄 isd1700.c

📁 语音模块程序
💻 C
字号:
/*
实验说明:
接线:
  1、将模块上的INT与CPU板上的INT0相连;
  2、将模块上的DO与CPU板上的P11相连;
  3、将模块上的DI与CPU板上的P12相连;
  4、将模块上的CLK与CPU板上的P10相连;
  5、将模块上的SS与CPU板上的P14相连;
  6、将试验箱上开关KK1的输出K1与CPU板上的P15相连;
  7、将试验箱上开关KK2的输出K2与CPU板上的P16相连;
  8、将试验箱上开关KK3的输出K3与CPU板上的P17相连;暂时不用接。
实验过程:
  检查接线正确无误后,加电,运行程序ISD1700,将开关KK1、KK2、KK3拨到低电平侧(L侧)
先将KK1拨到H侧并对MIC讲话,结束后将开关KK1拨回L侧。将拨码开关KK2拨到H侧,开始放音,直至结束。
如果想重放,先将开关KK2拨到L侧,在拨到H侧,则重复放音。

*/
#include    <reg51.h>
//sbit		INT	 =	P1^0;   //Port to Receive interrupt signal from ISD1700
sbit		DO	 =	P1^1;    //Port to Receive data from ISD1700
sbit		DI	 =	P1^2;    //Port to Sent data to ISD1700
sbit		CLK	 =	P1^0;    //Output SPI clock
sbit		SS	 =	P1^4;    //Reset this port to enable SPI of ISD1700
sbit		rec	 =	P1^5;    //Record from Line In or Mic selected by sel
sbit		play =	P1^6;    //Playing while end
sbit		sel	 =	P1^7;    //select source of audio
unsigned char PU_cmd[] 		= {0x01,0x00};		//Power on
unsigned char STOP_cmd[]	= {0x02,0x00};		//Stop current operation
unsigned char RESET_cmd[]	= {0x03,0x00};		//Stop current operation
unsigned char CLR_INT_cmd[] = {0x04,0x00};		//clearn INT to zero
unsigned char RD_STA_cmd[] 	= {0x05,0x00,0x0};		//Read status byte
unsigned char RD_PLY_PTR_cmd[]	= {0x06,0x00,0x0,0x0};		//Read play point
unsigned char PD_cmd[] 		= {0x07,0x00};		//Power off
unsigned char RD_REC_PTR_cmd[] 	= {0x08,0x0,0x0,0x0};	//Read record point
unsigned char DEVID_cmd[] 		= {0x09,0x0,0x0};		//Read device ID
unsigned char PLAY_cmd[] 		= {0x40,0x0};			//begin to play here 
unsigned char REC_cmd[] 		= {0x41,0x0};			//begin to record here
unsigned char ERASE_cmd[] 		= {0x42,0x0};			//Erase the current sigment
unsigned char G_ERASE_cmd[] 	= {0x43,0x0};			//Erase all chip
unsigned char RD_APC_cmd[] 		= {0x44,0x0,0x0,0x0};	//Read register APC
unsigned char WR_APC1_dir_cmd[] 	= {0x45,0x7,0x4};		//Enable mode direct in SPI
unsigned char WR_APC1_mic_cmd[] 	= {0x45,0x47,0x4};		//Disable mode direct in SPI
unsigned char WR_APC2_cmd[] 	= {0x65};				//Write config data to APC,refer to function WriteApc(unsigned int dat)
unsigned char FWD_cmd[] 		= {0x48,0x0};			//Move the current point to next
unsigned char CHK_MEM_cmd[] 	= {0x49,0x0};			//Check the loop memory
unsigned char EXTCLK_cmd[] 		= {0x4a,0x0};			//Enable the ext clock
bit		idle = 1;		//Chip is in idle status
bit		recflag = 0;	//flag of record
bit 	audinflag = 0;	//flag  mode audio in 
unsigned char *pStatus;  //Status of chip
void Delay(unsigned int time)
  {
   while(time-->0);
  }
void SpiIni(void)			//Initialize SPI port          
  {
   SS = 1;
   CLK = 1;
   DI = 0;
   Delay(10);
  }
unsigned char WriteByte(unsigned char dat)	//write a byte to ISD1700, Read a byte from ISD
  {
   char num = 8;
   unsigned char tmp = 0;
   DO = 1;
   while(num-->0)
     {
      CLK = 0;
	  Delay(20);
	  DI = (dat&0x1)?1:0;
	  dat >>=1;	  
      tmp >>= 1;	  
	  tmp |= (DO == 0) ? 0x80:0x0;
	  Delay(20);
      CLK = 1;
      Delay(80);
	 }
   //Delay(1000);
   return tmp;
  }

void Write2ISD1700(unsigned char num,unsigned char * pBuff,unsigned char *pReceive)  //
  {
   SS = 0;
   while(num-->0)
     {
	  *(pReceive++) = WriteByte(*(pBuff++));
	 }
   SS = 1;
  }
void Ext0Inter(void) interrupt 0
  {
   unsigned char IntClrCmd[] = {0x04,0x0};
   idle = 1;
   Write2ISD1700(2,IntClrCmd,pStatus);   //Clearn INTERRUPT and EOM flag
  }
void PlayCurrent(void)  //Start to play at current segment
  {
   while(!idle); 
   idle = 0;
   Write2ISD1700(2,PLAY_cmd,pStatus);  //Start to play at current segment
  }
void Record(void)  //Start to play at current segment
  {
   while(!idle); 
   idle = 0;
   recflag = 1;
   Write2ISD1700(2,REC_cmd,pStatus);  //Start to play at current segment
  }
void EraseAll(void)  //Start to play at current segment
  {
   while(!idle); 
   idle = 0;
   Write2ISD1700(2,G_ERASE_cmd,pStatus);  //Start to play at current segment
  }
void Stop(void)
  {
   Write2ISD1700(2,STOP_cmd,pStatus);  //Start to play at current segment   
   recflag = 0;
  }
void AudioSeclect(bit s)
  {
   if(s) Write2ISD1700(3,WR_APC1_dir_cmd,pStatus);
   else  Write2ISD1700(3,WR_APC1_mic_cmd,pStatus);
   audinflag = 0;
  }
void main(void)
  {
    unsigned char *pDevid,Cmd[] = {0xa5};
   bit selbak = 0,selchange = 0;
   SpiIni();
   IT0 = 1; EX0 = 1; EA=1;
   Write2ISD1700(2,RESET_cmd,pStatus);    //Reset the chip
   Write2ISD1700(2,PU_cmd,pStatus);       //Power on
   Write2ISD1700(3,DEVID_cmd,pDevid);
   EraseAll();
   while(1) 
     {
	 /*
	  if(sel != selbak) 
	    {
		 selbak = sel;
		 selchange = 1;
		}
	  */
 	  if(rec&&!play) 
	    {
		/*
		 if(selchange)
		   {
		    AudioSeclect(sel);
			selchange = 0;
		   }
		 */
		 Record();
		 while(rec);
		}
	  if(recflag) Stop();
      if(play&&!rec)
	    {
		 PlayCurrent();
		 while(play);
		}
 	 }
  }

⌨️ 快捷键说明

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