【iCore4 双核心板_ARM】例程一:ARM驱动三色LED
实验原理:
通过STM32的三个GPIO驱动一个三色LED,引脚PB2接红色LED(ARM_LEDR),
引脚PA9接蓝色LED(ARM_LEDB),引脚PA10接绿色LED(ARM_LEDG), GPIO为推
挽输出模式,采用灌电流方式与LED连接,通过拉高拉低GPIO电平,从而控制LED亮灭。
实验现象:
该实验实现跑马灯功能,红、绿、蓝三色LED每隔500ms循环点亮。
源代码下载链接:
链接:http://pan.baidu.com/s/1eSu18A2 密码:ud87
核心源码:
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ LED_RED_ON; LED_BLUE_OFF; LED_GREEN_OFF; HAL_Delay(500); LED_RED_OFF; LED_BLUE_ON; LED_GREEN_OFF; HAL_Delay(500); LED_RED_OFF; LED_BLUE_OFF; LED_GREEN_ON; HAL_Delay(500); } /* USER CODE END 3 */ }
/* USER CODE BEGIN Private defines */ #define LED_RED_ON HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET) #define LED_RED_OFF HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET) #define LED_BLUE_ON HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET) #define LED_BLUE_OFF HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET) #define LED_GREEN_ON HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET) #define LED_GREEN_OFF HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET) /* USER CODE END Private defines */
iCore4链接: