#define uchar unsigned char
#define uint unsigned int
//******************定义端口******************//
sbit SS = P1^0
sbit SCK = P1^1
sbit MOSI = P1^2
sbit MISO = P1^3
sbit PR = P1^4//PLAY = 0REC = 1
sbit STOP = P1^5
sbit AN = P1^6
sbit LED = P1^7
//******************定义ISD1700状态寄存器及各标志位******************//
uchar bdata SR0_L//SR0寄存器低位、高位
uchar bdata SR0_H
uchar bdata SR1//SR1寄存器
uchar APC_L = 0, APC_H = 0//APC寄存器
uchar PLAYADDL = 0, PLAYADDH = 0//放音指针低位、高位
uchar RECADDL = 0, RECADDH = 0//录音指针低位、高位
sbit CMD_ERR = SR0_L^0//SPI指令无效标志位
sbit FULL = SR0_L^1//芯片存储空间满标志位
sbit PU = SR0_L^2//上电标志位
sbit EOM 岩裤念= SR0_L^3//EOM标志位
sbit INT = SR0_L^4// *** 作完成标志位
sbit RDY = SR1^0//芯片空闲标志位
sbit ERASE = SR1^1//擦除标志位
sbit PLAY = SR1^2//放音标志位
sbit REC = SR1^3//录音标志位
//******************定义标志位******************//
uchar bdata fang
sbit 粗困PR_fang = fang^1//录音、放音标志位,放音=0,录音=1
sbit Erase_fang = fang^4//擦出标志位
sbit STOP_fang = fang^7//停止放音标志位
//******************延时μs******************//
void delay(uint time)//延时n微秒
{
while(time!=0)
{
time--
}
}
//******************延时ms******************//
void delayms(uint time)//延时n毫秒
{
for(time time>0 time--)
{
TH0 = 0xfc
TL0 = 0x18
TR0 = 1//计数器0启动
纯历 while(TF0!=1)//计数溢出处理
TF0 = 0
TR0 = 0
}
}
//******************CPU初始化******************//
void cpu_init (void)
{
P1 = 0xFF
P2 = 0xFF
P3 = 0xFF
TMOD = 0x01//定时器初始化,工作于方式1
EA = 0//关中断
fang = 0//标志位归0
LED = 1//关指示灯
}
//******************发送、读回数据******************//
uchar isd_senddata (uchar dat)
{
uchar i, BUF_ISD = dat
SS = 0
SCK = 1
delay(4)
for(i=0 i<8 i++)
{
SCK = 0
if((BUF_ISD&0x01)==1)
{
MOSI = 1
}
else
{
MOSI = 0
}
BUF_ISD = BUF_ISD >> 1
if(MISO)
{
BUF_ISD = BUF_ISD|0x80
}
SCK = 1
delay(6)
}
MOSI = 0
return(BUF_ISD)
}
//******************上电******************//
void isd_pu (void)
{
isd_senddata (0x01)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************停止当前 *** 作******************//
void isd_stop (void)
{
isd_senddata (0x02)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************复位******************//
void isd_reset (void)
{
isd_senddata (0x03)
isd_senddata (0x00)
SS = 1
}
//******************清除中断******************//
void isd_clr_int (void)
{
isd_senddata (0x04)
isd_senddata (0x00)
SS = 1
}
//******************读状态寄存器内容******************//
void isd_rd_status (void)
{
isd_senddata (0x05)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x05)
SR0_H = isd_senddata (0x00)
SR1 = isd_senddata (0x00)
SS = 1
}
//******************读放音指针******************//
void isd_rd_playptr (void)
{
isd_senddata (0x06)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x06)
SR0_H = isd_senddata (0x00)
PLAYADDL = isd_senddata (0x00)
PLAYADDH = isd_senddata (0x00)
SS = 1
}
//******************下电******************//
void isd_pd (void)
{
isd_senddata (0x07)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************读录音指针******************//
void isd_rd_recptr (void)
{
isd_senddata (0x08)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x08)
SR0_H = isd_senddata (0x00)
RECADDL = isd_senddata (0x00)
RECADDH = isd_senddata (0x00)
SS = 1
}
//******************读芯片ID******************//
uchar isd_devid (uchar deviceNO)
{
isd_senddata (0x09)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
isd_senddata (0x09)
isd_senddata (0x00)
deviceNO = isd_senddata (0x00)
SS = 1
return(deviceNO)
}
//******************放音******************//
void isd_play (void)
{
isd_senddata (0x40)
isd_senddata (0x00)
SS = 1
}
//******************录音******************//
void isd_rec (void)
{
isd_senddata (0x41)
isd_senddata (0x00)
SS = 1
}
//******************擦除******************//
void isd_erase (void)
{
isd_senddata (0x42)
isd_senddata (0x00)
SS = 1
}
//******************全部擦出******************//
void isd_g_erase (void)
{
isd_senddata (0x43)
isd_senddata (0x00)
SS = 1
}
//******************读APC寄存器内容******************//
void isd_rd_apc (void)
{
isd_senddata (0x44)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x44)
SR0_H = isd_senddata (0x00)
APC_L = isd_senddata (0x00)
APC_H = isd_senddata (0x00)
SS = 1
}
//******************写APC寄存器******************//
void isd_wr_apc2 (uchar apcdatl,apcdath)
{
isd_senddata (0x65)
isd_senddata (apcdatl)
isd_senddata (apcdath)
SS = 1
}
//******************将APC寄存器内容写入NVCFG******************//
void isd_wr_nvcfg (uchar apcdatl,apcdath)
{
isd_senddata (0x46)
isd_senddata (apcdatl)
isd_senddata (apcdath)
SS = 1
}
//******************将NVCFG内容写入APC******************//
void isd_ld_nvcfg (void)
{
isd_senddata (0x47)
isd_senddata (0x00)
SS = 1
}
//******************快进******************//
void isd_fwd (void)
{
isd_senddata (0x48)
isd_senddata (0x00)
SS = 1
}
//******************空检查******************//
void isd_chk_mem (void)
{
isd_senddata (0x49)
isd_senddata (0x00)
SS = 1
}
//******************外部时钟的启用、关闭******************//
void isd_extclk (void)
{
isd_senddata (0x4a)
isd_senddata (0x00)
SS = 1
}
//******************指定地址放音******************//
void isd_set_play (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x80)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************指定地址录音******************//
void isd_set_rec (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x81)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************指定地址擦除******************//
void isd_set_erase (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x82)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************芯片系统初始化******************//
void isd_init (void)
{
uchar i = 2
SS = 1
SCK = 1
MOSI = 0
do
{
isd_pu ()
isd_rd_status ()
}while(CMD_ERR||(!PU))
isd_wr_apc2 (0x40,0x04)
do
{
isd_rd_status ()
}while(RDY==0)
do
{
LED = 0
delayms(300)
LED = 1
delayms(300)
i--
}while(i>0)
}
//******************isd1700的相关 *** 作******************//
void isdwork (void)
{
uchar i
switch (fang)
{
case 0x00:
{
do
{
isd_rd_status ()
}while(RDY==0)
delayms(10)
isd_play ()
delayms(2)
LED = 0
do
{
isd_rd_status ()
if(STOP==0)
{
delayms (10)
if(STOP==0)
{
LED = 1
isd_clr_int ()
isd_stop ()
isd_reset ()
isd_pd ()
isd_init ()
return
}
}
}while(PLAY==1)
LED = 1
isd_clr_int ()
do
{
isd_rd_status ()
}while(RDY==0)
delayms (10)
isd_fwd ()
do
{
isd_rd_status ()
}while(RDY==0)
}
break
case 0x02:
{
isd_clr_int ()
do
{
isd_rd_status ()
}while(RDY==0)
delayms(10)
isd_rec ()
delayms(2)
LED = 0
do
{
isd_rd_status ()
if(FULL==1)
{
for(i=3 i>0 i--)
{
LED = 0
delayms (300)
LED = 1
delayms (200)
}
}
}while(AN==0)
isd_clr_int ()
isd_stop ()
LED = 1
}
break
case 0x10:
{
do
{
isd_rd_status ()
}while(RDY==0)
delayms (10)
isd_g_erase ()
delayms (2)
do
{
isd_rd_status ()
}while(RDY==0)
for(i=3 i>0 i--)
{
LED = 0
delayms (300)
LED = 1
delayms (200)
}
}
break
case 0x80:
{
isd_clr_int ()
isd_stop ()
isd_reset ()
isd_pd ()
}
break
}
}
//******************主程序******************//
void main (void)
{
uchar i
cpu_init ()
delayms (1)
isd_init ()
while(1)
{
if(AN==0)
{
delayms (10)
if(AN==0)
{
if(PR==1)
{
PR_fang = 1
}
else
{
PR_fang = 0
}
isdwork ()
}
}
if(STOP==0)
{
delayms (10)
if(STOP==0)
{
for(i=100 i>0 i--)
{
if(STOP==1)
{
STOP_fang = 1
isdwork ()
isd_init ()
break
}
delayms(30)
}
if (STOP_fang==1)
{
fang = 0
continue
}
Erase_fang = 1
isdwork ()
}
}
}
}
#include <reg51.h>#define uchar unsigned char
#define uint unsigned int
//******************定义端口******************//
sbit SS = P1^0
sbit SCK = P1^1
sbit MOSI = P1^2
sbit MISO = P1^3
sbit PR = P1^4//PLAY = 0REC = 1
sbit STOP = P1^5
sbit AN = P1^6
sbit LED = P1^7
//******************定义ISD1700状态寄存器及各标志位******************//
uchar bdata SR0_L//SR0寄存器低位、高位
uchar bdata SR0_H
uchar bdata SR1//SR1寄存器
uchar APC_L = 0, APC_H = 0//亩穗胡APC寄存器
uchar PLAYADDL = 0, PLAYADDH = 0//放音指针低位、高位迅拦
uchar RECADDL = 0, RECADDH = 0//录音指针低位、高位
sbit CMD_ERR = SR0_L^0//SPI指令无效标志位
sbit FULL = SR0_L^1//芯片存储空间满标志位
sbit PU = SR0_L^2//上电标志位
sbit EOM = SR0_L^3//EOM标志位
sbit INT = SR0_L^4// *** 作完成标志位
sbit RDY = SR1^0//芯片空闲标志位
sbit ERASE = SR1^1//擦除族燃标志位
sbit PLAY = SR1^2//放音标志位
sbit REC = SR1^3//录音标志位
//******************定义标志位******************//
uchar bdata fang
sbit PR_fang = fang^1//录音、放音标志位,放音=0,录音=1
sbit Erase_fang = fang^4//擦出标志位
sbit STOP_fang = fang^7//停止放音标志位
//******************延时μs******************//
void delay(uint time)//延时n微秒
{
while(time!=0)
{
time--
}
}
//******************延时ms******************//
void delayms(uint time)//延时n毫秒
{
for(timetime>0time--)
{
TH0 = 0xfc
TL0 = 0x18
TR0 = 1//计数器0启动
while(TF0!=1)//计数溢出处理
TF0 = 0
TR0 = 0
}
}
//******************CPU初始化******************//
void cpu_init (void)
{
P1 = 0xFF
P2 = 0xFF
P3 = 0xFF
TMOD = 0x01//定时器初始化,工作于方式1
EA = 0//关中断
fang = 0//标志位归0
LED = 1//关指示灯
}
//******************发送、读回数据******************//
uchar isd_senddata (uchar dat)
{
uchar i, BUF_ISD = dat
SS = 0
SCK = 1
delay(4)
for(i=0i<8i++)
{
SCK = 0
if((BUF_ISD&0x01)==1)
{
MOSI = 1
}
else
{
MOSI = 0
}
BUF_ISD = BUF_ISD >>1
if(MISO)
{
BUF_ISD = BUF_ISD|0x80
}
SCK = 1
delay(6)
}
MOSI = 0
return(BUF_ISD)
}
//******************上电******************//
void isd_pu (void)
{
isd_senddata (0x01)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************停止当前 *** 作******************//
void isd_stop (void)
{
isd_senddata (0x02)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************复位******************//
void isd_reset (void)
{
isd_senddata (0x03)
isd_senddata (0x00)
SS = 1
}
//******************清除中断******************//
void isd_clr_int (void)
{
isd_senddata (0x04)
isd_senddata (0x00)
SS = 1
}
//******************读状态寄存器内容******************//
void isd_rd_status (void)
{
isd_senddata (0x05)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x05)
SR0_H = isd_senddata (0x00)
SR1 = isd_senddata (0x00)
SS = 1
}
//******************读放音指针******************//
void isd_rd_playptr (void)
{
isd_senddata (0x06)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x06)
SR0_H = isd_senddata (0x00)
PLAYADDL = isd_senddata (0x00)
PLAYADDH = isd_senddata (0x00)
SS = 1
}
//******************下电******************//
void isd_pd (void)
{
isd_senddata (0x07)
isd_senddata (0x00)
SS = 1
delayms(50)
}
//******************读录音指针******************//
void isd_rd_recptr (void)
{
isd_senddata (0x08)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x08)
SR0_H = isd_senddata (0x00)
RECADDL = isd_senddata (0x00)
RECADDH = isd_senddata (0x00)
SS = 1
}
//******************读芯片ID******************//
uchar isd_devid (uchar deviceNO)
{
isd_senddata (0x09)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
isd_senddata (0x09)
isd_senddata (0x00)
deviceNO = isd_senddata (0x00)
SS = 1
return(deviceNO)
}
//******************放音******************//
void isd_play (void)
{
isd_senddata (0x40)
isd_senddata (0x00)
SS = 1
}
//******************录音******************//
void isd_rec (void)
{
isd_senddata (0x41)
isd_senddata (0x00)
SS = 1
}
//******************擦除******************//
void isd_erase (void)
{
isd_senddata (0x42)
isd_senddata (0x00)
SS = 1
}
//******************全部擦出******************//
void isd_g_erase (void)
{
isd_senddata (0x43)
isd_senddata (0x00)
SS = 1
}
//******************读APC寄存器内容******************//
void isd_rd_apc (void)
{
isd_senddata (0x44)
isd_senddata (0x00)
isd_senddata (0x00)
isd_senddata (0x00)
SS = 1
delay(2)
SR0_L = isd_senddata (0x44)
SR0_H = isd_senddata (0x00)
APC_L = isd_senddata (0x00)
APC_H = isd_senddata (0x00)
SS = 1
}
//******************写APC寄存器******************//
void isd_wr_apc2 (uchar apcdatl,apcdath)
{
isd_senddata (0x65)
isd_senddata (apcdatl)
isd_senddata (apcdath)
SS = 1
}
//******************将APC寄存器内容写入NVCFG******************//
void isd_wr_nvcfg (uchar apcdatl,apcdath)
{
isd_senddata (0x46)
isd_senddata (apcdatl)
isd_senddata (apcdath)
SS = 1
}
//******************将NVCFG内容写入APC******************//
void isd_ld_nvcfg (void)
{
isd_senddata (0x47)
isd_senddata (0x00)
SS = 1
}
//******************快进******************//
void isd_fwd (void)
{
isd_senddata (0x48)
isd_senddata (0x00)
SS = 1
}
//******************空检查******************//
void isd_chk_mem (void)
{
isd_senddata (0x49)
isd_senddata (0x00)
SS = 1
}
//******************外部时钟的启用、关闭******************//
void isd_extclk (void)
{
isd_senddata (0x4a)
isd_senddata (0x00)
SS = 1
}
//******************指定地址放音******************//
void isd_set_play (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x80)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************指定地址录音******************//
void isd_set_rec (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x81)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************指定地址擦除******************//
void isd_set_erase (uchar saddl,saddh,eaddl,eaddh)
{
isd_senddata (0x82)
isd_senddata (0x00)
isd_senddata (saddl)
isd_senddata (saddh)
isd_senddata (eaddl)
isd_senddata (eaddh)
isd_senddata (0x00)
SS = 1
}
//******************芯片系统初始化******************//
void isd_init (void)
{
uchar i = 2
SS = 1
SCK = 1
MOSI = 0
do
{
isd_pu ()
isd_rd_status ()
}while(CMD_ERR||(!PU))
isd_wr_apc2 (0x40,0x04)
do
{
isd_rd_status ()
}while(RDY==0)
do
{
LED = 0
delayms(300)
LED = 1
delayms(300)
i--
}while(i>0)
}
//******************isd1700的相关 *** 作******************//
void isdwork (void)
{
uchar i
switch (fang)
{
case 0x00:
{
do
{
isd_rd_status ()
}while(RDY==0)
delayms(10)
isd_play ()
delayms(2)
LED = 0
do
{
isd_rd_status ()
if(STOP==0)
{
delayms (10)
if(STOP==0)
{
LED = 1
isd_clr_int ()
isd_stop ()
isd_reset ()
isd_pd ()
isd_init ()
return
}
}
}while(PLAY==1)
LED = 1
isd_clr_int ()
do
{
isd_rd_status ()
}while(RDY==0)
delayms (10)
isd_fwd ()
do
{
isd_rd_status ()
}while(RDY==0)
}
break
case 0x02:
{
isd_clr_int ()
do
{
isd_rd_status ()
}while(RDY==0)
delayms(10)
isd_rec ()
delayms(2)
LED = 0
do
{
isd_rd_status ()
if(FULL==1)
{
for(i=3i>0i--)
{
LED = 0
delayms (300)
LED = 1
delayms (200)
}
}
}while(AN==0)
isd_clr_int ()
isd_stop ()
LED = 1
}
break
case 0x10:
{
do
{
isd_rd_status ()
}while(RDY==0)
delayms (10)
isd_g_erase ()
delayms (2)
do
{
isd_rd_status ()
}while(RDY==0)
for(i=3i>0i--)
{
LED = 0
delayms (300)
LED = 1
delayms (200)
}
}
break
case 0x80:
{
isd_clr_int ()
isd_stop ()
isd_reset ()
isd_pd ()
}
break
}
}
//******************主程序******************//
void main (void)
{
uchar i
cpu_init ()
delayms (1)
isd_init ()
while(1)
{
if(AN==0)
{
delayms (10)
if(AN==0)
{
if(PR==1)
{
PR_fang = 1
}
else
{
PR_fang = 0
}
isdwork ()
}
}
if(STOP==0)
{
delayms (10)
if(STOP==0)
{
for(i=100i>0i--)
{
if(STOP==1)
{
STOP_fang = 1
isdwork ()
isd_init ()
break
}
delayms(30)
}
if (STOP_fang==1)
{
fang = 0
continue
}
Erase_fang = 1
isdwork ()
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)