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

📄 isd1700.c

📁 ISD 语音芯片的驱动程序。 原有产品已经停产
💻 C
字号:
#include "Includes.h"
//unsigned char   ISDEvent=0;
//unsigned char   ISDEvent2=0;

#define uint  unsigned int
#define uchar unsigned char


void delay_50us(uint time1)
{
    unsigned char i;
    for(time1;time1>0;time1--)
    {
	//for(i=0;i<12;i++)     22.1184
        for(i=0;i<6;i++)       //11.0592  2007.12.03
	{
	   _nop_();
	}
    }
}

void delay(uint msec)
{
    for (msec; msec > 0; msec--)
    {
//        clrwatchdog();
        delay_50us(20);
    }
}

uchar spio(uchar BUF_ISD) //shaoliang
{
 uchar i,dat=BUF_ISD;
 SCLK=1;
 SS=0;
 for(i=0;i<8;i++)
 {
 	 SCLK=0;
	 _nop_(); _nop_();_nop_(); _nop_(); _nop_();
 	  if(dat&0X01)	MOSI=1;
	  else	 	  	MOSI=0;
	 dat>>=1;
	 if(MISO)
	    dat=(dat|0X80);
	  SCLK=1;
	  _nop_(); _nop_(); _nop_(); _nop_();_nop_();
 }
 MOSI=0;
 return(dat);
}
 void rdstatus()
{
 spio(0x05);
 spio(0x00);
 spio(0x00);
 SS=1;
 //delay(100);               //延迟100ms
 //SR0_L=spio(0x05);
 //SR0_H=spio(0x00);
 //SR1=spio(0x00);
}
void clrint()
{
 	spio(0x04);	 	spio(0x00);	   	SS=1;

}
void pu()		 //power up
{
   spio(0x01);	   	spio(0x00);	   	SS=1;
    delay(120);
    //delay(60);
}
void pd()	    //power down
{
 	spio(0x07);	 	spio(0x00); 	SS=1;
 	delay(100);
}
void reset()
{
 	spio(0x03);	 	spio(0x00); 	SS=1;
	delay(100);
}
void chk_mem()
{
	spio(0x49);	 	spio(0x00);	 	SS=1;	 delay(150);
}

void wr_apc2()		//aux输出    音量最大000   command		 d7:d0     d11:d8
{
        unsigned char SR0_L;

	spio(0x65); 	spio(0x80);	 	spio(0x04);		// d7:d0   d11:d8
	SS=1;  delay(5)	;

	    spio(0x05);
 		spio(0x00);
 		spio(0x00);
		 SS=1;

		 SR0_L=0;
         SR0_L=spio(0x05);

		 if((SR0_L&0x01)==0x01)
		 {
		 wr_apc2();
		 }
        wr_nvcfg();
}


void wr_apc1()		//线路输入, aux 输出
{
	spio(0x45); 	spio(0xc0);	 	spio(0x04);		// d7:d0   d11:d8
	SS=1;  delay(1)	;
}
/*
void rd_apc()
{
 spio(0x44);spio(0x00); spio(0x00);spio(0x00);
 SS=1;
 spio(0x44);spio(0x00); APCL=spio(0x00);APCH=spio(0x00);
}

void playall()
{
 	spio(0x40);		spio(0x00);	 	SS=1;
}

void rec()
{
 spio(0x41);   spio(0x00);	   SS=1;
}
void erase()
{
	spio(0x42);	 	spio(0x00);	 	SS=1;
}

void eraseall()
{
	spio(0x43);		spio(0x00);	 	SS=1;
}
void rd_play_ptr()
{
	spio(0x06);	 	spio(0x00);	 	spio(0x00);		spio(0x00);
	SS=1;
}
void devid()
{
	spio(0x09);spio(0x00);spio(0x00);
	SS=1;
	spio(0x09);spio(0x00);ID=spio(0x00);
}

senddata()
{
 	SBUF=SR0_L;	   	while(TI==0);	TI=0;
	SBUF=SR0_H ;	while(TI==0);	TI=0;
	SBUF=SR1;   	while(TI==0);	TI=0;
}
*/
void stop()
{
 	spio(0x02);spio(0x00); SS=1;
}

/*void setplay(uchar segment)
{
        stop();
        clrint();
        chk_mem();
	switch (segment)
    {
        case 1:
            spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x2a);spio(0x00);SS=1;
            break;
        case 2:
            spio(0x80);spio(0x00); spio(0x2B);spio(0x00);spio(0x41);spio(0x00);SS=1;
            break;
        case 3:
            spio(0x80);spio(0x00); spio(0x42);spio(0x00);spio(0x4e);spio(0x00);SS=1;
            break;
		case 4:
            spio(0x80);spio(0x00); spio(0x4F);spio(0x00);spio(0x62);spio(0x00);SS=1;
            break;
		case 5:
            spio(0x80);spio(0x00); spio(0x63);spio(0x00);spio(0x70);spio(0x00);SS=1;
            break;
		case 6:
            spio(0x80);spio(0x00); spio(0x71);spio(0x00);spio(0x80);spio(0x00);SS=1;
            break;
		case 7:
            spio(0x80);spio(0x00); spio(0x81);spio(0x00);spio(0x9e);spio(0x00);SS=1;
            break;
		case 8:
            spio(0x80);spio(0x00); spio(0x9F);spio(0x00);spio(0xaf);spio(0x00);SS=1;
            break;
		case 9:
            spio(0x80);spio(0x00); spio(0xB0);spio(0x00);spio(0xBc);spio(0x00);SS=1;
            break;
		case 10:
            spio(0x80);spio(0x00); spio(0xBD);spio(0x00);spio(0xCB);spio(0x00);SS=1;
            break;
        default:
			 spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x2a);spio(0x00);SS=1;
            break;
    }
}*/

void setplay(uchar segment)
{
        stop();
        clrint();
        chk_mem();
	switch (segment)
    {
        case 0:          //播放4元
            spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x1a);spio(0x00);SS=1;
            break;
        case 1:		  //卡片无效         //播放4元
            spio(0x80);spio(0x00); spio(0x1b);spio(0x00);spio(0x27);spio(0x00);SS=1;
            break;
        case 2:		  //学生卡             //卡片无效
            spio(0x80);spio(0x00); spio(0x28);spio(0x00);spio(0x32);spio(0x00);SS=1;
            break;
        case 3:		 //新高职             //学生卡
            spio(0x80);spio(0x00); spio(0x33);spio(0x00);spio(0x3d/*0x3D*/);spio(0x00);SS=1;
            break;
		case 4:	   //记名卡          //新高职
            spio(0x80);spio(0x00); spio(0x3e);spio(0x00);spio(0x49);spio(0x00);SS=1;
            break;
		case 5:		   //家属卡      //记名卡
            spio(0x80);spio(0x00); spio(0x49);spio(0x00);spio(0x53);spio(0x00);SS=1;
            break;
		case 6:		   //教工卡         //家属卡
            spio(0x80);spio(0x00); spio(0x54);spio(0x00);spio(0x5D);spio(0x00);SS=1;
            break;
		case 7:		   //临时卡        //教工卡
            spio(0x80);spio(0x00); spio(0x5E);spio(0x00);spio(0x67);spio(0x00);SS=1;
            break;
		case 8:		   //无效卡        //临时卡
            spio(0x80);spio(0x00); spio(0x68);spio(0x00);spio(0x71);spio(0x00);SS=1;
		case 9:		   //1            //无效卡
            spio(0x80);spio(0x00); spio(0x72);spio(0x00);spio(0x76);spio(0x00);SS=1;
            break;

	   //case 10:
         //   spio(0x80);spio(0x00); spio(0xBD);spio(0x00);spio(0xCB);spio(0x00);SS=1;
         //   break;
        default:
			 //spio(0x80);spio(0x00); spio(0x10);spio(0x00);spio(0x2a);spio(0x00);SS=1;
            break;
    }
}

void wr_nvcfg()
{

   	spio(0x46);spio(0x00); SS=1;

}

unsigned char initisd1700()
{

        unsigned char data ISDEvent=0,SR0_L;



dd: pu();   //上电

	//rdstatus();
        spio(0x05);
        spio(0x00);
        spio(0x00);
        SS=1;
        SR0_L=0;
         //delay(100);               //延迟100ms
        SR0_L=spio(0x05);
        //SR0_H=spio(0x00);

	if((((SR0_L&0x04)==0x00)||((SR0_L&0x01)==0x01)) &&ISDEvent!=1)
	{
		 ISDEvent++;
		 reset();
		 pd();
		 goto dd;
	}

        chk_mem();
        wr_apc1();
        wr_nvcfg();
        if(ISDEvent==1) return 1;
        else return 0;
	//ISDEvent=0;


}
  /*
void isdmain()
{

	uchar serial=0;
	uint aa=0;
		delay(1000);
	TMOD=0x20;
	TL1=0xfd;TH1=0xfd;		   //波特率9600 8数据 1停止
	SCON=0xd8;PCON=0x00;
	TR1=1;
	P0=0xFF;P2=0xFF; MOSI=0;
 	LED1=0;
 	SBUF=0x55;while(TI==0);	TI=0;
	SBUF=0xAA;while(TI==0);	TI=0;

dd: pu();   //上电
	rdstatus();
	senddata();
//	SBUF=SR0_L;	  while(TI==0);	TI=0; //////////////////
	if(PU_1700==0||CMD_ERR==1)
	{
		 reset();
		 pd();
		 SBUF=0xAB;	  while(TI==0);	TI=0; 	 //
		 goto dd;
	}
	clrint();
	rdstatus();
	senddata();

	 devid();
	 SBUF=0xDD;   	while(TI==0);	TI=0; //////////////////
	 SBUF=ID;   	while(TI==0);	TI=0;

	// wr_apc1();
	 rd_apc();
	 	 SBUF=0xAC;   	while(TI==0);	TI=0;
		  SBUF=APCH;   	while(TI==0);	TI=0;
		   SBUF=APCL;   	while(TI==0);	TI=0;



 aa:  setplay(1);

	 rdstatus();
	 senddata();						  //////////////////
	 if(CMD_ERR==1)
  {
 	 clrint();
  	 SBUF=0xBC;	  while(TI==0);	TI=0;
	 goto aa;
  }


  while(1)
 {
	if(key3==0)delay(20);
		{
		if(key3==0)
		{
		 	clrint();
			chk_mem();
			while(key3==0)
			{
				rec();
				rdstatus();
					while(REC_1700)
					{
					 	delay(50);
						LED1=!LED1;
						SBUF=0xCD;	  while(TI==0);	TI=0;
					}
			}
			clrint();
			stop();
			//delay(50);LED1=!LED1;
		 }
	}

	if(key1==0) delay(20) ;
	{
		if(key1==0)
		{
		  //	stop();
			 cc: chk_mem();
		  playall();
		  clrint();
			rdstatus();
			senddata();
			if(CMD_ERR)
		  {
		  	 SBUF=0xBC;	  while(TI==0);	TI=0;
			 goto cc;
		  }
		  while(key1==0);

		}

	}
   LED2=!LED2;	delay(50);//SBUF=0x1a;while(TI==0);	TI=0;
 }
}

*/

⌨️ 快捷键说明

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