查看: 928|回复: 0

[原创] MX6ULL 蜂鸣器实验笔记

[复制链接]
  • TA的每日心情
    慵懒
    2020-1-19 10:06
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2020-2-4 14:00:14 | 显示全部楼层 |阅读模式
    分享到:
    蜂鸣器实验笔记
    一、硬件原理介绍
    [size=10.5000pt]

    [size=10.5000pt]我们可以看到S8550PNP型三极管,当BEEP为低电平时蜂鸣器会叫。[size=10.5000pt]BEEP[size=10.5000pt]控制I[size=10.5000pt]O[size=10.5000pt]为[size=10.5000pt]SNVS_TAMPER1[size=10.5000pt],[size=10.5000pt]所以我们只需要控制[size=10.5000pt]SNVS_TAMPER1[size=10.5000pt]这个接口的电压就可以控制蜂鸣器。
    [size=10.5000pt]
    [size=10.5000pt]
    二、实验程序编写[size=10.5000pt]        [size=10.5000pt]1、初始化S[size=10.5000pt]NVS_TAMPER1[size=10.5000pt]这个I[size=10.5000pt]O[size=10.5000pt]复用为G[size=10.5000pt]PIO[size=10.5000pt]5[size=10.5000pt]_IO01
    [size=10.5000pt]        [size=10.5000pt]2、设置S[size=10.5000pt]NVS_TAMPER1[size=10.5000pt]这个I[size=10.5000pt]O[size=10.5000pt]的电气属性。
    [size=10.5000pt]        [size=10.5000pt]3、初始化G[size=10.5000pt]PIO
    [size=10.5000pt]        [size=10.5000pt]4、控制G[size=10.5000pt]PIO[size=10.5000pt]输出高低电平。
    [size=10.5000pt]
    三、代码分享





    Bsp_beep.h
    [size=10.5000pt]
    [size=10.5000pt]#ifndef __BSP_BEEP_H
    [size=10.5000pt]#define __BSP_BEEP_H
    [size=10.5000pt]#include [size=10.5000pt]”[size=10.5000pt]fsl_common.h[size=10.5000pt]”
    [size=10.5000pt]#include [size=10.5000pt]”[size=10.5000pt]fsl_iomuxc.h[size=10.5000pt]”
    [size=10.5000pt]#include[size=10.5000pt]”[size=10.5000pt]MXIMX6Y2.h[size=10.5000pt]”
    [size=10.5000pt]/*函数说明*/
    [size=10.5000pt]Void beep_init(void)
    [size=10.5000pt]Void beep_switch(int status)
    [size=10.5000pt]
    [size=10.5000pt]#endif
    [size=10.5000pt]
    Bsp_beep.c
    [size=10.5000pt]#include [size=10.5000pt]“[size=10.5000pt]bsp_beep.h[size=10.5000pt]”
    [size=10.5000pt]#include [size=10.5000pt]‘[size=10.5000pt]cc.h[size=10.5000pt]’
    [size=10.5000pt]/[size=10.5000pt]’[size=10.5000pt]BEEP[size=10.5000pt]’[size=10.5000pt]初始化/
    [size=10.5000pt]Void beep_init(void)
    [size=10.5000pt]{
    [size=10.5000pt]IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01,0);/复用为GPIO5
    [size=10.5000pt]IOMUXC_SetPinConfig(IIOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01,0X10bo);
    [size=10.5000pt]/*GPIO初始化*/
    [size=10.5000pt]GPIO5->GDIR |(1<<1);/*设置为输出*/
    [size=10.5000pt]GPIO5->DR&=~(1<<1);/*默认关闭*/
    [size=10.5000pt]}
    [size=10.5000pt]
    [size=10.5000pt]/*蜂鸣器控制函数*/
    [size=10.5000pt]Void beep_switch(int status)
    [size=10.5000pt]{
    [size=10.5000pt]If(status == OFF)
    [size=10.5000pt]GPIO->DR |=(1<<1)
    [size=10.5000pt]Else if( status ==ON)
    [size=10.5000pt]GPIO->DR&=-(1<<1);
    [size=10.5000pt]}
    [size=10.5000pt]
    main.c
    #include ‘’bsp_led.h
    #includebsp_delay.h
    #includebsp_beep.h

    Int main(void)
    {
    Clk_enable();/*使能外部时钟*
    Led_init();/*初始化LED*/
    Beep_init/*初始化蜂鸣器*/
    /*设置LED闪烁*/
    While(1)
    Led_on()
    Beep_switch(ON);
    Delay(1000);

    Led_off()
    Beep_switch(OFF);
    Delay(1000);

    }
    [size=10.5000pt]

    图片 2.png
    图片 2.png
    图片 1.png
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 01:49 , Processed in 0.119034 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.