stm32cube中文教程1:软件设置,点亮led灯,并实现流水灯效果(HAL_GPIO_TogglePin)

学习第一步,必须是led灯啊,呵呵
纯软件生成代码,等会编辑.

用stm32cubemx软件做流水灯实验(1),stm32cube实验教程一,用到函数hal_gpio_writepin,HAL_Delay,HAL_GPIO_TogglePin ,三句话搞定流水灯,无需编程

推荐初学stm32的人使用啊

详细图片教程请移步到 stm32cube贴吧 ,或者下载stm32cube教程的pdf
下载地址:http://pan.baidu.com/s/1kT2wuMz
有疑问可以留言
下面是按照教程里面得到的程序代码:
main.c文件:


/**
******************************************************************************
* File Name : main.c
* Date : 11/06/2014 21:08:41
* Description : Main program body
******************************************************************************
*
* COPYRIGHT(c) 2014 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/

/[i] Includes ------------------------------------------------------------------[/i]/
#include "stm32f4xx_hal.h"

/[i] Private variables ---------------------------------------------------------[/i]/

/[i] USER CODE BEGIN 0 [/i]/

/[i] USER CODE END 0 [/i]/

/[i] Private function prototypes -----------------------------------------------[/i]/
static void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{

/[i] USER CODE BEGIN 1 [/i]/

/[i] USER CODE END 1 [/i]/

/[i] MCU Configuration----------------------------------------------------------[/i]/

/[i] Reset of all peripherals, Initializes the Flash interface and the Systick. [/i]/
HAL_Init();

/[i] Configure the system clock [/i]/
SystemClock_Config();

/[i] Initialize all configured peripherals [/i]/
MX_GPIO_Init();

/[i] USER CODE BEGIN 2 [/i]/

/[i] USER CODE END 2 [/i]/

/[i] USER CODE BEGIN 3 [/i]/
/[i] Infinite loop [/i]/
while (1)
{
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_6,GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_6,GPIO_PIN_RESET);
HAL_Delay(1000);
}
/[i] USER CODE END 3 [/i]/

}

/** System Clock Configuration
*/
static void SystemClock_Config(void)
{

RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;

__PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

}

/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{

GPIO_InitTypeDef GPIO_InitStruct;

/[i] GPIO Ports Clock Enable [/i]/
__GPIOF_CLK_ENABLE();
__GPIOH_CLK_ENABLE();

/[i]Configure GPIO pin : PF6 [/i]/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

}

/[i] USER CODE BEGIN 4 [/i]/

/[i] USER CODE END 4 [/i]/

#ifdef USE_FULL_ASSERT

/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

}

#endif

/**
* @}
*/

/**
* @}
*/

/*******************[i][i][b][/i] (C) COPYRIGHT STMicroelectronics [/b][b][i]END OF FILE[/b][/i][/i]/
已邀请:

chendonghao55 - 90IT man

赞同来自: 大范围的范围 kamigakita

好简单 就是中间那三行
我也学会啦 加油
接着学习

happyer561

赞同来自:

楼主就没有用到HAL_GPIO_TogglePin函数,只用了前两个,实现LED间隔1秒闪烁!

bear087

赞同来自:

楼主意思是可以用
HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_6);
HAL_Delay(1000);
同样效果实现1S闪烁
匿名用户

匿名用户

赞同来自:

HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_6) 这个函数有什么作用??

rainy - 90后IT男

赞同来自:

谢谢分享

Napoleon Wang

赞同来自:

HAL_GPIO_TogglePin()这个函数没用啊

随别生活◕‿

赞同来自:

谢谢分享

hbthgs

赞同来自:

谢谢分享!

同...步

赞同来自:

HAL_GPIO_TogglePin()跪求这个怎么实现1S闪烁

才高七斗

赞同来自:

看了才发现那么简单

Xu_Yang

赞同来自:

 HAL_GPIO_WritePin(GPIOF,GPIO_PIN_6,GPIO_PIN_SET);这个函数从哪里来的,需要下载库文件吗

村中小孩

赞同来自:

挺好

自定义 - 95后

赞同来自:

怎么办??学不会

要回复问题请先登录注册