YL-56声音检测模块

YL-56可以检测声音的有无,工作在3.3-5v,灵敏度可调(通过调节电位器),该模块有三个口,VCC,GND,DQ,;有两个指示灯,一个为电源指示灯,另一个为开关指示灯(超过设定的阈值就亮),DQ没超过阈值输出高电平,超过就输出低电平。该模块相对简单,没有特定的驱动程序


下面附上我写的程序(检测到高声音蜂鸣器响lcd提示)

lcd库

#include <reg52.h>
#include "./delay/delay.h"
#include "./lcd/lcd.h"
#define LCDPORT P0
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;

void lcd_write(unsigned char byte, unsigned char flag)
{
 if(flag)
 {
  RS = 1;
 }
 else
 {
  RS = 0;
 }
 RW = 0;
 E = 1;
 LCDPORT = byte;
 delay_us(5);
 E = 0;
}

void lcd_init()
{
 delay_ms(15);
 lcd_write(0x38, LCD_WRITE_COM);
 delay_ms(5);
 lcd_write(0x38, LCD_WRITE_COM);
 delay_ms(5);
 lcd_write(0x38, LCD_WRITE_COM);
 lcd_write(0x08, LCD_WRITE_COM);
 delay_ms(5);
 lcd_write(0x01, LCD_WRITE_COM);
 delay_ms(5);
 lcd_write(0x06, LCD_WRITE_COM);
 delay_ms(5);
 lcd_write(0x0c, LCD_WRITE_COM);
 delay_ms(5);
}

void lcd_dis_char(unsigned char x, unsigned char y, unsigned char byte)
{
 unsigned char m;
 if(y==1)
 {
  m = 0x00+0x80+x;
 }
 if(y==2)
 {
  m = 0x40+0x80+x;
 }
 lcd_write(m,LCD_WRITE_COM);
 lcd_write(byte,LCD_WRITE_DATA);
}

void lcd_dis_string(unsigned x, unsigned char y, unsigned char * s)
{
 unsigned char m;
 unsigned char i = 0;
 unsigned char *temp = s;
 if(y==1)
 {
  m=0x00+0x80+x;
 }
 if(y==2)
 {
  m=0x40+0x80+x;
 }
 while(*temp != '\0')
 {
  lcd_write(m+i,LCD_WRITE_COM);
  lcd_write(*temp,LCD_WRITE_DATA);
  temp++;
  i++;
 }
}

delay库

void delay_us(unsigned char t)
{
    while(--t);
}

void delay_ms(unsigned char t)
{
    while(t--)
   {
      delay_us(245);
      delay_us(245);
   }
}

void delay_s(unsigned char t)
{
   while(t--)
  {
   delay_ms(200);
   delay_ms(200);
   delay_ms(200);
   delay_ms(200);
   delay_ms(200);
  }
}

主程序

#include <reg51.h>
#include "./lcd/lcd.h"
#include "./delay/delay.h"
sbit DQ = P1^0;
sbit beep = P1^1;
void main()
{
 unsigned char i;
 lcd_init();
 while(1)
 {
  if(DQ == 0)
  {
   lcd_dis_string(5,1,"stop make noise!");
   for(i=0 ; i<200 ; i++)
   {
     beep = ~beep;
     delay_us(200);
   }
  }
  lcd_dis_string(5,1,"quiet,keeping!");
 }
}

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_26654257

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值