STM32
直播中

陈厚合

16年用户 1708经验值
擅长:可编程逻辑
私信 关注
[问答]

请问一下如何去完成一种基于STM32的点灯设计呢

请问一下如何去完成一种基于STM32的点灯设计呢?

回帖(1)

李凤

2021-11-26 15:39:49
1. 引入文件

  
  

  

  2.新建led.h和led.c文件

  

#ifndef __LED_H
#define        __LED_H

#include "stm32f10x.h"

#define ON        0
#define OFF        1

#define LED11(a) if(a) GPIO_SetBits(GPIOB,GPIO_Pin_9); else GPIO_ResetBits(GPIOB,GPIO_Pin_9)

void LED_GPIO_Config(void);
#endif

/*
  * @brief  None  program.
  * @param  None
  * @retval None
  *
        */
void LED_GPIO_Config(void)
{
                GPIO_InitTypeDef GPIO_InitStructure;
       
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;       
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;      
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOB, &GPIO_InitStructure);

                GPIO_SetBits(GPIOB, GPIO_Pin_9);         
}
int main (void)
{

        LED_GPIO_Config();
       
        while(1)
        {
                LED11_workStatus(ON);
        }
}

  在main中就可以了。
   
   
举报

更多回帖

发帖
×
20
完善资料,
赚取积分