📄 audio.c
字号:
//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指令,使放音继续
PLAY 11110xxx(xxxxxxxxxxxxxxx) 从当前地址开始放音(直至
EOM或OVF)
SET REC 10110xxx(A15~A0) 从指定地址开始录
音,须后跟REC指令,使录音继续
REC 110110(xxxxxxxxxxxxxxx) 从当前地址开始录
音(直至OVF或停止)
SET MC 11101xxx(A15~A0) 从指定地址开始快
进,须后跟MC指令,使快进继续
MC 11111xxx(xxxxxxxxxxxxxxx) 执行快进,直到
EOM,若再无信息,则进入OVF状态
STOP 0x110xxx(xxxxxxxxxxxxxxx) 停止当前操作
STOP PWRDN 0X01Xxxx(xxxxxxxxxxxxxxx) 停止当前的操作并掉电
RINT 0X110xxx(xxxxxxxxxxxxxxxx) 读状态;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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -