51 MCU + ISD4002 voice chip reading and writing source code

Publisher:BlissfulHeartLatest update time:2015-01-15 Source: 51heiKeywords:MCU  ISD4002 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define uchar unsigned char
#define uint unsigned int
 
sbit SS=P2^3; //Enable control port
sbit SCLK=P2^2;
sbit MOSI=P2^0;
sbit MISO=P2^1;
 
sbit LED=P1^0;
sbit PR=P1^1; //Recording and playback control terminal, adjusted by switch, high level means recording state
sbit ISD_INT=P1^2; // Overflow interrupt
 
sbit AN=P2^4;
sbit STOP=P2^5;
 
void delay(uint time)
{
 while(time!=0)
 {
  time--;
 }
}
 
void delayms(uint time)
{
 TMOD=0x01;
 for(time;time>0;time--)
 {
  TH0=0xfc;
  TL0=0x18;
  TR0=1;
  while(TF0!=1)
  {;}
  TF0=0;
  TR0=0;
 }
}
 
void spi_send(uchar isdx)
{
 uchar isx_counter;
 SS=0;
 SCLK=0;
 for(isx_counter=0;isx_counter<8;isx_counter++)
 {
  if((isdx&0x01)==1)
   SMOKE=1;
     else
   SMOKE=0;
  isdx=isdx>>1;
  SCLK=1;
  delay(2);
  SCLK=0;
  delay(2);
 }
}
 
void isd_stop(void)
{
 delay(10);
 spi_send(0x30); //stop recording and playback
 SS=1; // Voice chip is not enabled
 delayms(50);
}
 
void isd_pu(void)
{
 delay(10);
 SS=0; //Voice chip is enabled
 spi_send(0x20); //The voice chip enters standby mode
 SS=1;
 delayms(50);
}
 
void isd_pd(void)
{
 delay(10);
 spi_send(0x10); //The chip stops this operation and enters power saving mode
 SS=1;
 delayms(50);
}
 
void isd_play(void)
{
 LED=0;
 spi_send(0xf0); //Start playing at the next address
 SS=1;
}
 
void isd_rec(void)
{
 LED=0;
 spi_send(0xb0); //Start recording at the next address
 SS=1;
}
 
void isd_setplay(fly adl,fly adh)
{
 spi_send(adl);
 adh=adh|0xe0;
 spi_send(adh);
 SS=1;
}
 
void isd_setrec(uchar adl,uchar adh)
{
 spi_send(adl);
 adh=adh|0xa0;
 spi_send(adh);
 SS=1;
}
 
void isd_overflow(void)
{
 while(AN==0)
 {
  LED=1;
  delayms(300);
  LED=0;
  delayms(300);
 }
}
 
fly chk_isdovf(void)
{
 SS=0;
 delay(2);
 SCLK=0;
 delay(2);
 SCLK=1;
 SCLK=0;
 delay(2);
 if(MISO==1)
 {
  SCLK=0;
  SS=1;
  isd_stop();
  return 1;
 }
 else
 {
  SCLK=0;
  SS=1;
  isd_stop();
  return 0;
 }
}
 
void main()
{
 flying ovflag;
 while(1)
 {
  P0=P1=P2=P3=0xff;
  while(AN==1)
  {
   if(AN==0)
   {
    delayms(20);
   }
  }
 
  isd_pu();
  isd_pd();
  isd_pu();
 
 
  if(PR==1)
  {
   delayms(500);
   isd_setrec(0x00,0x00);
   do
   {
    isd_rec();
    delay(20);
    while(AN==0)
    {
     if(ISD_INT==0)//Judge the interrupt output (open drain output). When the memory overflows or the playback end mark appears, this terminal is low level and remains
     isd_overflow(); //LED flashes when the chip overflows
    }
    if(ISD_INT==0)
     break;
    LED=1;
    isd_stop();
    while(AN==1)
    {
     if(STOP==0)
     break;
     if(AN==0)
     delayms(500);
    }
   }while(AN==0);
  }
 
  else
  {
   while(AN==0)
   {;}
   isd_setplay(0x00,0x00);
   do
   {
    isd_play();
    delay(20);
    while(ISD_INT==1)
    {;}
    LED=1;
    isd_stop();
    if(ovflog=chk_isdovf())
     break;
    while(AN==1)
    {
     if(STOP==0)
      delayms(20);
     if(STOP==0)
      break;
     if(AN==0)
      delayms(20);
    }
    LED=0;
   }while(AN==0);
  }
  isd_stop();
  isd_pd();
 }
}
Keywords:MCU  ISD4002 Reference address:51 MCU + ISD4002 voice chip reading and writing source code

Previous article:Ultrasonic distance measurement source program circuit diagram with voice broadcast function
Next article:Startup code startup file c51

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号