路过的大神帮我看看以下程序 体谅一下我只有3分而已
帮我设计main()主程序的内容:(1)按S1录音,同时LCD1602显示录音中的字样;(2)按 S2放音,同时lcd1602显示放音字样;(3)按一下S3擦除一段录音,按住3秒全部擦除录音;按S4是选段
#include<reg51.h>
#include <sound.h>
#include <ISD1700.h>
#define ui unsigned int
#define uc unsigned char
#define ISD1700_PU 0x01
#define ISD1700_STOP 0X02
#define ISD1700_REST 0x03
#define ISD1700_CLR_INT 0x04
#define ISD1700_RD_STAUS 0x05
#define ISD1700_RD_PLAY_PTR 0x06
#define ISD1700_PD 0x07
#define ISD1700_RD_REC_PTR 0x08
#define ISD1700_DEVID 0x09
#define ISD1700_PLAY 0x40
#define ISD1700_REC 0x41
#define ISD1700_ERASE 0x42
#define ISD1700_G_ERASE 0x43
#define ISD1700_RD_APC 0x44
#define ISD1700_WR_APC1 0x45
#define ISD1700_WR_APC2 0x65
#define ISD1700_WR_NVCFG 0x46
#define ISD1700_LD_NVCFG 0x47
#define ISD1700_FWD 0x48
#define ISD1700_CHK_MEM 0x49
#define ISD1700_EXTCLK 0x4A
#define ISD1700_SET_PLAY 0x80
#define ISD1700_SET_REC 0x81
#define ISD1700_SET_ERASE 0x82
#define NULL 0x00
#define ISD_LED 0x10
uc code table[]="HUAN YING SHI YON";
uc code table1[]="KU YING ZHONG";
uc code table2[]="FEN YING ZHONG";
sbit s1=P1^4;
sbit s2=P1^4;
sbit s3=P1^5;
sbit s4=P1^6;
sbit EN=P3^5;
sbit RW=P3^1;
sbit RS=P3^0;
uc RunLedTime;
bit play标志寄存器;
bit re_fig;
sbit ISD_SS=P1^0;
sbit ISD_SCLK=P1^1;
sbit ISD_MOSI=P1^2;
sbit ISD_MISO=P1^3;
uc data ISD_COMM_RAM[7];
uc data ISD_COMM_RAM_C[7];
uc data *isd_comm_ptr;
uc data *back_data_ptr;
void isd1700_par2_comm(uc comm_par, ui data_par);
void isd1700_Npar_comm(uc comm_par,comm_byte_count); //no parameter comm
void isd1700_7byte_comm(uc comm_par, ui star_addr, ui end_addr);
void spi_pu (void);
void spi_stop (void);
void spi_Rest ( void );
void spi_CLR_INT(void);
void spi_RD_STAUS(void);
void spi_RD_play_ptr(void);
void spi_pd(void);
void spi_RD_rec_ptr(void);
void spi_devid(void);
void spi_play(void);
void spi_rec (void);
void spi_erase (void);
void spi_G_ERASE (void);
void spi_rd_apc(void);
void spi_wr_apc1 (void);
void spi_wr_apc2 (void);
void spi_wr_nvcfg (void);
void spi_ld_nvcfg (void);
void spi_fwd (void);
void spi_chk_mem(void);
void spi_CurrRowAddr(void);
void seril_back_sate(uc byte_number);
void spi_set_opt(uc spi_set_comm);
void rest_isd_comm_ptr(void);
void initISD(void);
uc num;
void delay(ui z)
{ ui x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com (uc com)
{ delay(15);
RS=0;
P2=com;
delay(5);
EN=1;
delay(5);
EN=0;
}
void write_data(uc date)
{ RS =1;
P2=date;
delay(5);
EN=1;
delay(5);
EN=0;
}
void init()
{ EN=0;
write_com(0x38);
write_com(0x01);
write_com(0x0f);
write_com(0x06);
write_com(0x80+0x10);
for(num=0;num<17;num++)
{write_data(table[num]);
delay(20); }
}
//SPI接口函数
uc T_R_comm_byte( uc comm_data )
{
uc bit_nuber;
uc temp;
bit_nuber=0;
temp=0;
do{
ISD_SCLK=0;
delay(1);
if((comm_data>>bit_nuber&0x01)!=0)
{ISD_MOSI=1;}
else
{ISD_MOSI=0;}
if(ISD_MISO)
{temp=(temp>>1)|0x80;}
else
{temp=temp>>1;}
ISD_SCLK=1;
delay(1);
}while(++bit_nuber<=7);
ISD_MOSI=0;
return (temp);
}
//设置函数
void spi_set_opt(uc spi_set_comm)
{
ui start_addr,end_addr;
RI=0;
while(!RI);
start_addr=SBUF;
start_addr=start_addr<<8;
RI=0;
while(!RI);
start_addr|=SBUF;
RI=0;
while(!RI);
end_addr=SBUF;
end_addr=start_addr<<8;
RI=0;
while(!RI);
end_addr|=SBUF;
RI=0;
ISD_SS=0;
isd1700_7byte_comm(spi_set_comm, start_addr, end_addr);
ISD_SS=1;
}
//器件上电
void spi_pu (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_PU,2);
ISD_SS=1;
}
//器件停止
void spi_stop (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_STOP,2);
ISD_SS=1;
ISD_COMM_RAM_C[0]=ISD1700_STOP ;
seril_back_sate(1);
}
//器件复位
void spi_Rest (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_REST,2);
ISD_SS=1;
}
//清楚EOM标志
void spi_CLR_INT(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_CLR_INT,2);
ISD_SS=1;
}
//器件状态
void spi_RD_STAUS(void)
{ uc i;
ISD_SS=0;
isd1700_Npar_comm(ISD1700_RD_STAUS,3);
ISD_SS=1;
i=ISD_COMM_RAM_C[1];
//j=ISD_COMM_RAM_C[2];
ISD_COMM_RAM_C[1]=ISD_COMM_RAM_C[0];
ISD_COMM_RAM_C[0]=i;
seril_back_sate(3);
}
//当前地址
void spi_CurrRowAddr(void)
{ uc i;
ISD_SS=0;
isd1700_Npar_comm(ISD1700_RD_STAUS,3);
ISD_SS=1;
i=ISD_COMM_RAM_C[1];
ISD_COMM_RAM_C[1]=ISD_COMM_RAM_C[0]>>5|ISD_COMM_RAM_C[1]<<3;
ISD_COMM_RAM_C[0]= i >>5;
seril_back_sate(3);
}
//读播放地址
void spi_RD_play_ptr(void)
{ uc i;
ISD_SS=0;
isd1700_Npar_comm(ISD1700_RD_PLAY_PTR,4);
ISD_SS=1;
i=ISD_COMM_RAM_C[3]&0x03;
ISD_COMM_RAM_C[3]=ISD_COMM_RAM_C[2];
ISD_COMM_RAM_C[2]=i;
seril_back_sate(4);
}
//器件掉电
void spi_pd(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_PD,2);
ISD_SS=1;
}
//读录音地址
void spi_RD_rec_ptr(void)
{ uc i;
ISD_SS=0;
isd1700_Npar_comm(ISD1700_RD_REC_PTR,4);
ISD_SS=1;
i=ISD_COMM_RAM_C[3]&0x03;
ISD_COMM_RAM_C[3]=ISD_COMM_RAM_C[2];
ISD_COMM_RAM_C[2]=i;
seril_back_sate(4);
}
//器件ID
void spi_devid(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_DEVID,3);
ISD_SS=1;
ISD_COMM_RAM_C[2]=ISD_COMM_RAM_C[2]&0xf8;
seril_back_sate(3);
}
//播放当前
void spi_play(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_PLAY|ISD_LED,2);
ISD_SS=1;
}
//开始录音
void spi_rec (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_REC|ISD_LED,2);
ISD_SS=1;
ISD_COMM_RAM_C[0]=ISD1700_REC ;
seril_back_sate(1);
}
//擦除当前
void spi_erase (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_ERASE|ISD_LED,2);
ISD_SS=1;
}
//擦除全部
void spi_G_ERASE (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_G_ERASE|ISD_LED,2);
ISD_SS=1;
}
//返回状态寄存器信息
void spi_rd_apc(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_RD_APC,4);
ISD_SS=1;
seril_back_sate(4);
}
//写寄存器
void spi_wr_apc1 (void)
{
}
void spi_wr_apc2 (void)
{
ISD_SS=0;
isd1700_par2_comm(ISD1700_WR_APC2, 0x0400);
ISD_SS=1;
}
//将APC内容写入NVCFG
void spi_wr_nvcfg (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_WR_NVCFG,2);
ISD_SS=1;
}
////将NVCFG内容写入APC
void spi_ld_nvcfg (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_LD_NVCFG ,2);
ISD_SS=1;
}
//下一段
void spi_fwd (void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_FWD,2);
ISD_SS=1;
}
//检查环状存储体
void spi_chk_mem(void)
{
ISD_SS=0;
isd1700_Npar_comm(ISD1700_CHK_MEM,2);
ISD_SS=1;
}
//状态返回
void seril_back_sate(uc byte_number)
{
uc sate_temp;
rest_isd_comm_ptr();
sate_temp=0;
do{
SBUF=*back_data_ptr++;
while(!TI);
TI=0;
}while(++sate_temp<byte_number);
}
//复位
void rest_isd_comm_ptr(void)
{
isd_comm_ptr=ISD_COMM_RAM;
back_data_ptr=ISD_COMM_RAM_C;
}
//无参数命令
void isd1700_Npar_comm (uc comm_par,comm_byte_count)
{
uc i;
i=0;
ISD_COMM_RAM[0]=comm_par;
isd_comm_ptr=&ISD_COMM_RAM[1];
do{
*isd_comm_ptr++=NULL;
}while(++i<comm_byte_count-1);
rest_isd_comm_ptr();
i=0;
do{
*back_data_ptr++=T_R_comm_byte(*isd_comm_ptr++);
i++;
}while(i<comm_byte_count);
}
//2个字节命令
void isd1700_par2_comm(uc comm_par, ui data_par)
{
uc i;
ISD_COMM_RAM[0]=comm_par;
ISD_COMM_RAM[1]=data_par;
ISD_COMM_RAM[2]=data_par>>8;
rest_isd_comm_ptr();
i=0;
do{
*back_data_ptr++=T_R_comm_byte(*isd_comm_ptr++);
i++;
}while(i<3);
}
//7个字节命令
void isd1700_7byte_comm(uc comm_par, ui star_addr, ui end_addr)
{
uc i;
ISD_COMM_RAM[0]=comm_par;
ISD_COMM_RAM[1]=NULL;
ISD_COMM_RAM[2]=star_addr;
ISD_COMM_RAM[3]=star_addr>>8;
ISD_COMM_RAM[4]=end_addr;
ISD_COMM_RAM[5]=end_addr>>8;
ISD_COMM_RAM[6]=NULL;
rest_isd_comm_ptr();
i=0;
do{
*back_data_ptr++=T_R_comm_byte(*isd_comm_ptr++);
i++;
}while(i<=7);
}
//串口通信接口函数
void comm_sate(void)
{
uc sate_temp;
ui apc_temp;
if(RI)
{ sate_temp=SBUF;
if(sate_temp==0x09)
{ spi_devid();}
if(sate_temp==0x44)
{spi_rd_apc();}
if(sate_temp==0x40)
{spi_play();}
if(sate_temp==0x04)
{spi_CLR_INT();}
if(sate_temp==0x05)
{spi_RD_STAUS();}
if(sate_temp==0x43)
{ spi_G_ERASE();}
if(sate_temp==0x01)
{ spi_pu ();}
if(sate_temp==0x02)
{ spi_stop();}
if(sate_temp==0x03)
{ spi_Rest ();}
if(sate_temp==0x06)
{spi_RD_play_ptr();}
if(sate_temp==0x07)
{spi_pd();}
if(sate_temp==0x08)
{ spi_RD_rec_ptr();}
if(sate_temp==0x41)
{ spi_rec();}
if(sate_temp==0x42)
{ spi_erase();}
if(sate_temp==0x45)
{spi_wr_apc1 ();}
if(sate_temp==0x65)
{ spi_wr_apc2 ();}
if(sate_temp==0x46)
{ spi_wr_nvcfg ();}
if(sate_temp==0x47)
{ spi_ld_nvcfg ();}
if(sate_temp==0x48)
{ spi_fwd ();}
if(sate_temp==0x49)
{ spi_chk_mem();}
if(sate_temp==0x60)
{ spi_CurrRowAddr();}
if(sate_temp==0x80)
{
spi_set_opt(ISD1700_SET_PLAY|ISD_LED);
//spi_set_opt(ISD1700_SET_PLAY);
}
if(sate_temp==0x81)
{
spi_set_opt(ISD1700_SET_REC|ISD_LED);
//spi_set_opt(ISD1700_SET_REC);
ISD_COMM_RAM_C[0]=ISD1700_SET_REC ;
seril_back_sate(1);
}
if(sate_temp==0x82)
{
spi_set_opt(ISD1700_SET_ERASE|ISD_LED);
//spi_set_opt(ISD1700_SET_ERASE);
}
if(sate_temp==ISD1700_WR_APC2)
{
RI=0;
while(!RI);
apc_temp=SBUF;
apc_temp=apc_temp<<8;
RI=0;
while(!RI);
apc_temp|=SBUF;
RI=0;
ISD_SS=0;
isd1700_par2_comm(ISD1700_WR_APC2,apc_temp);
ISD_SS=1;
}
RI=0;
}
if(re_fig)
{
rest_isd_comm_ptr();
sate_temp=0;
do{
SBUF=*back_data_ptr++;
while(!TI);
TI=0;
}while(++sate_temp<=2);
re_fig=0;
}
}
void initISD(void)
{
TMOD=0x21;
SCON=0x50;
TL0=0x00; //25ms
TH0=0x70; //25ms
TH1=0xE8;
TL1=0xE8; //12M/1200bit/s/E6 11.0592M/E8
ET0=1;
EA=1;
TR0=1;
TR1=1;
IT0 = 0;
EX0 = 1;
spi_pu();
P3 = 0xff;
RunLedTime = 25;
}
void int0(void) interrupt 0
{
play标志寄存器 = 1; //播放标志位置1,允许播放
}
void tim0_sever(void) interrupt 1
{
TL0=0x00;
TH0=0x70; //重新赋初值
if(RunLedTime != 0)
{
if( --RunLedTime == 0)
{
RunLedTime = 25;
}
}
}
void main()
{ init();
initISD();
if(s1==1)
{ delay(5);
if(s1==1)
{ for(num=0;num<13;num++)
{write_data(table1[num]);
delay(5);
}
spi_play();
}
while(!s1);
delay(5);
while(!s1);
}
if(s2==0)
{ delay(5);
if(s2==0)
{ for(num=0;num<14;num++)
{write_data(table2[num]);
delay(20);
}
}
while(!s2);
delay(5);
while(!s2);
}
else
{ for(num=0;num<17;num++)
{write_data(table[num]);
delay(20);
}
}
while (1);
}
D:\Altium Designer14.3.15\新建文件夹\新建文件夹
|