初级会员

- 积分
- 174
- 金钱
- 174
- 注册时间
- 2014-3-5
- 在线时间
- 0 小时
|

楼主 |
发表于 2014-4-28 20:26:26
|
显示全部楼层
传感器端口与其他端口分开配置的
void SENSOR_GPIO_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
//U101, L-H
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ; //前方障碍物
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉引脚,检测障碍物
GPIO_Init(GPIOC, &GPIO_InitStructure) ;
//CLH
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; //左方碰触开关
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉引脚,检测障碍物
// GPIO_Init(GPIOC, &GPIO_InitStructure) ;
//CRH
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ; //右方碰触开关
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉引脚,检测障碍物
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,GPIO_Pin_13);
//U81,U87,U78,U714 L-H
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7| GPIO_Pin_8|GPIO_Pin_10| GPIO_Pin_12 ; //防跌落
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉引脚,检测障碍物
GPIO_Init(GPIOC, &GPIO_InitStructure) ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ; //悬空碰触开关
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉引脚,检测障碍物//
GPIO_Init(GPIOD, &GPIO_InitStructure);
//J162(H_PW)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 ; //红外接收
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//由高到脉冲
GPIO_Init(GPIOD, &GPIO_InitStructure);
//J34(H_PW)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ; //左侧光电编码
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//由高到脉冲
GPIO_Init(GPIOE, &GPIO_InitStructure);
//J64(H_PW)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; //右侧光电编码
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//由高到脉冲
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/*  A0,PA12-> 左右脉冲输入 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIOA, &GPIO_InitStructure);
//PE5输入到PA0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PE.5 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOE, &GPIO_InitStructure);
//LCD1602(DO~D7)对应STM32的GPIO口(PB8~PB15)
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//LCD1602的(RS、RS、E)对应STM32的GPIO口(PD11、PD10、PD9)
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_8|GPIO_Pin_9 | GPIO_Pin_10);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// U113,CRH, J162(H_PW),KEY1 ,6,9,10
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_1|GPIO_Pin_0|GPIO_Pin_4 |GPIO_Pin_5 |GPIO_Pin_6 );
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //
GPIO_Init(GPIOD, &GPIO_InitStructure);
// U88L,KEY5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //
GPIO_Init(GPIOD, &GPIO_InitStructure);
// U814(L)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; //左方碰触开关
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉引脚,检测障碍物
GPIO_Init(GPIOC, &GPIO_InitStructure) ;
GPIO_SetBits(GPIOC,GPIO_Pin_9);///
//SPEAKER(H-PW),MORTOR(H-L),KRL ,U1110 ,j142(PE13.PWM) ,j53h
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_14);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_9);
GPIO_SetBits(GPIOE,GPIO_Pin_10);
GPIO_ResetBits(GPIOE,GPIO_Pin_11);
GPIO_SetBits(GPIOE,GPIO_Pin_12);
// GPIO_ResetBits(GPIOE,GPIO_Pin_13); //
GPIO_ResetBits(GPIOE,GPIO_Pin_14);
//J81(H-L)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,GPIO_Pin_11);
// //ENA/BH
// GPIO_InitStructure.GPIO_Pin =(GPIO_Pin_6 | GPIO_Pin_7);
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_SetBits(GPIOA,GPIO_Pin_6);
// GPIO_SetBits(GPIOA,GPIO_Pin_7);
////PWMA.PWMB
// GPIO_InitStructure.GPIO_Pin =(GPIO_Pin_0 | GPIO_Pin_1);
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
// GPIO_SetBits(GPIOB,GPIO_Pin_0);
// GPIO_SetBits(GPIOB,GPIO_Pin_1);
//U19,U119
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_ResetBits(GPIOC,GPIO_Pin_4);
// GPIO_ResetBits(GPIOC,GPIO_Pin_5);
GPIO_SetBits(GPIOC,GPIO_Pin_5);
//J142
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13; //OC3N OC3
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_ResetBits(GPIOE,GPIO_Pin_13); //
} |
|