stm32 - 初识2

stm32 - 初识2

  • 工程架构
  • 点灯程序
    • 寄存器方式点灯
    • 库函数的方式点灯

工程架构

stm32 - 初识2_第1张图片

  • 启动文件

中断向量表,中断服务函数,其他中断等
中断服务函数中的,复位中断是整个程序的入口,调用systeminit,和main函数

点灯程序

寄存器方式点灯

#include "stm32f10x.h"

int main()
{
	/*====== 使用寄存器的方式驱动 ======*/
	/* setp 1:
	 * 设置针脚对应的GPIOX的时钟
	 * RCC 时钟使能寄存器
	 * 使能GPIOC的时钟
	 * GPIO都是APB2的外设,APB2的时钟使能寄存器是RCC_APB2ENR
	 */
	RCC->APB2ENR=0x00000010;
	
	/* setp 2:
	 * 设置IO口的模式
	 * CRH 端口配置寄存器 
	 */
	GPIOC->CRH=0x00300000;
	
	/* setp 3:
	 * 设置IO口输出数据寄存器
	 * ODR 端口输出数据寄存器 
	 */	
	GPIOC->ODR=0x00002000;

	while(1)
	{
		
	}
}

库函数的方式点灯

#include "stm32f10x.h"

int main()
{
	/*====== 使用库函数的方式驱动 ======*/
	// step1 设置GPIOC对应的GPIOX的时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
	
	// step2 配置IO口
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; // 通用推挽输出
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOC,&GPIO_InitStructure);
	
	GPIO_SetBits(GPIOC,GPIO_Pin_13);
//	GPIO_ResetBits(GPIOC,GPIO_Pin_13); // 设置低电平
	while(1)
	{
		
	}
}


你可能感兴趣的:(嵌入式,stm32,嵌入式硬件,单片机)