【iCore4 雙核心板_ARM】例程一:ARM驅動三色LED

XiaomaGee發表於2017-07-25

實驗原理:

  通過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連結:

相關文章