|
//ISD4004 DRIVER
#include"mcu-define.h" #include"delay.h" #include"isd4004.h"
sbit ISD4XXX_SCLK=P3^6; sbit ISD4XXX_MISO =P3^4; sbit ISD4XXX_MOSI =P3^5; sbit ISD4XXX_SS =P3^7;
//ISD4004 命令碼 /* 指令 8位控制碼,16位地址碼 操作摘要 POWERUP 00100xxx(xxxxxxxxxxxxxxxx) 上電:等待TPUD后器件可以工作 SET PLAY 11100xxx(A15~A0) 從指令地址開始放音,須后跟PLAY指令,使放音繼續(xù) PLAY 11110xxx(xxxxxxxxxxxxxxx) 從當前地址開始放音(直至EOM或OVF) SET REC 10110xxx(A15~A0) 從指定地址開始錄音,須后跟REC指令,使錄音繼續(xù) REC 110110(xxxxxxxxxxxxxxx) 從當前地址開始錄音(直至OVF或停止) SET MC 11101xxx(A15~A0) 從指定地址開始快進,須后跟MC指令,使快進繼續(xù) MC 11111xxx(xxxxxxxxxxxxxxx) 執(zhí)行快進,直到EOM,若再無信息,則進入OVF狀態(tài) STOP 0x110xxx(xxxxxxxxxxxxxxx) 停止當前操作 STOP PWRDN 0X01Xxxx(xxxxxxxxxxxxxxx) 停止當前的操作并掉電 RINT 0X110xxx(xxxxxxxxxxxxxxxx) 讀狀態(tài);OVF和EOM
*/ #define ISD4XXX_POWER_UP 0x20 #define ISD4XXX_SET_PLAY 0xe0 #define ISD4XXX_PLAY 0xf0 #define ISD4XXX_SET_REC 0xb0 #define ISD4XXX_REC 0xd8 #define ISD4XXX_SET_MC 0xe8 #define ISD4XXX_MC 0xf8 #define ISD4XXX_STOP 0x30 #define ISD4XXX_STOP_PWRDN 0x10
#define ISD4XXX_RINT 0x30
unsigned char isd_spi(ISD_COMMAND * isdcommand) { unsigned char i; unsigned long miso; unsigned long mosi=(unsigned long *)isdcommand; ISD4XXX_MISO=1; ISD4XXX_SCLK=0; ISD4XXX_SS=0; miso=0; for (i=0;i<24;i++) { miso<<=1; miso |=(unsigned long )ISD4XXX_MISO;
if (mosi & 0x800000 ==0x1) ISD4XXX_MOSI =1; else ISD4XXX_MOSI = 0;
ISD4XXX_SCLK=1; mosi <<= 1; ISD4XXX_SCLK=0; } ISD4XXX_SCLK=1;
return (char *)(miso+1); }
void ISD4XXX_Record(unsigned int address) { // 1. power up // 2. TPUD(25ms) *2; // 3. power up; // 4. set record address = 00; // 5. rec command . ISD_COMMAND isd_command; isd_command.command_code=ISD4XXX_POWER_UP; // isd_command.int_address=0; isd_spi(&isd_command); soft_delay_10ms(3); soft_delay_10ms(3);
isd_spi(&isd_command);
isd_command.command_code=ISD4XXX_SET_REC; isd_command.int_address=address; isd_spi(&isd_command);
isd_command.command_code=ISD4XXX_REC ; // isd_command.int_address=0; isd_spi(&isd_command); }
void ISD4XXX_Play(unsigned int address) { // 1. POWER UP // 2. Delay tpuid. // 3. SET PLAY WITH ADDRESS 0; // 4. SEND play command. ISD_COMMAND isd_command; isd_command.command_code=ISD4XXX_POWER_UP; // isd_command.int_address=0; isd_spi(&isd_command); soft_delay_10ms(3);
isd_command.command_code=ISD4XXX_SET_PLAY; isd_command.int_address=address; isd_spi(&isd_command);
isd_command.command_code=ISD4XXX_PLAY; // isd_command.int_address=0; isd_spi(&isd_command); }
void ISD4XXX_Stop(void) { ISD_COMMAND isd_command; isd_command.command_code=ISD4XXX_STOP; isd_spi(&isd_command); }
void ISD4XXX_PowerOff(void) { ISD_COMMAND isd_command; isd_command.command_code=0x08; isd_spi(&isd_command); }
void ISD4XXX_PowerOn(void) { ISD_COMMAND isd_command; isd_command.command_code=0x04; isd_spi(&isd_command); }
static code unsigned int address_tab[22]= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
void PlaySound(unsigned char index) {
ISD4XXX_Play(address_tab[index]); } //end of file
|