|
#include "key.h"
#include "stm32f10x.h"
#include "gpio.h"
#include "usart.h"
uint8_t key_Scan()
{
uint16_t temp=0x0000;
uint8_t key_input=0x00;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; //0~3 out
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //4~7 in
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3); //output 0
temp = GPIO_ReadInputData(GPIOA); //read
key_input=(uint8_t)( temp & 0x00f0);
///////////////////////////////////////////////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; //0~3 in
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //4~7 out
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7); //output 0
temp = GPIO_ReadInputData(GPIOA); //read
key_input |= (uint8_t)(temp & 0x000f);
return key_input;
}
void Key_process(uint8_t value)
{
switch(value)
{
case 0xee:
USART_SendData(USART1,'1');
break;
case 0xde:
USART_SendData( USART1,'2');
break;
case 0xbe:
USART_SendData( USART1,'3');
break;
case 0x7e:
USART_SendData( USART1,'A');
break;
case 0xed:
USART_SendData( USART1,'4');
break;
case 0xdd:
USART_SendData( USART1,'5');
break;
case 0xbd:
USART_SendData( USART1,'6');
break;
case 0x7d:
USART_SendData( USART1,'B');
break;
case 0xeb:
USART_SendData( USART1,'*');
break;
case 0xdb:
USART_SendData( USART1,'0');
break;
case 0xbb:
USART_SendData( USART1,'#');
break;
case 0x7b:
USART_SendData( USART1,'D');
break;
case 0xe7:
USART_SendData( USART1,'7');
break;
case 0xd7:
USART_SendData( USART1,'8');
break;
case 0xb7:
USART_SendData( USART1,'9');
break;
case 0x77:
USART_SendData( USART1,'C');
break;
default:
break;
}
}
|
-
-
key.zip
2018-7-17 10:41 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
1.02 KB, 下載次數: 25, 下載積分: 黑幣 -5
|