#include <mega16.h>
#include <ISD1760.H>
typedef unsigned char uchar;
typedef unsigned int uint;
//unsigned char flag=0x00;
/*ISD1760状态寄存器及各个标志位定义*/
uchar SR0_L; //SR0寄存器
uchar SR0_H;
uchar SR1; //SR1寄存器
uchar APCL=0,APCH=0;//APC寄存器
uchar PlayAddL=0,PlayAddH=0;//放音指针低位,高位
uchar RecAddL=0,RecAddH=0;//录音指针低位,高位
//延时程序(ms)
void delay (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<143;j++);
}
//spi主机发送
unsigned char ISD_SendData(uchar cData)
{
SS_L; //片选信号使能
SPDR=cData;//启动数据传输
while(!SPSR&(1<<SPIF));//等待数据发送结束
return SPDR;
}
/*ISD1760上电*/
void ISD_PU(void)
{
ISD_SendData(0x01); //发送PU命令
ISD_SendData(0x00);
SS_H;
}
/*ISD1760下电*/
void ISD_PD(void)
{
ISD_SendData(0x07); //发送PD命令
ISD_SendData(0x00);
SS_H;
}
/*停止当前操作*/
void ISD_STOP(void)
{
ISD_SendData(0x02); //发送STOP命令
ISD_SendData(0x00);
SS_H;
}
/*ISD1760复位*/
void ISD_Reset(void)
{
ISD_SendData(0x03); //发送RESET命令
ISD_SendData(0x00);
SS_H;
}
/*清除中断标志*/
void ISD_Clr_Int(void)
{
ISD_SendData(0x04);
ISD_SendData(0x00);
SS_H;
}
/*ISD1760放音*/
void ISD_Play(void)
{
ISD_Reset();////
ISD_PU();///////
ISD_SendData(0x40); //发送放音命令
ISD_SendData(0x00);
SS_H;
}
/*定点播放*/
void ISD_SET_PLAY(uchar Saddl,uchar Saddh,uchar Eaddl, uchar Eaddh)
{
ISD_SendData(0x80);
ISD_SendData(0x00);
ISD_SendData(Saddl); //开始地址低8位
ISD_SendData(Saddh); //开始地址高8位
ISD_SendData(Eaddl); //结束地址低8位
ISD_SendData(Eaddh); //结束地址高8位
ISD_SendData(0x00);
SS_H;
}
/*ISD1760录音*/
void ISD_Rec(void)
{
ISD_SendData(0x41); //发送录音命令
ISD_SendData(0x00);
SS_H;
}
/*定点录音*/
void ISD_SET_Rec(uchar Saddl,uchar Saddh,uchar Eaddl, uchar Eaddh)
{
ISD_SendData(0x81);
ISD_SendData(0x00);
ISD_SendData(Saddl); //开始地址低8位
ISD_SendData(Saddh); //开始地址高8位
ISD_SendData(Eaddl); //结束地址低8位
ISD_SendData(Eaddh); //结束地址高8位
ISD_SendData(0x00);
SS_H;
}
/*ISD1760擦除*/
void ISD_Erase(void)
{
ISD_SendData(0x42); //发送擦除命令
ISD_SendData(0x00);
SS_H;
}
/*定点擦除*/
void ISD_SET_Erase(uchar Saddl,uchar Saddh,uchar Eaddl, uchar Eaddh)
{
ISD_SendData(0x82);
ISD_SendData(0x00);
ISD_SendData(Saddl); //开始地址低8位
ISD_SendData(Saddh); //开始地址高8位
ISD_SendData(Eaddl); //结束地址低8位
ISD_SendData(Eaddh); //结束地址高8位
ISD_SendData(0x00);
SS_H;
}
/*ISD1760全体擦除*/
void ISD_G_Erase(void)
{
ISD_SendData(0x43); //发送全体擦除命令
ISD_SendData(0x00);
SS_H;
}
/*读取状态寄存器内容*/
void ISD_Rd_Status(void)
{
unsigned char i;
ISD_SendData(0x05); //发送
ISD_SendData(0x00);
ISD_SendData(0x00);
SS_H;
for(i=2;i>0;i--); //延迟
SR0_L=ISD_SendData(0x05); //从MISO读出状态
SR0_H=ISD_SendData(0x00);
SR1=ISD_SendData(0x00);
SS_H;
}
/*读取放音指针*/
void ISD_Rd_Playptr(void)
{
uchar i;
ISD_SendData(0x06); //发送
ISD_SendData(0x00);
ISD_SendData(0x00);
ISD_SendData(0x00);
SS_H;
for(i=2;i>0;i--); //延迟
SR0_L=ISD_SendData(0x06); //从MISO读出状态
SR0_H=ISD_SendData(0x00);
PlayAddL=ISD_SendData(0x00); //读取放音指针低8位
PlayAddH=ISD_SendData(0x00); //读取放音指针高8位
SS_H;
}
/*读取录音指针*/
void ISD_Rd_Recptr(void)
{
uchar i;
ISD_SendData(0x08); //发送
ISD_SendData(0x00);
ISD_SendData(0x00);
ISD_SendData(0x00);
SS_H;
for(i=2;i>0;i--); //延迟
SR0_L=ISD_SendData(0x08); //从MISO读出状态
SR0_H=ISD_SendData(0x00);
RecAddL=ISD_SendData(0x00); //读录音指针低8位
RecAddH=ISD_SendData(0x00); //读录音指针高8位
SS_H;
}
/*将APC数据写入NVCFG寄存器中*/
void ISD_WR_NVCFG(uchar apcdatl,uchar apcdath)
{
ISD_SendData(0x46);
ISD_SendData(apcdatl); //发送低8位数据
ISD_SendData(apcdath); //发送高8位数据
SS_H;
}
/*将NVCFG数据写入APC寄存器中*/
void ISD_LD_NVCFG(void)
{
ISD_SendData(0x47);
ISD_SendData(0x00);
SS_H;
}
/*放音指针下跳一段,指向下一段语音的起始地址*/
void ISD_FWD(void)
{
ISD_SendData(0x48);
ISD_SendData(0x00);
SS_H;
}
/*空间检查*/
void ISD_CHK_MEM(void)
{
ISD_SendData(0x49);
ISD_SendData(0x00);
SS_H;
}
/*启用/关闭 外部时钟模式*/
void ISD_EXTCLK(void)
{
ISD_SendData(0x4a);
ISD_SendData(0x00);
SS_H;
}
/*读取APC寄存器内容*/
unsigned char ISD_Devid(void)
{
uchar DeviceNO,i;
ISD_SendData(0x09); //发送
ISD_SendData(0x00);
ISD_SendData(0x00);
SS_H;
for(i=2;i>0;i--); //延迟
ISD_SendData(0x09);
ISD_SendData(0x00);
DeviceNO=ISD_SendData(0x00);
SS_H;
return DeviceNO;
}
/*设置APC2*/
void ISD_WR_APC2(uchar apcdatl,uchar apcdath)
{
ISD_SendData(0x65);
ISD_SendData(apcdatl); //发送低8位数据
ISD_SendData(apcdath); //发送高8位数据
SS_H;
}
/*ISD1760初始化*/
void ISD_Init(void)
{
unsigned char i=2;
do
{
ISD_PU(); //上电
delay(50);
ISD_Rd_Status(); //读取状态
}
while(CMD||(!PU)); //if(CMD_Err==1)||(PU!=1)则再次发送上电指令
ISD_WR_APC2(0x40,0x04); //将0x0440写入APC寄存器,此时语音提示关
do
{
ISD_Rd_Status();
} //等待RDY置位1
while (RDY==0);
do
{
LED_ON;
delay(300);
LED_OFF;
delay(300);
i--;
}
while(i>0);
// ISD_Clr_Int();//////////////
}
//SPI通信初始化
void Spi_Init()
{
// DDRB &=0X0F;
DDRB|=0xB0;//PB7,5,4设置为输出
PORTB = 0XD0;
SPCR=0x7F;//主机模式,LSB先发送,fosc/128
//SPCR=0x7C;
}
以上是.C文件 ISD1760的驱动,在网上找的
下面是主函数 .h文件就不写了
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
?Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
Project : ISD1760
Version : V1.0
Date : 2013/12/10
Author : QIANG
Company : RE
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <spi.h>
#include <ISD1760.H>
#include <delay.h>
void main(void)
{
unsigned char i;
DDRA = 0X01;
PORTA = 0XFF;
DDRD = 0XFF;
PORTD = 0XFF;
LED_ON;
Spi_Init();
PORTD &=0XFE;
ISD_Init();
PORTD &=0XFC;
delay_ms(100);
SREG = 0X00;
ISD_Play();
while(1)
{
}
}
|