您的位置:首页技术文栏单片机C51
内容搜索:
阅读内容
背景:#EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  

ISD4000系列语音芯片的C51程序

[日期:2008-05-07 ] [来源:东哥单片机学习网(www.picavr.com) 作者:佚名] [字体: (投递新闻)
//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
阅读:
录入:JETTA

推荐 】 【 打印
本文评论
      全部评论
发表评论


点评: 字数
姓名:
站长推荐