?? isd1700.c
字號:
/*
實驗說明:
接線:
1、將模塊上的INT與CPU板上的INT0相連;
2、將模塊上的DO與CPU板上的P11相連;
3、將模塊上的DI與CPU板上的P12相連;
4、將模塊上的CLK與CPU板上的P10相連;
5、將模塊上的SS與CPU板上的P14相連;
6、將試驗箱上開關(guān)KK1的輸出K1與CPU板上的P15相連;
7、將試驗箱上開關(guān)KK2的輸出K2與CPU板上的P16相連;
8、將試驗箱上開關(guān)KK3的輸出K3與CPU板上的P17相連;暫時不用接。
實驗過程:
檢查接線正確無誤后,加電,運行程序ISD1700,將開關(guān)KK1、KK2、KK3撥到低電平側(cè)(L側(cè))
先將KK1撥到H側(cè)并對MIC講話,結(jié)束后將開關(guān)KK1撥回L側(cè)。將撥碼開關(guān)KK2撥到H側(cè),開始放音,直至結(jié)束。
如果想重放,先將開關(guān)KK2撥到L側(cè),在撥到H側(cè),則重復(fù)放音。
*/
#include <reg51.h>
//sbit INT = P1^0; //Port to Receive interrupt signal from ISD1700
sbit DO = P1^1; //Port to Receive data from ISD1700
sbit DI = P1^2; //Port to Sent data to ISD1700
sbit CLK = P1^0; //Output SPI clock
sbit SS = P1^4; //Reset this port to enable SPI of ISD1700
sbit rec = P1^5; //Record from Line In or Mic selected by sel
sbit play = P1^6; //Playing while end
sbit sel = P1^7; //select source of audio
unsigned char PU_cmd[] = {0x01,0x00}; //Power on
unsigned char STOP_cmd[] = {0x02,0x00}; //Stop current operation
unsigned char RESET_cmd[] = {0x03,0x00}; //Stop current operation
unsigned char CLR_INT_cmd[] = {0x04,0x00}; //clearn INT to zero
unsigned char RD_STA_cmd[] = {0x05,0x00,0x0}; //Read status byte
unsigned char RD_PLY_PTR_cmd[] = {0x06,0x00,0x0,0x0}; //Read play point
unsigned char PD_cmd[] = {0x07,0x00}; //Power off
unsigned char RD_REC_PTR_cmd[] = {0x08,0x0,0x0,0x0}; //Read record point
unsigned char DEVID_cmd[] = {0x09,0x0,0x0}; //Read device ID
unsigned char PLAY_cmd[] = {0x40,0x0}; //begin to play here
unsigned char REC_cmd[] = {0x41,0x0}; //begin to record here
unsigned char ERASE_cmd[] = {0x42,0x0}; //Erase the current sigment
unsigned char G_ERASE_cmd[] = {0x43,0x0}; //Erase all chip
unsigned char RD_APC_cmd[] = {0x44,0x0,0x0,0x0}; //Read register APC
unsigned char WR_APC1_dir_cmd[] = {0x45,0x7,0x4}; //Enable mode direct in SPI
unsigned char WR_APC1_mic_cmd[] = {0x45,0x47,0x4}; //Disable mode direct in SPI
unsigned char WR_APC2_cmd[] = {0x65}; //Write config data to APC,refer to function WriteApc(unsigned int dat)
unsigned char FWD_cmd[] = {0x48,0x0}; //Move the current point to next
unsigned char CHK_MEM_cmd[] = {0x49,0x0}; //Check the loop memory
unsigned char EXTCLK_cmd[] = {0x4a,0x0}; //Enable the ext clock
bit idle = 1; //Chip is in idle status
bit recflag = 0; //flag of record
bit audinflag = 0; //flag mode audio in
unsigned char *pStatus; //Status of chip
void Delay(unsigned int time)
{
while(time-->0);
}
void SpiIni(void) //Initialize SPI port
{
SS = 1;
CLK = 1;
DI = 0;
Delay(10);
}
unsigned char WriteByte(unsigned char dat) //write a byte to ISD1700, Read a byte from ISD
{
char num = 8;
unsigned char tmp = 0;
DO = 1;
while(num-->0)
{
CLK = 0;
Delay(20);
DI = (dat&0x1)?1:0;
dat >>=1;
tmp >>= 1;
tmp |= (DO == 0) ? 0x80:0x0;
Delay(20);
CLK = 1;
Delay(80);
}
//Delay(1000);
return tmp;
}
void Write2ISD1700(unsigned char num,unsigned char * pBuff,unsigned char *pReceive) //
{
SS = 0;
while(num-->0)
{
*(pReceive++) = WriteByte(*(pBuff++));
}
SS = 1;
}
void Ext0Inter(void) interrupt 0
{
unsigned char IntClrCmd[] = {0x04,0x0};
idle = 1;
Write2ISD1700(2,IntClrCmd,pStatus); //Clearn INTERRUPT and EOM flag
}
void PlayCurrent(void) //Start to play at current segment
{
while(!idle);
idle = 0;
Write2ISD1700(2,PLAY_cmd,pStatus); //Start to play at current segment
}
void Record(void) //Start to play at current segment
{
while(!idle);
idle = 0;
recflag = 1;
Write2ISD1700(2,REC_cmd,pStatus); //Start to play at current segment
}
void EraseAll(void) //Start to play at current segment
{
while(!idle);
idle = 0;
Write2ISD1700(2,G_ERASE_cmd,pStatus); //Start to play at current segment
}
void Stop(void)
{
Write2ISD1700(2,STOP_cmd,pStatus); //Start to play at current segment
recflag = 0;
}
void AudioSeclect(bit s)
{
if(s) Write2ISD1700(3,WR_APC1_dir_cmd,pStatus);
else Write2ISD1700(3,WR_APC1_mic_cmd,pStatus);
audinflag = 0;
}
void main(void)
{
unsigned char *pDevid,Cmd[] = {0xa5};
bit selbak = 0,selchange = 0;
SpiIni();
IT0 = 1; EX0 = 1; EA=1;
Write2ISD1700(2,RESET_cmd,pStatus); //Reset the chip
Write2ISD1700(2,PU_cmd,pStatus); //Power on
Write2ISD1700(3,DEVID_cmd,pDevid);
EraseAll();
while(1)
{
/*
if(sel != selbak)
{
selbak = sel;
selchange = 1;
}
*/
if(rec&&!play)
{
/*
if(selchange)
{
AudioSeclect(sel);
selchange = 0;
}
*/
Record();
while(rec);
}
if(recflag) Stop();
if(play&&!rec)
{
PlayCurrent();
while(play);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -