资料编号:213
功能介绍:
采用stm32作为主控CPU,LCD1602显示,使用按键模拟出声音传感器,如果检测到声音(相当于按键按下),LED亮起,过一段时间LED熄灭,完美仿真出声控灯的应用场景,并且有声音是LCD1602会显示有人,等人走后,LCD1602显示无人;程序采用C语言,有中文注释,比较容易看懂,仿真采用Proteus,全套仿真资料齐全:
![](https://img-blog.csdnimg.cn/img_convert/4861d38fd03475654001f2e152442254.png)
程序部分展示:(有中文注释,新手容易看懂)
#define LED PAout(3)
#define KEY1 PAin(8)
#define KEY2 PAin(9)
#define KEY3 PAin(10)
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能P端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //LED0 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //输出高
}
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义结构体变量
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
int main(void)
{
int a,b,c,d;
int temp;
delay_init(); //延时函数初始化
LCD1602_Init();
ADC1_GPIO_Config();
ADC_Config();
LED_Init();
KEY_Init();LCD1602_ShowStr(1,0," wu ren ",7);//默认无人显示程序
b=0;
while(1)
{
if(KEY2==0)
{
LED=1;
LCD1602_ShowStr(1,0,"you ren ",7);//有人显示程序
b=1;
}
if(b==1)
{
a++;delay_ms(100);//调节延时时间
}
if(a>60000&&KEY2==1)
{
a=0;b=0;
LED=0;
LCD1602_ShowStr(1,0," wu ren ",7);//无人显示程序
}
}
}
![](https://img-blog.csdnimg.cn/img_convert/23a6499e6627d0737140d6dd72c94d26.png)
![](https://img-blog.csdnimg.cn/img_convert/d9e703e3249a020accdf4ce5465acc40.png)