由STM32F103C8T6和ISD1820,LCD1602,按键模块组成的录音设备,写一下ISD1820这一部分代码,并做出具体的解释,
时间: 2023-09-20 21:11:40 浏览: 101
ISD1820是一款语音录放模块,它可以通过模拟输入控制语音的录制、播放、停止等功能。下面是一个简单的示例代码:
```c
#include <reg52.h>
#define KEY P1
sbit REC = P2^0;
sbit PLAY = P2^1;
sbit DELAY = P2^2;
sbit LED = P2^3;
void delay(unsigned int i)
{
while(i--);
}
void write_cmd(unsigned char cmd)
{
P3 = cmd;
KEY = 0x02;
delay(100);
KEY = 0x00;
}
void write_data(unsigned char dat)
{
P3 = dat;
KEY = 0x03;
delay(100);
KEY = 0x01;
}
void init_lcd()
{
write_cmd(0x38);
write_cmd(0x0c);
write_cmd(0x06);
write_cmd(0x01);
}
void display_string(unsigned char x, unsigned char y, unsigned char *s)
{
unsigned char i;
if(x > 15 || y > 1) return;
if(y == 0) y = 0x80;
else y = 0xc0;
y += x;
write_cmd(y);
i = 0;
while(s[i] != '\0')
{
write_data(s[i]);
i++;
}
}
void main()
{
REC = 1;
PLAY = 1;
DELAY = 1;
LED = 0;
init_lcd();
display_string(0, 0, "Recording...");
while(1)
{
if(REC == 0)
{
LED = 1;
display_string(0, 1, "Recording...");
write_cmd(0x01);
write_cmd(0x80);
write_data('R');
write_data('E');
write_data('C');
write_data('O');
write_data('R');
write_data('D');
write_data('I');
write_data('N');
write_data('G');
delay(1000);
LED = 0;
display_string(0, 1, "Record done.");
write_cmd(0x01);
write_cmd(0x80);
write_data('R');
write_data('E');
write_data('C');
write_data('O');
write_data('R');
write_data('D');
write_data(' ');
write_data('D');
write_data('O');
write_data('N');
write_data('E');
delay(1000);
write_cmd(0x01);
}
if(PLAY == 0)
{
LED = 1;
display_string(0, 1, "Playing...");
write_cmd(0x01);
write_cmd(0x80);
write_data('P');
write_data('L');
write_data('A');
write_data('Y');
write_data('I');
write_data('N');
write_data('G');
delay(1000);
LED = 0;
display_string(0, 1, "Play done.");
write_cmd(0x01);
write_cmd(0x80);
write_data('P');
write_data('L');
write_data('A');
write_data('Y');
write_data(' ');
write_data('D');
write_data('O');
write_data('N');
write_data('E');
delay(1000);
write_cmd(0x01);
}
if(DELAY == 0)
{
LED = 1;
display_string(0, 1, "Delaying...");
write_cmd(0x01);
write_cmd(0x80);
write_data('D');
write_data('E');
write_data('L');
write_data('A');
write_data('Y');
write_data('I');
write_data('N');
write_data('G');
delay(1000);
LED = 0;
display_string(0, 1, "Delay done.");
write_cmd(0x01);
write_cmd(0x80);
write_data('D');
write_data('E');
write_data('L');
write_data('A');
write_data('Y');
write_data(' ');
write_data('D');
write_data('O');
write_data('N');
write_data('E');
delay(1000);
write_cmd(0x01);
}
}
}
```
上述代码中,我们使用了LCD1602显示模块来显示当前录音状态,按键模块来控制录音、播放和延时功能。
在录音功能中,我们通过判断REC按键是否按下,来进入录音状态,并通过LED指示灯和LCD1602模块显示当前状态。在录音完成后,同样通过LED指示灯和LCD1602模块显示录音完成。
在播放和延时功能中,同样通过判断PLAY和DELAY按键是否按下,来进入播放和延时状态,并通过LED指示灯和LCD1602模块显示当前状态。在播放或延时完成后,同样通过LED指示灯和LCD1602模块显示操作完成。
ISD1820模块的控制部分,需要使用模拟输入方式控制其录制、播放、停止等功能,我们在代码中并未给出具体的ISD1820模块控制代码。如果需要使用ISD1820模块,可以参考其官方文档或者第三方资料。
阅读全文