stm32 learning notes (I) lighting up the LED

Publisher:代码律动Latest update time:2018-12-29 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include "stm32f10x.h"

#include "delay.h"

 void Delay(u32 count)

 {

  u32 i=0;

  for(;i

 

 }

 

 

 int main(void)

 {

  GPIO_InitTypeDef  GPIO_InitStructure;

 

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //Enable PA

  delay_init();

 

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //LED0-->PA.8 port configuration

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Push-pull output

  GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz; //IO port speed is 50MHz

  GPIO_Init(GPIOA, &GPIO_InitStructure); //Initialize GPIOA according to the set parameters.8

  GPIO_SetBits(GPIOA,GPIO_Pin_8); //PA.8 output high

 

 // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //LED1-->PD.2 port configuration, push-pull output

 // GPIO_Init(GPIOD, &GPIO_InitStructure); //Push-pull output, IO port speed is 50MHz

  //GPIO_SetBits(GPIOD,GPIO_Pin_2); //PD.2 output high   

  while(1)

{

  GPIO_SetBits(GPIOA,GPIO_Pin_8);

    //GPIO_SetBits(GPIOD,GPIO_Pin_2);

   delay_ms(1000);

GPIO_ResetBits(GPIOA,GPIO_Pin_8);

//GPIO_ResetBits(GPIOD,GPIO_Pin_2);

delay_ms(1000);

}

 }


Before trying the dealy_ms function, first initialize delay_init.


Enable GPIO clock and configure IO port mode


The output mode is set to push-pull output, the output frequency is 50MHZ


The red light corresponds to pin GPIOA_Pin_8;


The yellow light corresponds to the pin GPIOD_Pin_2

Keywords:stm32 Reference address:stm32 learning notes (I) lighting up the LED

Previous article:STM32 learning notes (II) key experiment
Next article:Summary of the general timer PWM experiment of STM32F107

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号