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

📄 isd_4004.c

📁 89C51单片机控制语音芯片4004例程
💻 C
字号:
/*********************************************************************/
/*****************Isd_4004_16Me_program procedure*********************/
/******************************noting*********************************/
/*   c4        c3         c2          c1            c0               */
/*  run     play/rec     power   ignore addr  message cueing         */
/*        c4 ……c0  a15…………a0                    
POWERUP :  00100xxx(xxxxxxxxxxxxxxx) 上电:等待TPUD后器件可以工作
SET PLAY:  11100xxx(A15~A0)          从指令地址开始放音,须后跟PLAY指令,使放音继续
PLAY    :  11110xxx(xxxxxxxxxxxxxxx) 从当前地址开始放音(直至EOM或OVF)
SET REC :  10100xxx(A15~A0)          从指定地址开始录音,须后跟REC指令,使录音继续
REC     :  10110xxx(xxxxxxxxxxxxxxx) 从当前地址开始录音(直至OVF或停止)
SET MC  :  11101xxx(A15~A0)          从指定地址开始快进,须后跟MC指令,使快进继续
MC      :  11111xxx(xxxxxxxxxxxxxxx) 执行快进,直到EOM,若再无信息,则进入OVF状态
STOP    :  0x110xxx(xxxxxxxxxxxxxxx) 停止当前操作
STOPPWRDN: 0x01xxxx(xxxxxxxxxxxxxxx) 停止当前的操作并掉电
//RINT    :  0x110xxx(xxxxxxxxxxxxxxxx)读状态;OVF和EOM
**********************************************************************/

#include<reg52.h>
#include<intrins.h>
#define uint  unsigned int
#define uchar unsigned char                
#define ISD_POWER_UP   0x20   //00100xxx
#define ISD_SET_PLAY   0xe0   //11100xxx
#define ISD_PLAY       0xf0   //11110xxx
#define ISD_SET_REC    0xa0   //10100xxx     10110xxx
#define ISD_REC        0xb0   //10110xxx
#define ISD_SET_MC     0xe8   //11101xxx
#define ISD_MC         0xf8   //11111xxx
#define ISD_STOP       0x30   //0x110xxx
#define ISD_STOP_PWRDN 0x10   //0x01xxxx

void powerdown(uchar mode1);
void powerup(uchar powernum);

void delay_w(unsigned int del);


sbit    CS_4004   =  P1^3;      //      P1^3;
sbit    MOSI_4004 =  P1^6;      //      P1^6;
sbit    MISO_4004 =  P1^5;      //      P1^5;
sbit    SCLK_4004 =  P1^4;      //      P1^4;
sbit    RAC_4004  =  P1^4;      //      
sbit    LED       =  P2^6;           //      P1^4;
sbit    light     =  P0^1;
sbit    mute      =  P0^3;

/**********************************************************************/
/*delay procedure*/
/**********************************************************************/
void delay(uint i) //延时程序
{
    while(i--);//_nop_();
}
/**********************************************************************/
/*Move a byte rightwards */
/**********************************************************************/
bit cror_(uchar data1)
{
    if(data1&0x01) return 1;
    else return 0;
}
/**********************************************************************/
/*Move a byte rightwards*/
/**********************************************************************/
bit iror_(uint data2)
{
    if(data2&0x01) return 1;
    else return 0;
}
/**********************************************************************/
/*can stop any operation*///停滞
/**********************************************************************/
void stopmode(uchar mode)
{
    uchar i,j;
    CS_4004=1;
    SCLK_4004=0;
    CS_4004=0;
    j=mode;
    for(i=0;i<8;i++)
    {
        MOSI_4004=cror_(j);
        SCLK_4004=0;
        SCLK_4004=1;
        j=j>>1;
    }
    CS_4004=1;
}
/**********************************************************************/
/*power down means restart or reset*/
/**********************************************************************/
void powerdown(uchar mode1)
{
    uchar i,j;
    CS_4004=1;
    SCLK_4004=0;
    CS_4004=0;
    j=mode1;
    for(i=0;i<8;i++)
    {
        MOSI_4004=cror_(j);
        SCLK_4004=0;
        SCLK_4004=1;
        j=j>>1;
    }
    CS_4004=1;
}
/**********************************************************************/
/*the first option to do (must do it)*/
/**********************************************************************/
void powerup(uchar powernum)
{
    uchar i,j;
    CS_4004=1;
    SCLK_4004=0;
    CS_4004=0;
    if(powernum)
                {powernum=powernum|0x31;}
    j=0x20;
    for(i=0;i<8;i++)
    {
        MOSI_4004=cror_(j);
        SCLK_4004=0;
        SCLK_4004=1;
        j=j>>1;
    }
    CS_4004=1;
}
/**********************************************************************/
/*PLAYING OUT SOUND form addr*///音频输出
/**********************************************************************/
void audioout(unsigned int address)
{
    uchar i,j;
    uint add;
    powerup(4);
    delay(5000);
    CS_4004=1;
    SCLK_4004=0;
    CS_4004=0;
    add=address;
    for(i=0;i<16;i++)
    {
        MOSI_4004=iror_(add);
        SCLK_4004=0;
        SCLK_4004=1;
        add=add>>1;
    }
    j=ISD_SET_PLAY;
    for(i=0;i<8;i++)
    {
        MOSI_4004=cror_(j);
        SCLK_4004=0;
        SCLK_4004=1;
        j=j>>1;
    }
    CS_4004=1;
    SCLK_4004=0;
    CS_4004=0;
    j=ISD_PLAY;
    //delay(50000);
    for(i=0;i<8;i++)
    {
        MOSI_4004=cror_(j);
        SCLK_4004=0;
        SCLK_4004=1;
        j=j>>1;
    }
    CS_4004=1;
}
/**********************************************************************
/*EXAM PROCEDURE
***********************************************************************/
 main()
{
    uchar j=0;
    TMOD=0x01;
    TH0=0;
    TL0=0;
    ET0=1;
    EA=1;
    LED=1;
    //TR0=1;	
    delay(20000);
    powerdown(0x10);
    delay(1000);
	light=0;
    mute=1;
    while(1)
	{	    
      delay_w(500);
	  light=~light;
      audioout(0x0012);
      delay_w(5000);
      light=~light;
	  while(1);
	  //stopmode(0x20);
      //TR0=1;       
      //powerdown(0x10);
    }  
}

void delay_w(unsigned int del)
{
  unsigned int i=0;
  while(del--)
       {
         for(i=0;i<0x4c;i++)
           {
             _nop_();
           }
       }
}

⌨️ 快捷键说明

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