Mini板上唯一现成的东西是4个LED,接在GPIOB 5,6,7,8,历尽千辛万苦,灯,终于亮了。(汗颜啊!)
#include "stm32f10x_lib.h"
GPIO_InitTypeDef GPIO_InitStructure;
/* typedef struct
{u16 GPIO_Pin; select pins to configure
GPIOSpeed_TypeDef GPIO_Speed;
GPIOMode_TypeDef GPIO_Mode;}GPIO_InitTypeDef
*/
void LED_Init(void);
void Delay(vu32);
void LED_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //开GPIOB时钟
//RCC_APB2PeriphClockCmd enable clock for some peripheral devices such as GPIOx and ADC1 (APB2)
//RCC_APB1PeriphClockCmd enable clock for APB1 peripheral devices
/*配置 GPIOB 5,6,7,8为push pull输出*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; //configure Pin5,6,7
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // P164 push-pull mode
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_Speed_2/10/50MHz 3 frequencies
GPIO_Init(GPIOB, &GPIO_InitStructure); //GPIO initial
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
main()
{
LED_Init();
while(1)
{
GPIO_SetBits(GPIOB, GPIO_Pin_5);//set GPIOC.5=1
Delay(0x8ffff);
GPIO_ResetBits(GPIOB, GPIO_Pin_5);//set GPIOC.5=0
Delay(0x8ffff);
GPIO_SetBits(GPIOB, GPIO_Pin_7);//GPIOC.7=1
Delay(0x8ffff);
GPIO_ResetBits(GPIOB, GPIO_Pin_7);//GPIOC.7=0
Delay(0x8ffff);
GPIO_SetBits(GPIOB, GPIO_Pin_6);//GPIOC.8=1
Delay(0x8ffff);
GPIO_ResetBits(GPIOB, GPIO_Pin_6);//GPIOC.8=0
Delay(0x8ffff);
}
}
用户906612 2008-4-8 21:07