初级会员

- 积分
- 90
- 金钱
- 90
- 注册时间
- 2015-3-31
- 在线时间
- 0 小时
|
5金钱
我可不可以上一条语句输入时,配置上拉输入,下一条语句要输出时,再设置成推挽输出,只是这样,系统会不会疯啊,(上一条要它输入,下一条又要它输出),求大神指点
#include "stm32f10x.h"
#include "key.h"
#include "sys.h"
#include "delay.h"
unsigned char result1,result2,t1,t2;
uint8_t key;
const unsigned char keys[]={0x00ee,0x00de,0x00be,0x007e,0x00ed,0x00dd,0x00bd,0x007d,0x00eb,0x00db,0x00bb,0x007b,0x00d7,0x00e7,0x00d7,0x00b7,0x0077};
void delayms (uint32_t ms)
{uint8_t t;
while(ms--)
{for(t=0;t<=120;t++);
}
}
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1| GPIO_Pin_2 | GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOF, &GPIO_InitStructure);*/
}
void KEY1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1| GPIO_Pin_2 | GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
unsigned char rdkey()
{uint8_t result1,result2,keycode,j;
t1=0x000f;
t2=0x00f0;
KEY1_Init();
GPIOA->BSRR=t1;
GPIOA->BRR = (~t1)& 0x00f0;
delay_ms(2);
KEY_Init();
result1 = (GPIO_ReadInputData(GPIOC));
delay_ms(2);
if((result1&0x000f)!=0x000f)
{ delay_ms(2);
KEY_Init();
result1 = (GPIO_ReadInputData(GPIOC));
delay_ms(2);
KEY_Init();
if((result1&0x000f)!=0x000f)
delay_ms(2);
{
KEY1_Init();
GPIOA->BSRR=t2;
GPIOA->BRR = (~t2)& 0x00f0;
KEY_Init();
result2 = (GPIO_ReadInputData(GPIOC));
delay_ms(2);
keycode=result1|result2;
for(j=0;j<=15;j++)
{if (keycode==keys[j])
{key=j;
return(key);
}
}
}
}
else GPIOC->BRR =0xff;
return (16);
}
|
|