ARM embedded programming (no operating system, based on MDK) the simplest program: Light up an LED lamp

Source: Internet
Author: User

1. design requirements

EM-STM3210E Development Board has a LED lamp D1, write a program to light up the light.

2. hardware circuit connection

On the Development Board, D1 is connected to the PF6 pin on the STM32F103ZE chip, as shown in.

 

3. Software Programming

According to the task requirements, the program content mainly includes:

1. configure Reset and clock control (RCC) to enable the clock of the GPIOF port Module

2. Configure the PF6 pin of the GPIOF port (50 MHz, push-pull output)

3. Call the GPIO_WriteBit function of the STM32 standard Firmware Library to make the PF6 pin output a high level to light the LED lamp D1.

 

The entire project user only needs to implement the source code file: main. c. Other project files are provided by the MDK and STM32 standard firmware libraries.


The content of the main. c file is as follows:

[Cpp]
/**
**************************************** **************************************
* @ File main. c
* @ Author Max Liao
* @ Version
* @ Date 02-Novenber-2012
* @ Brief Main program body
**************************************** **************************************
*/
 
/* Includes ------------------------------------------------------------------*/
# Include "stm32f10x. h"
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
 
/* Private function prototypes -----------------------------------------------*/
Void RCC_Configuration (void );
Void GPIO_Configuration (void );
 
/* Private functions ---------------------------------------------------------*/
 
/**
* @ Brief Main program.
* @ Param None
* @ Retval None
*/
Int main (void)
{
RCC_Configuration ();
GPIO_Configuration ();

/* PF6 pin output high level, light the LED lamp D1 on the EM-STM3210E Development Board */
GPIO_WriteBit (GPIOF, GPIO_Pin_6, Bit_SET );
 
/* Infinite loop */
While (1 ){
}
}
 
 
Void RCC_Configuration (void)
{
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOF, ENABLE );
}
 
Void GPIO_Configuration (void)
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // push the output
GPIO_Init (GPIOF, & GPIO_InitStructure );
}

[Cpp]
 


4. Program Running Effect

 


 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.