1.震动传感器模块外部照片 
2.新建shake工程 ①在USER中新建shake文件夹,并且在其中新建shake.c、shake.h文件 ②在Keil5中添加shake.c(直接添加),shake.h(现在shake.c中#include “shake.h”然后编译后自动添加了shake.h) ③在shake.c和shake.h中#include “stm32f10x.h” ④在shake.c中定义一个函数——>在shake.h中申明——>在main.c中调用**(要添加#include “shake.h” ,并且要在魔术棒中添加shake.h路径)**     3.编写shake.c程序
- 打开GPIOA的时钟
①在外设FWLIB中找到 rcc.c>rcc.h 中APB2的申明函数 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState); 我们只需要这个函数的 RCC_APB2PeriphClockCmd( , ); 将其复制到shake.c中 ②配置第一个参数(GPIOA的外设时钟)  ③第二个参数(功能状态) goto其定义就能找到状态,我们需要其使能ENABLE - 配置结构体GPIOA1
①在rcc.c>gpio.h中找到结构体  ②我们把Shake_init复制到shake.c中并且定义一个名字为Shake_init的结构体(定义结构体名字要在时钟之前) 然后再名字后加 . 就能访问结构体。  ③给结构体内部加参数   至此我们第二个参数就配置完成。  4.在main.c函数中调用 我们要读入GPIOA Pin13的引脚  至此,震动传感器模块已完成
|