uint8_t Key_GetNum(void)
{
uint8_t KeyNum = 0;
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6) == 0);
Delay_ms(20);
KeyNum = 1;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7) == 0);
Delay_ms(20);
KeyNum = 2;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8) == 0);
Delay_ms(20);
KeyNum = 3;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9) == 0);
Delay_ms(20);
KeyNum = 4;
}
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) == 0);
Delay_ms(20);
KeyNum = 5;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == 0);
Delay_ms(20);
KeyNum = 6;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) == 0);
Delay_ms(20);
KeyNum = 7;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14) == 0);
Delay_ms(20);
KeyNum = 8;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15) == 0);
Delay_ms(20);
KeyNum = 9;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10) == 0);
Delay_ms(20);
KeyNum = 10;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_11) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_11) == 0);
Delay_ms(20);
KeyNum = 11;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_12) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_12) == 0);
Delay_ms(20);
KeyNum = 12;
}
if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2) == 0);
Delay_ms(20);
KeyNum = 13;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5) == 0);
Delay_ms(20);
KeyNum = 14;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6) == 0);
Delay_ms(20);
KeyNum = 15;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7) == 0);
Delay_ms(20);
KeyNum = 16;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) == 0);
Delay_ms(20);
KeyNum = 17;
}
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == 0);
Delay_ms(20);
KeyNum = 18;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == 0);
Delay_ms(20);
KeyNum = 19;
}
if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5) == 0)
{
Delay_ms(20);
while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5) == 0);
Delay_ms(20);
KeyNum = 20;
}
return KeyNum;
}我觉得该代码有些重复了,帮我优化一下