sbit LED1 = P2^6 ;
sbit LED5 = P3^0 ;
sbit LED6 = P1^7 ;
//
sbit BUTTON1 = P2^0 ;
sbit BUTTON2 = P2^1 ;
//
sbit SCK = P0^1 ;
sbit ISD4002_SS = P0^2 ;
sbit MOSI = P0^3 ;
sbit MISO = P0^4 ;
sbit ISD4002_INT = P0^0 ;
uint addr=0x0000;
uchar adl=0x00;
uchar adh=0x00;
/*
sbit ISD4002_RAC = P1^4 ;
*/
功能函数
*/
//
/* 1 us延时函数 */
void delay(uint t)
{
while(t!=0)
{t--;
}
}
/* 1 ms延时函数 */
delay1ms(uint t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<123;j++)
;
}
//
//
/*
SPI读/写函数
*/
uchar SPI_rw(uchar dat)
{
uchar i;
ISD4002_SS=0;
SCK = 0;
for(i=0;i<8;i++)
{ if((dat&0x01)==1)
MOSI = 1;
else
MOSI = 0;
dat=dat>>1;
SCK = 1;
delay(2);
SCK = 0;
delay(2);
}
}
/*
ISD4002电源唤醒
*/
void ISD4002_powerup(void)
{
delay(10);
SPI_rw(0x20);
ISD4002_SS = 1;
delay1ms(50);
}
void ISD4002_pd(void)
{
delay(10);
SPI_rw(0x10);
ISD4002_SS=1;
delay1ms(50);
}
/*
ISD4002停止命令
*/
void ISD4002_stop(void)
{
delay(10);
SPI_rw(0x30);
ISD4002_SS = 1;
delay1ms(50);
}
/*
ISD4002按地址录音
*/
void ISD4002_record(uchar adl,uchar adh)
{
SPI_rw(adl);
adh=adh|0xa0;
SPI_rw(adh);
ISD4002_SS = 1;
}
/*
ISD4002按地址录音
*/
void ISD4002_rec(void)
{
SPI_rw(0xb0);
ISD4002_SS = 1;
}
# define SPEECH_NUM 5
# define SPEECH_LEN 10
/*
ISD4002 录音程序
*/
void speech_record(uchar adl,uchar adh)
{
SPI_rw(adl);
adh=adh|0xa0;
SPI_rw(adh);
ISD4002_SS = 1;
}
//
void main(void)
{
uchar i;
P0=P1=P2=P3=0xff;
while(1)
{
ISD4002_powerup();
ISD4002_pd();
ISD4002_powerup();
for(i=0;i<5;i++)
{
while(BUTTON1);
delay1ms(100);
ISD4002_record(0x00,0x00);
LED5=0;
ISD4002_rec();
delay1ms(10000);
ISD4002_stop();
LED5=1;
addr=addr+0x32;
adl=addr;
addr=addr>>8;
adh=addr;
}
}
}
程序如上 不知道为什么无法实现控制ISD4002录音 |