微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > LED灯控制程序

LED灯控制程序

时间:10-02 整理:3721RD 点击:
#include "stm32f10x.h"
void LED_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  //打开PB口时钟
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        //打开PA口时钟
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        //PB8,PA2引脚设置

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
        //端口速度
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        //端口模式,此为输出推挽模式
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        //初始化对应的端口
  GPIO_Init(GPIOB, &GPIO_InitStructure);
        
        
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        //端口速度
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        //端口模式,此为输出推挽模式
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        //初始化对应的端口
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}
int main(void)
{
        
uint32_t i; //定义32位数
LED_Init(); //初始化LED
for(i=0;i<0xffffff;i++);//for循环不精确延时        
while(1)
{
      GPIO_SetBits(GPIOB,GPIO_Pin_8);                                                        
          GPIO_ResetBits(GPIOA,GPIO_Pin_2);
          GPIO_ResetBits(GPIOB,GPIO_Pin_8);                                                        
          GPIO_SetBits(GPIOA,GPIO_Pin_2);
}
}

小编这是有什么问题嘛?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top