新手入门
- 积分
- 7
- 金钱
- 7
- 注册时间
- 2021-7-1
- 在线时间
- 1 小时
|
1金钱
本人最近在学习正点原子的imx6ull板子的教程视频,在学习到用EPIT1定时器来对按键消抖的实验的时候,代码什么的和例程完全一样,操作什么的也是一样,但是按下按键之后,蜂鸣器应该发出声音,再按一次停止鸣叫,但是我按下的时候能看到执行了中断函数,但是蜂鸣器没有反应,代码如下:#include "bsp_keyfilter.h"
| [tr][/tr]
#include "bsp_int.h"
| [tr][/tr]
#include "bsp_gpio.h"
| [tr][/tr]
#include "bsp_beep.h"
| [tr][/tr]
#include "bsp_key.h"
| [tr][/tr]
/*keyfilter初始化*/
| [tr][/tr]
unsigned char beep_state = OFF;
| [tr][/tr]
void keyfilter_init(void)
| [tr][/tr]
gpio_pin_config_t key_config;
| [tr][/tr]
IOMUXC_SetPinMux(IOMUXC_UART1_CTS_B_GPIO1_IO18,0);
| [tr][/tr]
IOMUXC_SetPinConfig(IOMUXC_UART1_CTS_B_GPIO1_IO18,0xf080);
| [tr][/tr]
key_config.direction = kGPIO_DigitalInput;
| [tr][/tr]
key_config.interruptMode = kGPIO_IntFallingEdge;
| [tr][/tr]
key_config.outputLogic = 1;
| [tr][/tr]
gpio_init(GPIO1, 18, &key_config);
| [tr][/tr]
GIC_EnableIRQ(GPIO1_Combined_16_31_IRQn);
| [tr][/tr]
system_register_irqhandler(GPIO1_Combined_16_31_IRQn, (system_irq_handler_t)gpio1_16_31_irqhandler, NULL);
| [tr][/tr]
gpio_enableint(GPIO1, 18);
| [tr][/tr]
filtertimer_init(66000000/100);
| [tr][/tr]
void filtertimer_init(unsigned int value)
| [tr][/tr]
EPIT1->CR = (1 << 1) | (1 << 2) | (1 << 3) | (1 << 24);
| [tr][/tr]
EPIT1->LR = value; /*加载寄存器,相当于倒计数值*/
| [tr][/tr]
EPIT1->CMPR = 0;
| [tr][/tr]
GIC_EnableIRQ(EPIT1_IRQn);
| [tr][/tr]
system_register_irqhandler(EPIT1_IRQn, (system_irq_handler_t)filtertimer_irqhandler, NULL);
| [tr][/tr]
void filtertimer_stop(void)
| [tr][/tr]
EPIT1->CR &= ~(1 << 0);
| [tr][/tr]
void filtertimer_restart(unsigned int value)
| [tr][/tr]
EPIT1->CR &= ~(1 << 0);
| [tr][/tr]
EPIT1->LR = value; /*加载寄存器,相当于倒计数值*/
| [tr][/tr]
EPIT1->CR |= (1 << 0);
| [tr][/tr]
/*EPIT1定时器中断处理函数*/
| [tr][/tr]
void filtertimer_irqhandler(void)
| [tr][/tr]
if(EPIT1->SR & (1 << 0))
| [tr][/tr]
filtertimer_stop();
| [tr][/tr]
if(gpio_pinread(GPIO1, 18) == 0)
| [tr][/tr]
beep_state = !beep_state;
| [tr][/tr]
beep_switch(beep_state);
| [tr][/tr]
EPIT1->SR |= 1 << 0;
| [tr][/tr]
void gpio1_16_31_irqhandler(unsigned int gicciar, void *param)
| [tr][/tr]
filtertimer_restart(66000000/100);
| [tr][/tr]
gpio_clearintflags(GPIO1, 18);
| [tr][/tr] }
这是关于按键消抖的c文件中的程序,涉及到gpio初始化、gpio中断函数注册、定时器初始化、定时器开启函数、定时器关闭函数、定时器中断服务函数、按键中断服务函数等。接下来的是主函数的代码:
#include "fsl_iomuxc.h"
| [tr][/tr]
#include "fsl_common.h"
| [tr][/tr]
#include "MCIMX6Y2.h"
| [tr][/tr]
#include "bsp_led.h"
| [tr][/tr]
#include "bsp_delay.h"
| [tr][/tr]
#include "bsp_clk.h"
| [tr][/tr]
#include "main.h"
| [tr][/tr]
#include "bsp_beep.h"
| [tr][/tr]
#include "bsp_key.h"
| [tr][/tr]
#include "bsp_gpio.h"
| [tr][/tr]
#include "bsp_int.h"
| [tr][/tr]
#include "bsp_exti.h"
| [tr][/tr]
#include "bsp_epit.h"
| [tr][/tr]
#include "bsp_keyfilter.h"
| [tr][/tr]
unsigned char state = 0;
| [tr][/tr]
imx6u_clkinit();
| [tr][/tr]
clk_enable(); /* 使能所有的时钟 */
| [tr][/tr]
led_init(); /* 初始化led */
| [tr][/tr]
beep_init(); /*初始化蜂鸣器*/
| [tr][/tr]
key_init(); /*初始化按键*/
| [tr][/tr]
keyfilter_init();
| [tr][/tr]
while(1) /* 死循环 */
| [tr][/tr]
state = !state;
| [tr][/tr]
led_switch(LED0, state);
| [tr][/tr]
目前实验现象是主程序中的led灯能闪烁、但是按下按键,蜂鸣器没反应而且主程序也会暂停,led灯保持按键按下之前的状态。麻烦看看是什么原因,谢谢带佬们!!!!
|
|