STM32 點(diǎn)燈程序
初始化GPIO:
void led(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
//led
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // 輸出模式
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // 推挽輸出模式,增加輸出電流
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 引腳的的工作速度最高為100MHz,最低為2MHz,工作速度越高,功耗就越高
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // 不需要上拉電阻
GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化端口F
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14; //
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化端口F
}
如果有#include "sys.h"頭文件就
PFout(9) = 0//實(shí)現(xiàn)燈亮
如果沒有#include "sys.h"頭文件就
GPIO_ResetBits(GPIOF, GPIO_Pin_9); //實(shí)現(xiàn)燈亮
GPIO_SetBits(GPIOF, GPIO_Pin_9); //實(shí)現(xiàn)燈沒燈