初级会员

- 积分
- 80
- 金钱
- 80
- 注册时间
- 2015-5-23
- 在线时间
- 0 小时
|
5金钱
这个是我的io口配置函数
void KEY_Init(void) //IO初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);//使能PORTE时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;//PE0~5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化GPIOE
}
接下来是我的宏定义
#define KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_0)//读取按键0
#define KEY1 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_1)//读取按键1
#define KEY2 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2)//读取按键2
#define KEY3 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)//读取按键3
#define KEY4 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4)//读取按键4
#define KEY5 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_5)//读取按键5
void KEY_CHECK ( void )
{
//检测是否控制1号舵机
if ( KEY0 == KEY_DOWN ) {
txbuf[0] = 0 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
if ( KEY1 == KEY_DOWN ) {
txbuf[0] = 1 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
//检测是否控制2号舵机
if ( KEY2 == KEY_DOWN ) {
txbuf[1] = 0 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
if ( KEY3 == KEY_DOWN ) {
txbuf[1] = 1 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
//检测是否控制3号舵机
if ( KEY4 == KEY_DOWN ) {
txbuf[2] = 0 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
if ( KEY5 == KEY_DOWN ) {
txbuf[2] = 1 ;
GPIO_ResetBits(GPIOB, GPIO_Pin_0 );
delay ( 0x4fffef ) ;
GPIO_SetBits(GPIOB, GPIO_Pin_0 );
}
}
这里的PB0是接的led,这几个口接地以后led并没有亮
求助各位大神帮忙看看,指点指点
|
|