程序如下
#include<reg52.h>
#include<sound.h>
#include<isd1700.h>
#define uchar unsigned char
#define uint unsigned int
sbit ISD_SS=P0^7;
sbit ISD_MISO=P0^4;
sbit ISD_MOSI=P0^5;
sbit ISD_SCLK=P0^6;
sbit RUN_LED=P1^0;
uchar data ISD_COMM_RAM[7];
uchar data ISD_COMM_RAM_C[7];
uchar data *isd_comm_ptr;
uchar data *back_data_ptr;
void delay(int x);
void rest_isd_comm_ptr(void);
uchar T_R_comm_byte( uchar comm_data );
void isd1700_par2_comm(uchar comm_par, uint data_par);
void isd1700_Npar_comm(uchar comm_par,comm_byte_count); //no parameter comm
void isd1700_7byte_comm(uchar comm_par, uint star_addr, uint end_addr);
void spi_pu (void);
void spi_stop (void);
void init(void);
void PlaySoundTick(uchar number);
/***********器件初始化****************************/
void init(void)
{
ISD_MOSI=0; //isd1700 spi control line init
spi_pu(); //ISD语音芯片上电
RUN_LED=0;
}
void spi_pu (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_PU,2);
ISD_SS=1;
}
void spi_stop (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_STOP,2); //isd1700 spi power up
ISD_SS=1;
}
void rest_isd_comm_ptr(void)
{
isd_comm_ptr=ISD_COMM_RAM;
back_data_ptr=ISD_COMM_RAM_C;
}
void isd1700_Npar_comm (uchar comm_par,comm_byte_count)//no parameter comm
{
uchar i;
i=0;
ISD_COMM_RAM[0]=comm_par;
isd_comm_ptr=&ISD_COMM_RAM[1];
do{
*isd_comm_ptr++=NULL;
}while(++i<comm_byte_count-1);
rest_isd_comm_ptr();
i=0;
do{
*back_data_ptr++=T_R_comm_byte(*isd_comm_ptr++);
i++;
}while(i<comm_byte_count);
}
void isd1700_7byte_comm(uchar comm_par, uint star_addr, uint end_addr)
{
uchar i;
ISD_COMM_RAM[0]=comm_par;
ISD_COMM_RAM[1]=NULL;
ISD_COMM_RAM[2]=star_addr;
ISD_COMM_RAM[3]=star_addr>>8;
ISD_COMM_RAM[4]=end_addr;
ISD_COMM_RAM[5]=end_addr>>8;
ISD_COMM_RAM[6]=NULL;
rest_isd_comm_ptr();
i=0;
do{
*back_data_ptr++=T_R_comm_byte(*isd_comm_ptr++);
i++;
}while(i<=7);
}
uchar T_R_comm_byte( uchar comm_data )
{
uchar bit_nuber;
uchar temp;
bit_nuber=0;
temp=0;
do{
ISD_SCLK=0;
delay(1);
if((comm_data>>bit_nuber&0x01)!=0)
{ISD_MOSI=1;}
else
{ISD_MOSI=0;}
if(ISD_MISO)
{temp=(temp>>1)|0x80;}
else
{temp=temp>>1;}
ISD_SCLK=1;
delay(1);
}while(++bit_nuber<=7);
ISD_MOSI=0;
return (temp);
}
void delay(int x)
{
uchar i;
for(; x>=1; x--)
{for(;i<=20;i++);}
}
void delay_isd(uint time)
{
while(time--!=0);
}
/*****************获取语音段始末地址*****************/
void GetSound(uchar soundtick)
{
ISD_SS=0;
switch(soundtick)
{
case 0:{ isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED, sound_0A, sound_0B); }break;
case 1:{ isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED, sound_1A, sound_1B); }break;
case 2:{ isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED, sound_2A, sound_2B); }break;
case 3:{ isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED, sound_3A, sound_3B); }break;
default: break;
}
ISD_SS=1;
}
/*****************播放指定的语音段*****************/
void PlaySoundTick(uchar number)
{
spi_stop ();
delay_isd(30000);
GetSound(number);
}
/***********主函数****************************/
void main(void)
{
init(); //器件初始化
while(1)
{
PlaySoundTick(0); //播放0
delay(30000);
PlaySoundTick(1); //播放1
delay(30000);
PlaySoundTick(2); //播放2
delay(30000);
PlaySoundTick(3); //播放3
delay(30000);
}
}
录的声音地址已放置在sound.h里,程序主要参考了卖家给的程序,驱动程序读的不是很懂,但主程序很简单,请大家指教啦
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>