📄 isd4003.c
字号:
/*************************************************************/
/* isd4003.c */
/* 2001.10.25 designed by Wang XuanQiang */
/*************************************************************/
#pragma CODE DEBUG SYMBOLS OBJECTEXTEND
#include <reg51.h>
#include <absacc.h>
#include <isd4003.h>
void delay (void) /* 延时 */
{
uint xdata i,j; /*delay 1/2ms*/
for(i = 0; i < 1000; i++)
{
j = (i * 2) / 2;
}
}
void transmit_serial (void) /* */
{
uchar xdata i;
for (i = 0;i < 4;i++)
{
SBUF = transmit_buf[i];
while (TI==0);
TI=0;
}
}
void isd4003_write (uint command) /* 发送命令 */
{
uint i,j,k;
i = command;
S_CS = 0;
j = 0;
S_CLK = 0;
for(k = 0;k < 16;k++)
{
S_IN = i & 0x01;
j = 0;
S_CLK = 1;
j = 0;
S_CLK = 0;
i = (i >> 1);
}
S_CS = 1;
delay();
}
void isd4003_read (void) /* 读取命令 */
{
uchar xdata i,j;
S_CS = 0;
j = 0;
temp = 0;
S_CLK = 0;
for(i = 0;i < 16;i++)
{
S_CLK = 1;
j = 0;
S_CLK = 0;
if(S_OUT)
temp = (temp << 1) + 1;
else
temp = (temp << 1);
S_CLK = 0;
}
S_CS = 1;
temp = (temp >> 4) & 0x0fff;
r_addr = 0;
for(i = 0;i < 10;i++)
{
temp = temp >> 1;
c_flag = temp & 0x01;
if(c_flag == 0x01)
r_addr = (r_addr << 1) + 1;
else
r_addr = (r_addr << 1);
}
delay();
}
void init_manage(void)
{
uint xdata temp2;
if((init_flag == 1) && (duan_num != 7))
{
temp2 = 0x2000;
isd4003_write(temp2);
temp2 = duan_addr[duan_num];
temp2 = temp2 + 0xe000;
isd4003_write(temp2);
temp2 = 0xf000;
isd4003_write(temp2);
PLAY_LED = 0;
duan_num++;
}
else
{
init_flag = 0;
duan_num = 0;
transmit_buf[0] = 0xbb;
transmit_buf[1] = 0x0;
transmit_buf[2] = 0x0;
transmit_buf[3] = 0x0;
transmit_serial();
c_temp = 0x1000;
isd4003_write(c_temp);
isd4003_read();
delay();
delay();
delay();
transmit_buf[0] = 0xbb;
transmit_buf[1] = 0x1;
transmit_buf[2] = (r_addr >> 8);
transmit_buf[3] = (r_addr & 0xff);
transmit_serial();
PLAY_LED = 1;
REC_LED = 1;
}
}
void manage_command (void) /**/
{
uchar xdata temp1;
uint xdata temp2;
if(command_data[0] == 0xaa)
{
temp1 = command_data[1];
switch (temp1)
{
case 0: /* 从设定地址开始放音 */
temp2 = 0x2000;
isd4003_write(temp2);
temp2 = ((command_data[2] << 8) + command_data[3]) & 0x7ff;
temp2 = temp2 + 0xe000;
isd4003_write(temp2);
temp2 = 0xf000;
isd4003_write(temp2);
PLAY_LED = 0;
break;
case 1: /* 快进到某一段 */
temp2 = 0x2000;
isd4003_write(temp2);
temp2 = duan_addr[duan_num];
temp2 = temp2 + 0xe000;
isd4003_write(temp2);
temp2 = 0xf000;
isd4003_write(temp2);
PLAY_LED = 0;
duan_num++;
init_flag = 1;
break;
case 2: /* 从设定地址开始录音 */
temp2 = 0x2000;
isd4003_write(temp2);
temp2 = ((command_data[2] << 8) + command_data[3]) & 0x7ff;
temp2 = temp2 + 0xa000;
isd4003_write(temp2);
temp2 = 0xb000;
isd4003_write(temp2);
REC_LED = 0;
break;
case 3: /* 读取一个段的结束地址 */
isd4003_read();
break;
case 4: /* 芯片上电 */
temp2 = 0x2000;
isd4003_write(temp2);
transmit_buf[0] = 0xbb;
transmit_buf[1] = 0x0;
transmit_buf[2] = 0x0;
transmit_buf[3] = 0x0;
transmit_serial();
break;
case 5: /* 停止当前操作 */
init_manage();
break;
default:
temp2 = 0x1000;
isd4003_write(temp2);
break;
}
}
}
void extract_command (void)/**/
{
uchar xdata temp;
while(c_bottom != c_top)
{
for(temp = 0;temp < 4;temp++)
command_data[temp] = command_buf[((temp + c_top) & 0xff)];
manage_command();
c_top = (c_top + 4) & 0xff;
}
}
void init_var () /* */
{
uint xdata temp;
duan_num = 0;
c_bottom = 0;
c_top = 0;
ms50_num = 0;
flag_50ms = 0;
flag_1s = 0;
c_flag = 0;
r_addr = 0;
temp = 0;
init_flag = 0;
for(temp = 0;temp < 4;temp++)
{
command_data[temp] = 0;
transmit_buf[temp] = 0;
}
for(temp = 0;temp < 256;temp++)
command_buf[temp] = 0;
}
void serial () interrupt 4 using 3 /*串口中断*/
{
uchar xdata temp;
EA = 0;
if(RI)
{
RI = 0;
temp=SBUF;
command_buf[c_bottom] = temp;
c_bottom = (c_bottom + 1) & 0xff;
}
EA = 1;
}
void intt() interrupt 1 using 2 /*定时器0中断处理 */
{
xdata uint m;
EA = 0;
TH0=0xa0;
TL0=0x00;
ms50_num++;
flag_50ms = 1;
if(ms50_num > 10)
{
flag_1s = 1;
ms50_num = 0;
}
EA=1;
}
void main ()
{
IE = 0;
P1 = 0xff;
P1 = 0x0;
P1 = 0xff;
S_IN = 0;
S_CS = 1;
S_CLK = 0;
init_var();
c_temp = 0x2000;
isd4003_write(c_temp);
delay();
SCON = 0x50;/* 设置串口 */
TMOD = 0x21;/* SCON 工作方式1 10位异步收发 允许接收串口数据 */
TCON = 0x69;/* 定时器1为工作方式2 自动重装载8位定时器 定时器0为工作方式1 16位定时器 */
TH1 = 0xfa;/* TCON 定时器1启动 定时器1溢出标志置1 外部中断0,1置1 */
TL1 = 0xfa; /* TH1 0xe8h 1.2k 0xfa 4.8k 0xfd 9.6k */
PCON = 0;
TH0 = 0xa0;
TL0 = 0x00;
TCON = 0x50;/* 定时器0,1同时启动 */
IE = 0x92;
while(1)
{
if(flag_50ms == 1)
{
flag_50ms = 0;
if(P_INT == 0)
init_manage();
if(flag_1s == 0x01)
{
flag_1s = 0;
RUN_LED = !RUN_LED;
extract_command();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -