当前位置:网站首页>I.MX6U-ALPHA开发板(蜂鸣器实验)
I.MX6U-ALPHA开发板(蜂鸣器实验)
2022-07-21 07:13:00 【*﹏ℳ๓无情*】
一、硬件原理图分析
BEEP控制IO为SNVS_TAMPER1,当输出低电平的时候蜂鸣器响,输出高电平的时候蜂鸣器不响。
二、实验程序编写
1、初始化复用
初始化SNVS_TAMPER1这个IO复用为GPIO5_IO01
2、设置电气属性
设置SNVS_TAMPER1这个IO的电气属性
3、初始化GPIO
4、控制GPIO输出高低电平
//bsp_beep.h
#ifndef __BSP_BEEP_H
#define __BSP_BEEP_H
#include "imx6ul.h"
/* 函数声明 */
void beep_init(void);
void beep_switch(int status);
#endif
//bsp_beep.c
#include "bsp_beep.h"
void beep_init(void)
{
//初始化IO复用,复用为GPIO5_IO01
IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01,0);
//配置GPIO1_IO03的IO属性
IOMUXC_SetPinConfig(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01,0X10B0);
//初始化GPIO,GPIO5_IO01设置为输出
GPIO5->GDIR |= (1 << 1);
//设置GPIO5_IO01输出高电平,关闭蜂鸣器
GPIO5->DR |= (1 << 1);
}
void beep_switch(int status)
{
if(status == ON)
GPIO5->DR &= ~(1 << 1); /* 打开蜂鸣器 */
else if(status == OFF)
GPIO5->DR |= (1 << 1); /* 关闭蜂鸣器 */
}
//main.c
#include "bsp_clk.h"
#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_beep.h"
int main(void)
{
clk_enable(); /* 使能所有的时钟 */
led_init(); /* 初始化led */
beep_init(); /* 初始化beep */
while(1)
{
/* 打开LED0和蜂鸣器 */
led_switch(LED0,ON);
beep_switch(ON);
delay(500);
/* 关闭LED0和蜂鸣器 */
led_switch(LED0,OFF);
beep_switch(OFF);
delay(500);
}
return 0;
}
只需要更改TARGET、INCDIRS、SRCDIRS即可
CROSS_COMPILE ?= arm-linux-gnueabihf-
TARGET ?= beep
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
OBJDUMP := $(CROSS_COMPILE)objdump
INCDIRS := imx6ul \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep
SRCDIRS := project \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep
INCLUDE := $(patsubst %, -I %, $(INCDIRS))
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
SFILENDIR := $(notdir $(SFILES))
CFILENDIR := $(notdir $(CFILES))
SOBJS := $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS := $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS := $(SOBJS) $(COBJS)
VPATH := $(SRCDIRS)
.PHONY: clean
$(TARGET).bin : $(OBJS)
$(LD) -Timx6ul.lds -o $(TARGET).elf $^
$(OBJCOPY) -O binary -S $(TARGET).elf [email protected]
$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
$(SOBJS) : obj/%.o : %.S
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o [email protected] $<
$(COBJS) : obj/%.o : %.c
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o [email protected] $<
clean:
rm -rf $(TARGET).elf $(TARGET).dis $(TARGET).bin $(COBJS) $(SOBJS)
三、实验现象
LED灯亮时蜂鸣器响,LED灯灭时蜂鸣器不响
边栏推荐
猜你喜欢
Lecture 1 Overview
Houdini building rigid body area influence breaking notes
“我放弃编程,写了一本130万字的硬科幻小说”
1306_ Comparison test of resource usage of two open source printf
逍遙管理器安裝
Basic usage of Networkx
Niu Ke brushes question 01 - Kiki de duplication of integers and sorting (C language)
Visualization: you must know these ten data visualization tool software platforms
Introduction to common interfaces of vector
list解析<stl初级> (跑路人笔记)
随机推荐
使用CompletableFuture实现异步回调
如何测试webservice接口
Pipeline operators in mongodb ($group, $unwind, $sort, $limit, $skip)
How to understand pointers?
Mysql07 (data update DML)
Kaptcha验证码的配置与使用
[paper notes] 3D point cloud segmentation pointnet
一种新的UI测试方法:视觉感知测试
Mysql06 (sequence)
Share 50 free cloud disk and online disk Services - with unlimited storage space
Leetcode skimming 03
weirdo The interview topics include toilet habits, eating time and sleeping time
The NSLOOKUP command uses
How to start your online life
小程序 奇葩BUG 更新~
Mysql05(视图)
47: Chapter 4: developing file services: 8: automatic image review (Alibaba cloud content security); (don't read it if you haven't written it yet; to be written...)
word2vec简单总结
2022年化工自动化控制仪表考试试题模拟考试平台操作
Mysql03 (Association query)