isd4004与stc89C52对应脚怎么接?请大神指点,以下是录音笔图纸及代码,都是复制别人的
制作出来实物图如下:
单片机源程序如下:
- // 以ISD4004-8录音时间为8分钟,即8*60=480S根据4004的资料,480秒可分为2400段,也就是1S的段数为
- // 5段,即从,0000-0005H的内容为1秒。0X0000-0X012C ;0X012D-0X0258;0X259-0X0384;0X0385-0X04B0.
- #include <reg52.h>
- #include <intrins.h>
- #include"1602.c"
- #include"eeprom.h"
- #define uchar unsigned char
- #define uint unsigned int
- 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从当前地址开始录音
- sbit SCLK=P3^7;
- sbit SS=P3^6; //LOW IS ACTIVELY
- sbit MOSI=P3^5;
- //sbit MISO=P3^4;
- sbit K1=P1^2;
- sbit K2=P1^3;
- sbit K3=P1^4; //按键输入
- sbit LED1=P1^0;
- sbit LED2=P1^1; //指示灯
- uchar aa,bb,cc,dd,ee;
- uchar num_rec=0;
- void delayms(uchar ms);
- uchar playcout,reccout; //放音和录音次数。
- ////////////////放音部分子程序,放音地址由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;
- 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; }
- //////////////////////////lu音部分子程序,地址由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 stop()
- {
- 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 delayms(uchar ms)
- // 延时子程序
- {
- uchar j;
- while(ms--)
- {
- for(j = 0; j < 120; j++);
- }
- }
- ////////////////////////////////
- void playsound() ///录放音子函数
- {
- if(playbit)
- {
- playbit=0;
- switch(playcout)
- { ///////////====每段60S=====////////////////
- case 0x01:{play(0x0000);LCD_write_str(0,0,"NUM:1 Playing ");}break; //此处第一段音乐的开始地址为0X00,到0X012d地址结束,约为60秒。
- case 0x02:{play(0x012d);LCD_write_str(0,0,"NUM:2 Playing ");}break;
- case 0x03:{play(0x0259);LCD_write_str(0,0,"NUM:3 Playing ");}break;
- case 0x04:{play(0x0385);LCD_write_str(0,0,"NUM:4 Playing ");}break;
- }
- }
- if(recbit)
- {
- recbit=0;
- switch(reccout)
- {
- case 0x01:{rec(0x0000); LCD_write_str(0,0,"NUM:1 Recording");aa=1;}break;
- case 0x02:{rec(0x012d);LCD_write_str(0,0,"NUM:2 Recording");aa=1;}break;
- case 0x03:{rec(0x0259);LCD_write_str(0,0,"NUM:3 Recording");aa=1;}break;
- case 0x04:{rec(0x0385);LCD_write_str(0,0,"NUM:4 Recording");aa=1;}break;
- }
- }
- }
- bit key_bit1=0,key_bit2=0;
- uchar num11;
- uchar play_count=4,rec_count=4;
- ////////////////////////////////////
- void keyscan() //直控键盘扫描子程序。
- {
- if(K1==0)
- {
- while(K1==0);
- key_bit1=1;
- recbit=1;
- reccout++;
- LED2=0;LED1=1;
- if(reccout>rec_count) //
- reccout=1;
- }
- if(K2==0&&key_bit2==0)
- {
- while(K2==0);
- key_bit1=1;
- playbit=1;
- playcout++;
- LED1=0;LED2=1;
- if(playcout>play_count)
- playcout=1;
- // reccout=num_rec;
- }
- if(K3==0&&key_bit1==1)
- {
- while(K3==0);
- stop();
- LED2=1;
- LED1=1;
- if(aa==1){
- num_rec++;
- aa=0;
- if(num_rec>4){
- num_rec=1;
- key_bit1=0;
- }
- }
- ISP_ERASE(0x2c00); //注意:字节编程时必须要先要擦除整个扇区
- ISP_PROGRAM(0x2c00, num_rec); //写入eeprom 掉电保存
- ISP_PROGRAM(0x2c01, reccout);
- play_count=num_rec; //保存播放的段数
- reccout=num_rec; //从第几段录起
- LCD_write_str(0,0," ");
- key_bit1=0;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- if(K3==0&&key_bit1==0) //选择播放哪段
- {
- while(K3==0&&key_bit1==0);
- key_bit2=1;
- num11++;
- if(num11>play_count)
- {
- num11=0;
- bb=0;cc=0;dd=0;
- key_bit2=0;
- LCD_write_str(0,0," ");
- }
- switch(num11)
- {
- case 1:{LCD_write_str(0,0,"NUM:1 Rec ");bb=1;cc=0;dd=0;ee=0;}break;
- case 2:{LCD_write_str(0,0,"NUM:2 Rec ");bb=0;cc=1;dd=0;ee=0;}break;
- case 3:{LCD_write_str(0,0,"NUM:3 Rec ");cc=0;bb=0;dd=1;ee=0;}break;
- case 4:{LCD_write_str(0,0,"NUM:4 Rec ");cc=0;bb=0;dd=0;ee=1;}break;
- }
- }
- if(bb==1){
- if(K2==0&&key_bit2==1)
- {
- while(K2==0);
- key_bit1=1;
- play(0x0000);
- LCD_write_str(0,0,"NUM:1 Playing ");
- }
- }
- if(cc==1){
- if(K2==0&&key_bit2==1)
- {
- while(K2==0);
- key_bit1=1;
- play(0x012d);
- LCD_write_str(0,0,"NUM:2 Playing ");
- }
- }
- if(dd==1){
- if(K2==0&&key_bit2==1)
- {
- while(K2==0);
- key_bit1=1;
- play(0x0259);
- LCD_write_str(0,0,"NUM:3 Playing ");
- }
- }
- if(ee==1){
- if(K2==0&&key_bit2==1)
- {
- while(K2==0);
- key_bit1=1;
- play(0x0385);
- LCD_write_str(0,0,"NUM:4 Playing ");
- }
- }
- }
- ////////////////////////////////////////////////
- /////////以下部分为主程序///////////////////
- void main()
- {
- num_rec = ISP_READ(0x2c00); //保存数值回读
- reccout = ISP_READ(0x2c01);
- play_count=num_rec; //保存条数
- init1602(); //液晶初始化
- LCD_write_str(0,1,"N:");
- stop();
- while(1)
- {
- keyscan(); //按键扫描
- playsound(); //录播放
- Write_num(0xC2,num_rec); //显示条数
- }
- }
|