#include
Keywords:MCU ISD4002
Reference address:51 MCU + ISD4002 voice chip reading and writing source code
#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();
}
}
Previous article:Ultrasonic distance measurement source program circuit diagram with voice broadcast function
Next article:Startup code startup file c51
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Guess you like
- Quartus II 11.0 + NIOS soft core fails to program FLASH
- Python Keyboard using circuitpython
- CCS6 Call Array
- RVB2601 simple unpacking
- TI Embedded Live Month: In-depth exploration of new applications of embedded products in industry and automobiles. The second session will be live at 14:00 today.
- Integrate MCU and sensors into multiple nodes to power wireless weather stations
- [Update Mailing Information] 2020-2021 ON Semiconductor and Avnet IoT Creative Design Competition
- About the Standardization of PLC Programming
- MEMS pressure sensors solve new pain points in human-machine interface
- How to set the wake-up clock on CC1310 WOR