- 利用官方固件库开发
1.硬件说明
机械按键:KEY1-> PA0; KEY2->PC13
RGB LED:R-> PB5; G->PB0; B->PB1
2.bsd_led.h
//为了防止被多个文件调用的时候出现重复定义的错误,我们需要用#ifndef 。。。#endif
#ifndef _BSP_LED_H
#define _BSP_LED_H
#include "stm32f10x.h"
#define LED_R_GPIO_PIN GPIO_Pin_5
#define LED_G_GPIO_PIN GPIO_Pin_0
#define LED_B_GPIO_PIN GPIO_Pin_1
#define LED_RGB_GPIO_PORT GPIOB
#define LED_RGB_GPIO_CLK RCC_APB2Periph_GPIOB
#define ON 0
#define OFF 1
#define LED_G(a) if(a) GPIO_SetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);else GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
//^异或
//与1异或改变为0,与0异或不变还是0
#define LED_G_TOGGLE {LED_RGB_GPIO_PORT->ODR ^= LED_G_GPIO_PIN;}
#define LED_R_TOGGLE {LED_RGB_GPIO_PORT->ODR ^= LED_R_GPIO_PIN;}
void led_init(void);
#endif /* _BSP_LED_H */