是这样的,我用的f103vet6,采用的是库开发方式。结果控制4颗LED亮,实际却是只有一颗亮。代码如下:
led.h
[mw_shl_code=c,true]#ifndef __LED_H
#define __LED_H
#include "stm32f10x.h"
#define ON 0
#define OFF 1
#define LED1(a) if(a) \
GPIO_ResetBits(GPIOD,GPIO_Pin_8);\
else \
GPIO_SetBits(GPIOD,GPIO_Pin_8)
#define LED2(a) if(a) \
GPIO_ResetBits(GPIOD,GPIO_Pin_9);\
else \
GPIO_SetBits(GPIOD,GPIO_Pin_9)
#define LED3(a) if(a) \
GPIO_ResetBits(GPIOD,GPIO_Pin_10);\
else \
GPIO_SetBits(GPIOD,GPIO_Pin_10)
#define LED4(a) if(a) \
GPIO_ResetBits(GPIOD,GPIO_Pin_11);\
else \
GPIO_SetBits(GPIOD,GPIO_Pin_11)
void LED_GPIO_Config(void);
#endif
[/mw_shl_code]
led.c
[mw_shl_code=c,true]#include "led.h"
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,GPIO_Pin_8);
GPIO_SetBits(GPIOD,GPIO_Pin_9);
GPIO_SetBits(GPIOD,GPIO_Pin_10);
GPIO_SetBits(GPIOD,GPIO_Pin_11);
}
[/mw_shl_code]
main.c
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "led.h"
void Delay(__IO u32 nCount);
int main(void)
{
LED_GPIO_Config();
while(1)
{
Delay(0x0fffef);
LED1(ON);
Delay(0x0fffef);
LED2(ON);
Delay(0x0fffef);
LED3(ON);
Delay(0x0fffef);
LED4(ON);
Delay(0x0fffef);
}
}
void Delay(__IO u32 nCount)
{
for(; nCount !=0; nCount-- );
}
[/mw_shl_code]
|