有12个LED通过移位寄存器HC595连接,使用的模块是nrf51822(蓝牙模块)。我希望 LED 在 3 秒间隔后熄灭。我的代码如下 -
#include "main.h"
#include "uart.h"
#include "nrf_delay.h"
#include "rc522.h"
#include "hc595.h"
#include "tsm12m.h"
#include "iic.h"
#include "app_timer.h"
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
#define APP_TIMER_OP_QUEUE_SIZE 6
APP_TIMER_DEF(LEDOps);
static void timer_a_handler(void * p_context)
{
lightAllLEDs();
}
static void create_timers()
{
uint32_t err_code;
// Create timers
err_code = app_timer_create(&LEDOps,
APP_TIMER_MODE_SINGLE_SHOT,
timer_a_handler);
APP_ERROR_CHECK(err_code);
}
void timers_init(){
uint32_t err_code;
// Initialize the application timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
create_timers();
}
void timer_a_start(){
uint32_t err_code;
err_code = app_timer_start(LEDOps, APP_TIMER_TICKS(3,APP_TIMER_PRESCALER), NULL);
APP_ERROR_CHECK(err_code);
}
int main(void)
{
uartInit();
TSM12_Init();
HC595_Init();
timers_init();
timer_a_start();
UartSendstring("123456789");
printf("timer stopped!!");
app_timer_stop(LEDOps);
while(1)
{
TSM12_Handle();
nrf_delay_ms(1);
}
}
上面的代码似乎不起作用。我是模块新手。请提供解决方案帮助。