中级会员
 
- 积分
- 369
- 金钱
- 369
- 注册时间
- 2013-12-23
- 在线时间
- 32 小时
|
5金钱
在网上发现了这样一段GPIO口的初始化程序,这段代码是用来初始化USART1的两个GPIO口的,但是他的代码和我所知所用的代码完全不同,而且我在3.5的库中没有找到这些函数和结构体成员,但是我发现网上还有不少类似的代码,难道这些函数是作者自己封装的?如果是,这样有什么意义?这不是增加了阅读它代码的人的理解难度吗?如果不是这些东西的出处在哪里?所以想请教一下为什么可以这样写?
void USART1_INIT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
/* Connect PXx to USARTx_Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_USART1);//PA9-TX
/* Connect PXx to USARTx_Rx */
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);//PA10-RX
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/* USART configuration */
USART_Init(USART1,&USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
}
首先他用AHB时钟使能GPIO,好像APB是挂在AHB上的如果是那么这里可以理解,但是下面的GPIO_PinAFConfig、
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
我都是第一次见到,还请高人指教啊
|
|