|
|
- /*************************************************
- 功 能:STC12C5A60S2驅(qū)動(dòng)ISD1760語(yǔ)音模塊
- 單片機(jī):STC12C5A60S2
- 晶 振:11.0592M
- 作 者:蘇義江根據(jù)1730改編
- 時(shí) 間:2016-8-4
- 說(shuō) 明:?jiǎn)纹瑱C(jī)4個(gè)IO口接1760的SS,SCLK,MOSI,MOSO.
- 地址從0x0010開(kāi)始安自己所錄得語(yǔ)音長(zhǎng)度調(diào)節(jié)
- 通過(guò)按鍵或傳感器定點(diǎn)播放'你好歡迎光臨。你好請(qǐng)避讓。
- 這是你點(diǎn)的菜謝謝。歡迎再次光臨再見(jiàn)'
- ***************************************************/
- #include<stc12c5a60s2.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define PU 0x01// 上電
- #define STOP 0x02//停止
- #define RESET 0x03//復(fù)位
- #define CLI_INT 0x04//清除EOM標(biāo)志和中斷信號(hào)
- #define RD_STATUS 0x05//返回狀態(tài)寄存器內(nèi)容
- //在1,2字節(jié)返回狀態(tài)寄存器信息,2,3字節(jié)返回放音指針
- #define RD_PLAY_PTR 0x06
- #define PD 0x07//芯片下電
- //在1,2字節(jié)返回狀態(tài)寄存器信息,2,3字節(jié)返回錄音指針
- #define RD_REC_PTR 0x08
- #define RD_DEVID 0x09//讀取芯片ID號(hào)碼
- #define PLAY 0x40 //從當(dāng)前地址放音
- #define REC 0x41 //從當(dāng)前地址錄音
- #define ERASE 0x42 //擦除當(dāng)前語(yǔ)音段
- #define G_ERASE 0x43 //擦除芯片所有語(yǔ)音
- //返回狀態(tài)寄存器信息在1,2字節(jié),APC寄存器信息在3字節(jié)
- #define RD_APC 0x44
- //將<D11:D0>寫入APC寄存器
- #define WR_APC1 0x45
- #define WR_NVCFG 0x46//將APC內(nèi)容寫入NVCFG
- #define LD_NVCFG 0x47 //將NVCFG內(nèi)容寫入APC
- #define FWD 0x48 //將放音指針指向下一段語(yǔ)音地址處
- #define CHK_MEM 0x49//檢查環(huán)狀存儲(chǔ)體系
- #define EXTCLK 0x4a //外部時(shí)鐘使能
- //將<D11:D0>寫入APC寄存器,并由<D2:D0>位控制音量
- #define WR_APC2 0x65
- #define SET_PLAY 0x80//從起始地址<S10:S0>放音到結(jié)束地址<E10:E0>結(jié)束
- #define SET_REC 0x81//從起始地址<S10:S0>錄音到結(jié)束地址<E10:E0>結(jié)束
- #define SET_ERASE 0x82//從起始地址<S10:S0>擦除到結(jié)束地址<E10:E0>結(jié)束
- #define HIGH 1
- #define LOW 0
- #define NOP _nop_()//定義除命令外剩余字節(jié)個(gè)數(shù)
- #define Surplus_One_BYTE 1 //定義字節(jié)個(gè)數(shù)為4
- #define Surplus_Two_BYTE 2 //定義字節(jié)個(gè)數(shù)為2
- #define Surplus_Three_BYTE 3 //定義字節(jié)個(gè)數(shù)為3
- #define ENISD1760_SS ISD1760_SS=0
- #define DISENISD1760_SS ISD1760_SS=1
- #define ISD1760_MISO_L ISD1760_MISO=0
- #define ISD1760_MISO_H ISD1760_MISO=1
- #define ISD1760_MOSI_L ISD1760_MOSI=0
- #define ISD1760_MOSI_H ISD1760_MOSI=1
- #define ISD1760_SCLK_L ISD1760_SCLK=0
- #define ISD1760_SCLK_H ISD1760_SCLK=1
- ////接收1730內(nèi)部返回的數(shù)
- uchar SR0H; // bdata
- uchar SR0L; // bdata
- uchar SR1; // bdata
- uchar SR2;
- sbit ISD1760_SS = P1^3;
- sbit ISD1760_SCLK= P1^2;
- sbit ISD1760_MOSI= P1^1;
- sbit ISD1760_MISO= P1^0;
- sbit led =P3^7;
- sbit s1=P3^0;
- sbit s2=P3^1;
- sbit s3=P2^6;
- sbit s4=P2^7;
- volatile uchar ISD1760_Spio(volatile uchar dat) ;
- void ISD1760_Write_APC2(void) ;
- void ISD1760_delay(uint Count)
- {
- uint x,y;
- for(x=Count;x>0;x--)
- for(y=420;y>0;y--);
- }
- //功能:ISD1730 SPI驅(qū)動(dòng)函數(shù)
- //輸入:dat:要傳送到ISD1730的數(shù)據(jù)
- //返回:receive:接收的數(shù)據(jù)
- static uchar ISD1760_Spio(uchar dat)
- {
- uchar i;
- // uchar recevice;
- ISD1760_SCLK_L; //SCLK==0
- ENISD1760_SS ;//為低選擇當(dāng)前設(shè)備,并開(kāi)啟SPI
- for (i=0; i<8; i++)
- //將dat字節(jié)的8個(gè)位數(shù)據(jù)一一送到MOSI線上
- {
- ISD1760_SCLK_L;
- //先將SCLK拉低
- // if(dat&0x01==0x01)
- if(dat&0x01)//先發(fā)低位
- {
- ISD1760_MOSI_H; //輸入到1760 上升沿輸入
- }
- else
- {
- ISD1760_MOSI_L;
- //MOSI和MISO信號(hào)同時(shí)改變數(shù)據(jù),但有前后關(guān)系如:左程序
- }
- dat>>=1;
- // ISD1760_delay(1);
- // ISD1760_SCLK_H;
- // ISD1760_delay(1);
- // recevice>>=1;
- if(ISD1760_MISO == 1)
- {
- dat|=0x80;
- }
- ISD1760_SCLK_H;
- // ISD1760_SCLK_L;
- //SCLK來(lái)一個(gè)上升沿鎖存MOSI信號(hào)
- }
- ISD1760_MOSI_L;
- //非忙線時(shí)MOSI要拉低
- return(dat);
- }
- //功能:ISD1730上電操作
- static void ISD1760_PU(void)
- {
- DISENISD1760_SS;
- ISD1760_delay(1);
- ISD1760_SCLK_H;
- ISD1760_delay(1);
- ISD1760_MOSI_L;
- ISD1760_delay(1);
- ENISD1760_SS;
- ISD1760_delay(1);
- SR0L = ISD1760_Spio(PU); //發(fā)送命令字節(jié)
- SR0H = ISD1760_Spio(0x00); //發(fā)送數(shù)據(jù)字節(jié)1
- DISENISD1760_SS;
- ISD1760_delay(10);
- }
- //功能:寫入APC參數(shù)
- void ISD1760_Write_APC2(void)
- {
- DISENISD1760_SS;
- ISD1760_delay(1);
- ISD1760_SCLK_H;
- ISD1760_delay(1);
- ISD1760_MOSI_L;
- ISD1760_delay(1);
- ENISD1760_SS;
- ISD1760_delay(1);
- //SPI總線準(zhǔn)備好
- SR0L = ISD1760_Spio(WR_APC2); //發(fā)送命令字節(jié)
- SR0H = ISD1760_Spio(0x40); //發(fā)送數(shù)據(jù)字節(jié)1
- // SR0H = ISD1760_Spio(0x70); //發(fā)送數(shù)據(jù)字節(jié)1
- SR1 = ISD1760_Spio(0x0C);
- DISENISD1760_SS; //一個(gè)命令完畢
- ISD1760_delay(10);
- }
- //功 能: 取出當(dāng)前語(yǔ)音的首末地址
- void GetToneAdd(uchar NUM, uint *ipStartAdd, uint *ipEndAdd)
- {
- uint caToneAdd[]={
- 0x0010,0x0020, 0x0021, 0x0031,0x0032,0x0042,
- 0x0043,0x0058
- //0x0010,0x00ff//
- };
- *ipStartAdd=caToneAdd[NUM*2];
- *ipEndAdd=caToneAdd[NUM*2+1];
- }
- //定點(diǎn)地址播放
- void ISD1760_Set_Play(uchar VOICE_NUM)
- {
- uint Add_ST, Add_ED; //ST起始地址,ED結(jié)束地址
- uchar Add_ST_H, Add_ST_L, Add_ED_H, Add_ED_L;
- //起始地址高8位,起始地址低8位,結(jié)束地址高8位,結(jié)束地址低8位
- GetToneAdd( VOICE_NUM, &Add_ST, &Add_ED);
- Add_ST_L=(uchar)(Add_ST&0x00ff);
- Add_ST_H=(uchar)((Add_ST>>8)&0x00ff);
- Add_ED_L=(uchar)(Add_ED&0x00ff);
- Add_ED_H=(uchar)((Add_ED>>8)&0x00ff);
- DISENISD1760_SS;
- ISD1760_delay(1);
- ISD1760_SCLK_H;
- ISD1760_delay(1);
- ISD1760_MOSI_L;
- ISD1760_delay(1);
- ENISD1760_SS;
- ISD1760_delay(1);
- //發(fā)送命令
- SR0L = ISD1760_Spio(SET_PLAY);
- //發(fā)送命令字節(jié)
- SR0H = ISD1760_Spio(0x00);
- //發(fā)送數(shù)據(jù)字節(jié)1
- SR1 = ISD1760_Spio(Add_ST_L);
- //發(fā)送數(shù)據(jù)字節(jié)2,放音起始地址低8位<S7:S0>
- SR2 = ISD1760_Spio(Add_ST_H);
- //發(fā)送數(shù)據(jù)字節(jié)3,放音起邕地址高3位<S10:S8>,ISD1730不用
- SR0H = ISD1760_Spio(Add_ED_L);
- //發(fā)送數(shù)據(jù)字節(jié)4,放音結(jié)束地址低8位<E7:E0>
- SR0H = ISD1760_Spio(Add_ED_H);
- //發(fā)送數(shù)據(jù)字節(jié)5,放音結(jié)束地址低8位<E10:E8>,ISD1730不用
- SR0H = ISD1760_Spio(0x00);
- //發(fā)送數(shù)據(jù)字節(jié)6 DISENISD1730_SS; //
- ISD1760_delay(10);
- }
- //功能:ISD1730下電命令
- void ISD1760_PD(void)
- {
- DISENISD1760_SS;
- ISD1760_delay(1);
- ISD1760_SCLK_H;
- ISD1760_delay(1);
- ISD1760_MOSI_L;
- ISD1760_delay(1);
- ENISD1760_SS;
- ISD1760_delay(1);
- SR0L = ISD1760_Spio(PD);
- //發(fā)送命令字節(jié)
- SR0H = ISD1760_Spio(0x00);
- //發(fā)送數(shù)據(jù)字節(jié)1
- DISENISD1760_SS;
- ISD1760_delay(10);
- }
- //功能:播放指定的語(yǔ)音信息
- //輸入:voice_num,語(yǔ)音索引編號(hào)(第幾段:0 第一段,1第二段。。。)
- void ISD1760_PLAY(uchar voice_name)
- {
- ISD1760_PU(); // delay10ms(5);
- ISD1760_delay(5);
- ISD1760_Set_Play(voice_name); // delay10ms(350);
- ISD1760_delay(50);
- ISD1760_PD(); // delay10ms(15);
- ISD1760_delay(5);
- }
- //功能: 停止
- void ISD_Stop(void)
- {
- ENISD1760_SS;
- ISD1760_Spio(STOP); //停止當(dāng)前操作
- ISD1760_Spio(0x00);
- DISENISD1760_SS;
- ISD1760_delay(50);
- }
- //功能: 掉電
- void ISD_PD(void)
- {
- ENISD1760_SS;
- ISD1760_Spio(PD); //Power down 掉電
- ISD1760_Spio(0x00);
- DISENISD1760_SS;
- ISD1760_delay(50);
- }
- void keyscan()
- {
- if(s1==0)
- {
- ISD1760_delay(10);
- if(s1==0)
- {
- ISD1760_PLAY(0) ; //歡迎光臨
- ISD_PD();
- ISD_Stop();
- led =~led;ISD1760_delay(3000);
- }
- }
- if(s2==0)
- {
- ISD1760_delay(10);
- if(s2==0)
- {
- ISD1760_PLAY(1) ;//你好請(qǐng)避讓
- ISD_PD();
- ISD_Stop();
- led =~led;ISD1760_delay(3000);
- }
- }
- if(s3==0)
- {
- ISD1760_delay(10);
- if(s3==0)
- {
- ISD1760_PLAY(2) ; //你好這是你點(diǎn)的菜謝謝
- ISD_PD();
- ISD_Stop();
- led =~led;ISD1760_delay(3000);
- }
- }
- if(s4==0)
- {
- ISD1760_delay(10);
- if(s4==0)
- {
- ISD1760_PLAY(3) ; //歡迎再次光臨再見(jiàn)
- ISD_PD();
- ISD_Stop();
- led =~led;ISD1760_delay(3000);
- }
- }
- }
- void main(void)
- {
- // ISD1760_Write_APC2(); //設(shè)置芯片模擬輸入方式:模擬寄存器APC2
- while(1)
- {
- ISD1760_Write_APC2();
- keyscan();
- }
- }
復(fù)制代碼
用STC12C5A60S2單片機(jī)驅(qū)動(dòng)ISD1760語(yǔ)音模塊實(shí)現(xiàn)分段播放所錄得語(yǔ)音。首先自己先把要播放的語(yǔ)音錄下在用單片機(jī)驅(qū)動(dòng)模塊進(jìn)行定點(diǎn)播放。 |
|