1.Led.h
#ifndef __Led_H
#define __Led_H
#include "stm32f10x.h" // Device header
#include "sys.h"
//LED0 GPIOÅäÖÃ
#define LED0_GPIO_CLK RCC_APB2Periph_GPIOB //GPIOBʱÖÓ
#define LED0_GPIO_PORT GPIOB //GPIOB
#define LED0_GPIO_Mode GPIO_Mode_Out_PP //ÍÆÍìÊä³ö
#define LED0_GPIO_Pin GPIO_Pin_5 //Pin_5
//LED1 GPIOÅäÖÃ
#define LED1_GPIO_CLK RCC_APB2Periph_GPIOE //GPIOEʱÖÓ
#define LED1_GPIO_PORT GPIOE //GPIOE
#define LED1_GPIO_Mode GPIO_Mode_Out_PP //ÍÆÍìÊä³ö
#define LED1_GPIO_Pin GPIO_Pin_5 //Pin_5
//
#define LED0 PBout(5)// PB5
#define LED1 PEout(5)// PE5
void Led_Init(void);
#endif
2.Led.c
#include "Led.h"
void Led_Init(void)
{
RCC_APB2PeriphClockCmd(LED0_GPIO_CLK | LED1_GPIO_CLK,ENABLE); //ʹÄÜGPIOB GPIOE¶Ë¿ÚʱÖÓ
//PB5 PE5 ¶Ë¿Ú³õʼ»¯ ÍÆÍìÊä³ö 50MHz
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=LED0_GPIO_Mode;
GPIO_InitStructure.GPIO_Pin=LED0_GPIO_Pin;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(LED0_GPIO_PORT,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=LED1_GPIO_Mode;
GPIO_InitStructure.GPIO_Pin=LED1_GPIO_Pin;
GPIO_Init(LED1_GPIO_PORT,&GPIO_InitStructure);
GPIO_SetBits(LED0_GPIO_PORT,LED0_GPIO_Pin);
GPIO_SetBits(LED1_GPIO_PORT,LED1_GPIO_Pin);
// GPIO_ResetBits(LED0_GPIO_PORT,LED0_GPIO_Pin);
// GPIO_ResetBits(LED1_GPIO_PORT,LED1_GPIO_Pin);
}
3.main
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "sys.h"
#include "stdio.h"
#include "Led.h"
int main(void)
{
Led_Init();
while(1)
{
LED0 = 0;
LED1 = 0;
}
}