基于52单片机ISD1760语音芯片的原理图和程序代码。

基于52单片机ISD1760语音芯片的原理图和程序代码。,第1张

#include <reg51.h>

#define uchar unsigned char

#define uint unsigned int

//******************定义端衡早乱口******************//

sbit SS = P1^0

sbit SCK = P1^1

sbit MOSI = P1^2

sbit MISO = P1^3

sbit PR = P1^4//PLAY = 0REC = 1

sbit STOP = P1^5

sbit AN = P1^6

sbit LED = P1^7

//******************定义ISD1700状态寄存器及各标志位******************//

uchar bdata SR0_L//SR0寄存器低位、高位

uchar bdata SR0_H

uchar bdata SR1//SR1寄存器

uchar APC_L = 0, APC_H = 0//APC寄存器

uchar PLAYADDL = 0, PLAYADDH = 0//放音指针低位、高位

uchar RECADDL = 0, RECADDH = 0//录音指针低位、高位

sbit CMD_ERR = SR0_L^0//SPI指令无效标志位

sbit FULL = SR0_L^1//芯片存储空间满标志位

sbit PU = SR0_L^2//上电标志位

sbit EOM = SR0_L^3//EOM标志位

sbit INT = SR0_L^4// *** 作完成标志位

sbit RDY = SR1^0//芯片空闲标志位

sbit ERASE = SR1^1//擦除标志位

sbit PLAY = SR1^2//放音标志位

sbit REC = SR1^3//录音标志位

//******************定义标志位******************//

uchar bdata fang

sbit PR_fang = fang^1//录音、放音标志位,放音=0,录音=1

sbit Erase_fang = fang^4//擦出标志位

sbit STOP_fang = fang^7//停止放音标志位

//******************延时μs******************//

void delay(uint time)//延时n微秒

{

while(time!=0)

{

time--

}

}

//******************延时ms******************//

void delayms(uint time)//延时n毫秒

{

for(timetime>0time--)

{

TH0 = 0xfc

TL0 = 0x18

TR0 = 1//计数器0启动

while(TF0!=1)//计咐档数溢出处理

TF0 = 0

TR0 = 0

}

}

//******************CPU初始化******************//

void cpu_init (void)

{

P1 = 0xFF

P2 = 0xFF

P3 = 0xFF

TMOD = 0x01//定时器初睁空始化,工作于方式1

EA = 0//关中断

fang = 0//标志位归0

LED = 1//关指示灯

}

//******************发送、读回数据******************//

uchar isd_senddata (uchar dat)

{

uchar i, BUF_ISD = dat

SS = 0

SCK = 1

delay(4)

for(i=0i<8i++)

{

SCK = 0

if((BUF_ISD&0x01)==1)

{

MOSI = 1

}

else

{

MOSI = 0

}

BUF_ISD = BUF_ISD >>1

if(MISO)

{

BUF_ISD = BUF_ISD|0x80

}

SCK = 1

delay(6)

}

MOSI = 0

return(BUF_ISD)

}

//******************上电******************//

void isd_pu (void)

{

isd_senddata (0x01)

isd_senddata (0x00)

SS = 1

delayms(50)

}

//******************停止当前 *** 作******************//

void isd_stop (void)

{

isd_senddata (0x02)

isd_senddata (0x00)

SS = 1

delayms(50)

}

//******************复位******************//

void isd_reset (void)

{

isd_senddata (0x03)

isd_senddata (0x00)

SS = 1

}

//******************清除中断******************//

void isd_clr_int (void)

{

isd_senddata (0x04)

isd_senddata (0x00)

SS = 1

}

//******************读状态寄存器内容******************//

void isd_rd_status (void)

{

isd_senddata (0x05)

isd_senddata (0x00)

isd_senddata (0x00)

SS = 1

delay(2)

SR0_L = isd_senddata (0x05)

SR0_H = isd_senddata (0x00)

SR1 = isd_senddata (0x00)

SS = 1

}

//******************读放音指针******************//

void isd_rd_playptr (void)

{

isd_senddata (0x06)

isd_senddata (0x00)

isd_senddata (0x00)

isd_senddata (0x00)

SS = 1

delay(2)

SR0_L = isd_senddata (0x06)

SR0_H = isd_senddata (0x00)

PLAYADDL = isd_senddata (0x00)

PLAYADDH = isd_senddata (0x00)

SS = 1

}

//******************下电******************//

void isd_pd (void)

{

isd_senddata (0x07)

isd_senddata (0x00)

SS = 1

delayms(50)

}

//******************读录音指针******************//

void isd_rd_recptr (void)

{

isd_senddata (0x08)

isd_senddata (0x00)

isd_senddata (0x00)

isd_senddata (0x00)

SS = 1

delay(2)

SR0_L = isd_senddata (0x08)

SR0_H = isd_senddata (0x00)

RECADDL = isd_senddata (0x00)

RECADDH = isd_senddata (0x00)

SS = 1

}

//******************读芯片ID******************//

uchar isd_devid (uchar deviceNO)

{

isd_senddata (0x09)

isd_senddata (0x00)

isd_senddata (0x00)

SS = 1

delay(2)

isd_senddata (0x09)

isd_senddata (0x00)

deviceNO = isd_senddata (0x00)

SS = 1

return(deviceNO)

}

//******************放音******************//

void isd_play (void)

{

isd_senddata (0x40)

isd_senddata (0x00)

SS = 1

}

//******************录音******************//

void isd_rec (void)

{

isd_senddata (0x41)

isd_senddata (0x00)

SS = 1

}

//******************擦除******************//

void isd_erase (void)

{

isd_senddata (0x42)

isd_senddata (0x00)

SS = 1

}

//******************全部擦出******************//

void isd_g_erase (void)

{

isd_senddata (0x43)

isd_senddata (0x00)

SS = 1

}

//******************读APC寄存器内容******************//

void isd_rd_apc (void)

{

isd_senddata (0x44)

isd_senddata (0x00)

isd_senddata (0x00)

isd_senddata (0x00)

SS = 1

delay(2)

SR0_L = isd_senddata (0x44)

SR0_H = isd_senddata (0x00)

APC_L = isd_senddata (0x00)

APC_H = isd_senddata (0x00)

SS = 1

}

//******************写APC寄存器******************//

void isd_wr_apc2 (uchar apcdatl,apcdath)

{

isd_senddata (0x65)

isd_senddata (apcdatl)

isd_senddata (apcdath)

SS = 1

}

//******************将APC寄存器内容写入NVCFG******************//

void isd_wr_nvcfg (uchar apcdatl,apcdath)

{

isd_senddata (0x46)

isd_senddata (apcdatl)

isd_senddata (apcdath)

SS = 1

}

//******************将NVCFG内容写入APC******************//

void isd_ld_nvcfg (void)

{

isd_senddata (0x47)

isd_senddata (0x00)

SS = 1

}

//******************快进******************//

void isd_fwd (void)

{

isd_senddata (0x48)

isd_senddata (0x00)

SS = 1

}

//******************空检查******************//

void isd_chk_mem (void)

{

isd_senddata (0x49)

isd_senddata (0x00)

SS = 1

}

//******************外部时钟的启用、关闭******************//

void isd_extclk (void)

{

isd_senddata (0x4a)

isd_senddata (0x00)

SS = 1

}

//******************指定地址放音******************//

void isd_set_play (uchar saddl,saddh,eaddl,eaddh)

{

isd_senddata (0x80)

isd_senddata (0x00)

isd_senddata (saddl)

isd_senddata (saddh)

isd_senddata (eaddl)

isd_senddata (eaddh)

isd_senddata (0x00)

SS = 1

}

//******************指定地址录音******************//

void isd_set_rec (uchar saddl,saddh,eaddl,eaddh)

{

isd_senddata (0x81)

isd_senddata (0x00)

isd_senddata (saddl)

isd_senddata (saddh)

isd_senddata (eaddl)

isd_senddata (eaddh)

isd_senddata (0x00)

SS = 1

}

//******************指定地址擦除******************//

void isd_set_erase (uchar saddl,saddh,eaddl,eaddh)

{

isd_senddata (0x82)

isd_senddata (0x00)

isd_senddata (saddl)

isd_senddata (saddh)

isd_senddata (eaddl)

isd_senddata (eaddh)

isd_senddata (0x00)

SS = 1

}

//******************芯片系统初始化******************//

void isd_init (void)

{

uchar i = 2

SS = 1

SCK = 1

MOSI = 0

do

{

isd_pu ()

isd_rd_status ()

}while(CMD_ERR||(!PU))

isd_wr_apc2 (0x40,0x04)

do

{

isd_rd_status ()

}while(RDY==0)

do

{

LED = 0

delayms(300)

LED = 1

delayms(300)

i--

}while(i>0)

}

//******************isd1700的相关 *** 作******************//

void isdwork (void)

{

uchar i

switch (fang)

{

case 0x00:

{

do

{

isd_rd_status ()

}while(RDY==0)

delayms(10)

isd_play ()

delayms(2)

LED = 0

do

{

isd_rd_status ()

if(STOP==0)

{

delayms (10)

if(STOP==0)

{

LED = 1

isd_clr_int ()

isd_stop ()

isd_reset ()

isd_pd ()

isd_init ()

return

}

}

}while(PLAY==1)

LED = 1

isd_clr_int ()

do

{

isd_rd_status ()

}while(RDY==0)

delayms (10)

isd_fwd ()

do

{

isd_rd_status ()

}while(RDY==0)

}

break

case 0x02:

{

isd_clr_int ()

do

{

isd_rd_status ()

}while(RDY==0)

delayms(10)

isd_rec ()

delayms(2)

LED = 0

do

{

isd_rd_status ()

if(FULL==1)

{

for(i=3i>0i--)

{

LED = 0

delayms (300)

LED = 1

delayms (200)

}

}

}while(AN==0)

isd_clr_int ()

isd_stop ()

LED = 1

}

break

case 0x10:

{

do

{

isd_rd_status ()

}while(RDY==0)

delayms (10)

isd_g_erase ()

delayms (2)

do

{

isd_rd_status ()

}while(RDY==0)

for(i=3i>0i--)

{

LED = 0

delayms (300)

LED = 1

delayms (200)

}

}

break

case 0x80:

{

isd_clr_int ()

isd_stop ()

isd_reset ()

isd_pd ()

}

break

}

}

//******************主程序******************//

void main (void)

{

uchar i

cpu_init ()

delayms (1)

isd_init ()

while(1)

{

if(AN==0)

{

delayms (10)

if(AN==0)

{

if(PR==1)

{

PR_fang = 1

}

else

{

PR_fang = 0

}

isdwork ()

}

}

if(STOP==0)

{

delayms (10)

if(STOP==0)

{

for(i=100i>0i--)

{

if(STOP==1)

{

STOP_fang = 1

isdwork ()

isd_init ()

break

}

delayms(30)

}

if (STOP_fang==1)

{

fang = 0

continue

}

Erase_fang = 1

isdwork ()

}

}

}

}

这个是按键录放的例程,你可以根据这个例程自己修改一下

其实实现这个稿巧禅功能也不是很难,但是你一定要选择一款合适的语音芯片,我前两天刚做了一个这方面的东东,51上的控制很简单,只有几条语句,控制一下语音芯片的时序就可以宽闷了。下面是控制代码:

//TG2 、TG1 分别语音芯片键尘的两个控制管脚

TG2 = 0

for(i=0i<250i++) // 延时750us

TG2 = 1

for(i=0i<250i++) // 延时750us

TG1 = 1

for(j=0j<360j++) // 延时 2 ms

TG1 = 0

就这几条语句,就可以发音了。希望对你有所帮助。

并且不同的语音芯片,控制方法也不一样,你应该把你的语音芯片的型号告诉我们,也许正好有人用过呢,或者正在用,大家可以一起交流一下的,

您好,单片机语音录放软件流程局旦基主要包括以下几个步骤:

1. 系统初始化:包括时钟、IO口、中断等初始化。

2. 录音模式:将输入的语音信号通过模拟转数字(ADC)转换器转换成数字信号,存储到内部或外部存储器中桐谨。

3. 播放模式:读取内部或外部存储器中的语音数据,通过数字转模拟(DAC)转换器转换成模拟信号,输出到扬声器或耳机中播放。

4. 暂停和停止:在录音或播放过程中,可以通过按键等方式实现暂停和停止功能。

5. 声音调节:可以通过调整音量、音调迟仔等参数来实现对录音和播放声音的调节。

6. 数据传输:可以通过串口、USB等方式将录音数据传输到电脑等外部设备中进行处理和存储。

以上就是单片机语音录放软件流程的主要步骤,通过这些步骤可以实现对语音信号的录制、播放和处理。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12454139.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存