今天要来学习FireBLE的 timer
实验目的:
使用Timer来让led灯交替闪烁
实验电路:
实验代码:
GPIO配置
- // P0.0 -> GPIO Pull Up Drive ability: Low
- // P0.3 -> GPIO Pull Up Drive ability: Low
- // P0.6 -> SWD [DAT] Pull Up Drive ability: Low
- // P0.7 -> SWD [CLK] Pull Up Drive ability: Low
- // P1.0 -> GPIO Pull Up Drive ability: Low
- // P1.1 -> GPIO Pull Up Drive ability: Low
- // P1.2 -> GPIO Pull Up Drive ability: Low
- // P1.3 -> GPIO Pull Up Drive ability: Low
- // P1.7 -> GPIO Pull Up Drive ability: Low
- // P2.3 -> GPIO Pull Up Drive ability: Low
- // P2.4 -> GPIO Pull Up Drive ability: Low
- // P2.6 -> GPIO Pull Up Drive ability: Low
- // P2.7 -> GPIO Pull Up Drive ability: High
- // P3.0 -> GPIO Pull Up Drive ability: Low
- // P3.1 -> GPIO Pull Up Drive ability: Low
- //Pin Mux Control Register
- syscon_SetPMCR0(QN_SYSCON, P00_GPIO_0_PIN_CTRL
- | P03_GPIO_3_PIN_CTRL
- | P06_SW_DAT_PIN_CTRL
- | P07_SW_CLK_PIN_CTRL
- | P10_GPIO_8_PIN_CTRL
- | P11_GPIO_9_PIN_CTRL
- | P12_GPIO_10_PIN_CTRL
- | P13_GPIO_11_PIN_CTRL
- | P17_GPIO_15_PIN_CTRL);
- //Pin Mux Control Register
- syscon_SetPMCR1(QN_SYSCON, P23_GPIO_19_PIN_CTRL
- | P24_GPIO_20_PIN_CTRL
- | P26_GPIO_22_PIN_CTRL
- | P27_GPIO_23_PIN_CTRL
- | P30_GPIO_24_PIN_CTRL
- | P31_GPIO_25_PIN_CTRL);
- //Pull Control Register
- syscon_SetPPCR0(QN_SYSCON, 0xAAAAAAAA);
- //Pull Control Register
- syscon_SetPPCR1(QN_SYSCON, 0xAAAAAAAA);
- //Drive ability Control Register
- syscon_SetPDCR(QN_SYSCON, 0x00800000);
复制代码
以上代码替换掉system.c里的SystemIOCfg函数
主程序代码
- #include "timer.h"
- #include "system.h"
- /*led翻转*/
- void led_blink(void)
- {
- gpio_toggle_pin(GPIO_P27);
- }
- int main(void)
- {
- /*系统初始化*/
- SystemInit();
-
- /*配置GPIO*/
- gpio_init(NULL);
- gpio_set_direction(GPIO_P27,GPIO_OUTPUT);
- gpio_write_pin_field(GPIO_PIN_ALL,GPIO_HIGH);
- /*配置Timer0*/
- timer_init(QN_TIMER0,led_blink);
- timer_config(QN_TIMER0,TIMER_PSCAL_DIV,TIMER_COUNT_MS(1000,TIMER_PSCAL_DIV));
- timer_enable(QN_TIMER0,MASK_ENABLE);
-
- while(true)
- {
-
- }
- }
复制代码
编译下载至 开发板,可以看到蓝色的LED每隔1秒交替闪烁。
0
|
|
|
|
|
|