学习江协科技stm32基于库函数开发记录一下
代码压缩包地址:code
1.点灯
RCC_APB2PeriphClockCmd()//时钟使能
GPIO_Init(GPIOx,&GPIO_InitStruct)//引脚初始化
GPIO_SetBits(GPIOC,GPIO_Pin_13);//设置高电平
GPIO_ResetBits(GPIOC,GPIO_Pin_13);//设置低电平
main.c
//P13脚点灯
#include "stm32f10x.h" // Device header
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//时钟使能
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStruct);//结构体定义
GPIO_SetBits(GPIOC,GPIO_Pin_13);//高电平
GPIO_ResetBits(GPIOC,GPIO_Pin_13);
while(1)
{
;
}
}
2.led闪烁
GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);//写引脚电平
main.c
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//时钟使能
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);//结构体定义
// GPIO_SetBits(GPIOC,GPIO_Pin_13);//高电平
// GPIO_ResetBits(GPIOC,GPIO_Pin_13);
while(1)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
Delay_ms(500);
GPIO_SetBits(GPIOA,GPIO_Pin_0);
Delay_ms(500);//gpio_setbits与gpio_resetbits
GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);
Delay_ms(500);
GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);
Delay_ms(500);//gpio_write函数
GPIO_WriteBit(GPIOA,GPIO_Pin_0,(BitAction)0);
Delay_ms(500);
GPIO_WriteBit(GPIOA,GPIO_Pin_0,(BitAction)1);
Delay_ms(500);//强制类型转换
}
}
3.流水灯
GPIO_Write(GPIOA, ~0x0001);//按字节写
main.c
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//时钟使能
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);//结构体定义
while(1)
{
GPIO_Write(GPIOA, ~0x0001);//按字节写//0000 0000 0000 0001
Delay_ms(100);
GPIO_Write(GPIOA, ~