码迷,mamicode.com
首页 > 其他好文 > 详细

STM32F103C8Z6流水灯程序

时间:2018-05-14 19:54:52      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:led   code   class   时钟   its   系统   out   使用   else   

led.h

#ifndef __LED_H
#define	__LED_H

#include "stm32f10x.h"

#define ON  0
#define OFF 1

#define LED1(a)	if(a)GPIO_SetBits(GPIOC,GPIO_Pin_13);else GPIO_ResetBits(GPIOC,GPIO_Pin_13);

void LED_GPIO_Config(void);

#endif 

led.c

#include "led.h"
#include "stm32f10x.h"
void LED_GPIO_Config(void)	
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); // ê1?üPC???úê±?ó  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;	//??????ó|μ?òy??
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;       
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  //3?ê??ˉPC???ú
  GPIO_SetBits(GPIOC, GPIO_Pin_13 );	 // 1?±??ùóDLED
}

main.c


#include "stm32f10x.h"
#include "led.h"

void Delay(__IO u32 Count)
{
  for(; Count != 0; Count--);
} 

int main(void)
{	    
 SystemInit();	// ?????μí3ê±?ó?a72M 	
 LED_GPIO_Config(); //LED ???ú3?ê??ˉ 
  while (1)
  {
		LED1( ON );			  // áá
		Delay(0x200000);
		LED1( OFF );		  // ?e
		Delay(0x200000);	
  }
}


STM32使用姿势

1、main.c里include stm32f10x.h

2、配置系统时钟/为72M

GPIO使用流程

GPIO初始化

使能时钟

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);

选择引脚

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

配置输入输出方式

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

配置IO口速度

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

调用GPIO口初始化函数

GPIO_Init(GPIOC, &GPIO_InitStructure);

将IO口置为高电平或低电平

GPIO_SetBits(GPIOC,GPIO_Pin_13);
GPIO_ResetBits(GPIOC,GPIO_Pin_13);

使用示例

#define LED1(a)	if (a)						GPIO_SetBits(GPIOC,GPIO_Pin_13);					else							GPIO_ResetBits(GPIOC,GPIO_Pin_13)

其中define里面换行需使用斜杆\

STM32F103C8Z6流水灯程序

标签:led   code   class   时钟   its   系统   out   使用   else   

原文地址:https://www.cnblogs.com/uestcman/p/9037596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!