基于51单片机控制ISD1760的c程序

基于51单片机控制ISD1760的c程序,第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系列的控制ISD1760实现语音组合播放,前提对ISD1760的语音存储原理、语音信息地址分布机理要有足够了解。完成这些准备工作后,就是录音,制作样品,提取每段语音信息的地址信息,根据这些地址信息去编写51的控制程序。一般做法,存储在ISD1760中的语音有“0~9,一些英文字母,比如E(代替13层),叮咚提示音,还有欢迎词,欢送词,运行方向提示等”这些语音字段是语音组合播放的基础信息。这一切完成后,就该用51去组合调用这些声音,以达到播放例句“叮咚!1层到了,请走好”等等不同情形下的语音提示内容。

能实现语音组合播放的语音芯片很多,比如PM66智能语音芯片,WD588D语音模组等,这些芯片的开发比ISD便利很多,性能也稳定。

你好!

1、首先 isd1760 只是一个语音芯片,不具备MCU的功能

2、isd1760 接入单片机,然后用单片机发指令控制芯片

3、上位机通过串口和单片机连接,通过上位机间接控制芯片


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存