国民技术N32G430开发笔记(2)- 点亮开发板的LED

点亮开发板的LED

1、官方下载的AN_N32G430_GCC Development Environment Application Note_V1.zip文件里
有LedBlink例子,我们在此基础上修改即可。

2、将LedBlink工程 的bsp_led.c bsp_led.h移到我们的代码,这里包含了对板载三颗LED灯的初始化以及控制。

bsp_led.c主要代码:

void LED_Initialize(GPIO_Module* GPIOx, uint16_t pin, uint32_t AHB_periph)
{
	/* Define a structure of type GPIO_InitType */
	GPIO_InitType GPIO_InitStructure;
	
	/* Enable LED related GPIO peripheral clock */
	RCC_AHB_Peripheral_Clock_Enable(AHB_periph);
	
	/* Assign default value to GPIO_InitStructure structure */
	GPIO_Structure_Initialize(&GPIO_InitStructure);
	
	/* Select the GPIO pin to control */
	GPIO_InitStructure.Pin          = pin;
	/* Set pin mode to general push-pull output */
	GPIO_InitStructure.GPIO_Mode    = GPIO_MODE_OUT_PP;
	/* Set the pin drive current to 4MA*/
	GPIO_InitStructure.GPIO_Current = GPIO_DS_4MA;
	/* Initialize GPIO */
	GPIO_Peripheral_Initialize(GPIOx, &GPIO_InitStructure);
}

void LED_Toggle(GPIO_Module* GPIOx, uint16_t pin)
{
    GPIO_Pin_Toggle(GPIOx, pin);;
}
void LED_On(GPIO_Module* GPIOx,uint16_t pin)
{
    GPIO_Pins_Set(GPIOx, pin);
}
void LED_Off(GPIO_Module* GPIOx,uint16_t pin)
{
    GPIO_PBC_Pins_Reset(GPIOx, pin);
}

bsp_led.h

#include "n32g430.h"

/** Define the GPIO port to which the LED is connected **/
#define LED1_GPIO_PORT    	GPIOA			              /* GPIO port */
#define LED1_GPIO_CLK 	    RCC_AHB_PERIPH_GPIOA		/* GPIO port clock */
#define LED1_GPIO_PIN		    GPIO_PIN_1			        /* GPIO connected to the SCL clock line */

#define LED2_GPIO_PORT    	GPIOA			              /* GPIO port */
#define LED2_GPIO_CLK 	    RCC_AHB_PERIPH_GPIOA		/* GPIO port clock */
#define LED2_GPIO_PIN		    GPIO_PIN_7			        /* GPIO connected to the SCL clock line */

#define LED3_GPIO_PORT    	GPIOA			              /* GPIO port */
#define LED3_GPIO_CLK 	    RCC_AHB_PERIPH_GPIOA		/* GPIO port clock */
#define LED3_GPIO_PIN		    GPIO_PIN_9			        /* GPIO connected to the SCL clock line */

void LED_Initialize(GPIO_Module* GPIOx, uint16_t pin, uint32_t AHB_periph);
void LED_Toggle(GPIO_Module* GPIOx, uint16_t pin);
void LED_On(GPIO_Module* GPIOx,uint16_t pin);
void LED_Off(GPIO_Module* GPIOx,uint16_t pin);

3、main.c 添加对bsp_led.c的调用即可,在main.c里添加如下代码:

/* Initialize Led1~Led3 as output push-pull mode */
LED_Initialize(LED1_GPIO_PORT, LED1_GPIO_PIN, LED1_GPIO_CLK);
LED_Initialize(LED2_GPIO_PORT, LED2_GPIO_PIN | LED3_GPIO_PIN, LED2_GPIO_CLK);
	
/* Turn off Led1~Led3 */
LED_Off(LED2_GPIO_PORT, LED1_GPIO_PIN | LED2_GPIO_PIN | LED3_GPIO_PIN);
	
/* Turn on Led2~Led3 */
LED_On(LED2_GPIO_PORT, LED2_GPIO_PIN | LED3_GPIO_PIN);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值