#include <intrins.h>
#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char
//=========ISD4004--c51接口定义=================
//sbit ISD_SS = P3^0; //片选
//sbit ISD_MOSI = P3^1; //数据输入
//sbit ISD_SCLK = P3^3; //ISD4004 时钟
//sbit ISD_INT = P3^4; //溢出中断
//sbit ISD_RAC = P3^5; //行地址时钟
//sbit ISD_MISO = P3^2; //数据输出
sbit SS=P3^0; //LOW IS AC
tiVELY
sbit MOSI=P3^1;
sbit MISO=P3^2;
sbit SCLK=P3^3;
unsigned char playcout,reccout;
//定义两个位变量,放音和录音位
bit playbit,recbit;
////////定义放音命令,定义常量//////
#define ISDPOWERUP 0X20 //ISD4004上电
#define ISDSTOP 0X10 //ISD4004下电
#define OPERSTOP 0X30 //ISD4004停止当前操作
#define PLAYSET 0XE0 //ISD4004从指定地址开始放音
#define PLAYCUR 0XF0 //ISD4004从当前地址开始放音
#define RECSET 0XA0 //ISD4004从指定地址开始录音
#define RECCUR 0XB0 //ISD4004从当前地址开始录音
// 延时子程序
void delayms(uint ms)
{
uchar j;
while(ms--)
{
for(j = 0; j < 120; j++);
}
}
//放音部分子程序,放音地址由ADDR决定
void play(uint addr)
{
uint y;
SS=0;
MOSI=0;//发送开始
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0x20>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}//发送结束
SS=1;//上电结束
delayms(50);
SS=0;
MOSI=0;//发送地址
SCLK=0;
for(y=0;y<16;y++)
{
SCLK=0;
if((addr>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}//发送地址结束
MOSI=0;//放音
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0xe0>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}
SS=1;
delayms(50);
delayms(50);
SS=0;
MOSI=0;//放音
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0xf0>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}
SS=1;
}
//录音部分子程序,地址由ADDR决定
void rec(addr)
{ uint y;
SS=0;
MOSI=0;//发送开始
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0x20>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}//发送结束
SS=1;//上电结束
delayms(50);
SS=0;
MOSI=0;//发送开始
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0x20>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}//发送结束
SS=1;//上电结束
delayms(50);
delayms(50);
SS=0;
MOSI=0;//发送地址
SCLK=0;
for(y=0;y<16;y++)
{
SCLK=0;
if((addr>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}//发送地址结束
MOSI=0;
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0xa0>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}
SS=1;
SS=0;
MOSI=0;
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0xb0>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}
SS=1;
}
//停止子程序
void DDstop()
{
uchar y;
SS=1;
SS=0;
MOSI=0;//放音
SCLK=0;
for(y=0;y<8;y++)
{
SCLK=0;
if((0x30>>y)&0x01)MOSI=1;
else MOSI=0;
_nop_();
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
_nop_();
}
SS=1;
}
//录放音子函数
void playsound()
{
//放音
if(playbit==1)
{
playbit=0;
switch(playcout)
{
case 0x01:{play(0x00);}break; //0 //此处第一段音乐的开始地址为0X00,到0X100地址结束,约为51秒。
case 0x02:{play(0x025);}break;//1
case 0x03:{play(0x050);}break;//2
case 0x04:{play(0x075);}break;//3
case 0x05:{play(0x100);}break;//4
case 0x06:{play(0x125);}break;//5
case 0x07:{play(0x150);}break;//6
case 0x08:{play(0x175);}break;//7
case 0x09:{play(0x200);}break;//8
case 0x0A:{play(0x225);}break;//9
case 0x0B:{play(0x250);}break;//10
case 0x0C:{play(0x275);}break;//20
case 0x0D:{play(0x300);}break;//30
case 0x0E:{play(0x325);}break;//40
case 0x0F:{play(0x350);}break;//50
case 0x10:{play(0x375);}break;//60
case 0x11:{play(0x400);}break;//70
case 0x12:{play(0x425);}break;//80
case 0x13:{play(0x450);}break;//90
case 0x14:{play(0x475);}break;//.
case 0x15:{play(0x500);}break;//度
}
}
//录音
else if(recbit==1)
{
recbit=0;
switch(reccout)
{
case 0x01:{rec(0x00);}break; //0 //此处第一段音乐的开始地址为0X00,到0X100地址结束,约为51秒。
case 0x02:{rec(0x025);}break;//1
case 0x03:{rec(0x050);}break;//2
case 0x04:{rec(0x075);}break;//3
case 0x05:{rec(0x100);}break;//4
case 0x06:{rec(0x125);}break;//5
case 0x07:{rec(0x150);}break;//6
case 0x08:{rec(0x175);}break;//7
case 0x09:{rec(0x200);}break;//8
case 0x0A:{rec(0x225);}break;//9
case 0x0B:{rec(0x250);}break;//10
case 0x0C:{rec(0x275);}break;//20
case 0x0D:{rec(0x300);}break;//30
case 0x0E:{rec(0x325);}break;//40
case 0x0F:{rec(0x350);}break;//50
case 0x10:{rec(0x375);}break;//60
case 0x11:{rec(0x400);}break;//70
case 0x12:{rec(0x425);}break;//80
case 0x13:{rec(0x450);}break;//90
case 0x14:{rec(0x475);}break;//.
case 0x15:{rec(0x500);}break;//度
}
}
}
if(K1==0) //K1键按下。录音
{
while(K1 == 0);
LCD_disp_char(0x0d,0,0x31);
LCD_disp_char(0x0f,0,0x30+playcout);
playbit=0;
recbit=1;
playsound();
delay_2S();
delay_2S();
DDstop();
delayms(100);
//开始放音
playbit=1;
recbit=0;
playsound();
delay_2S();
delay_2S();
DDstop();
LCD_disp_char(0x0d,0,0x30);
playcout++;
if(playcout>9)
playcout = 0;
}
//============================K2放音键================================
if(K2==0 || K3 == 0)
{
while(K2 == 0||K3==0);
LCD_disp_char(0x0d,1,0x31);
LCD_disp_char(0x0f,1,0x30+playcout);
playbit=1;
recbit=0;
playsound();
delay_2S();
delay_2S();
DDstop();
LCD_disp_char(0x0d,1,0x30);
playcout++;
if(playcout>9) playcout = 0;
}
一周热门 更多>