嵌入式系统课程实验
在PORTG端口实现传感器接口的功能
课程实验需要同时实现多个模块的运用,传感器接口仅有一个不能复用多个模块, 因此需要使用扩展的PORTG接口实现两个模块同时使用。
需要注意的是PORTG端口:PG0~PG15在硬件电路连线上均不存在与时钟信号(TIM)复用的端口。所以需要使用TIM时钟的模块不能在PORTG上实现。
以下以实现热释电模块(红外人体检测)在PORTG上运行为例:
#include "Pyroelectric.h"
#include "head.h"
/**************************************************************
*功能:PG4端口初始化
*参数:无
*返回值:无
**************************************************************/
void Pyroelec_GPIO(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG,ENABLE); //PORTG时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //PG4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //设置成上拉输入
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOG, &GPIO_InitStructure); //初始化GPIO PG4
}
/************************************