点灯程序
#include "stm32f10x.h"
#include "sys.h"
#include "delay.h"
#define LEDPORT GPIOB
#define LED1 GPIO_Pin_0
#define LED2 GPIO_Pin_1
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //初始化参数的结构体声明和名称的定义
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);//在时钟上启动IO端口
GPIO_InitStructure.GPIO_Pin = LED1 | LED2; //选择端口号(0~15或all)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//选择IO工作方式(推挽输出)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置IO接口速度(2/10/50MHz)
GPIO_Init(LEDPORT,&GPIO_InitStructure);//选择设置的端口组
}
int main (void)
{
RCC_Configuration(); //时钟设置
LED_Init(); // led初始化
while(1)
{
GPIO_WriteBit(LEDPORT,LED1,(BitAction) (1));//高电平亮
delay_ms(500);//延时500ms
GPIO_WriteBit(LEDPORT,LED1,(BitAction) (0));//低电平灭
delay_ms(500);
}
}
在写注释时如果发现乱码,出现?的情况,可以这样解决:
1.点击Edit
2.点击最后一项
3.点击蓝色地方
4.点击OK就行了