foggia2004

key 4v4

#include "key4v4.h"
#include "stm32f10x.h"
#include "delay.h"

/*
PA4-L1    PA0-R1
PA5-L2    PA1-R2
PA6-L3    PA2-R3
PA7-L4    PA3-R4
*/

#define R1_L GPIO_ResetBits(GPIOA,GPIO_Pin_0)
#define R2_L GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define R3_L GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define R4_L GPIO_ResetBits(GPIOA,GPIO_Pin_3)

#define R1_H GPIO_SetBits(GPIOA,GPIO_Pin_0)
#define R2_H GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define R3_H GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define R4_H GPIO_SetBits(GPIOA,GPIO_Pin_3)

#define Scanf_R1 R1_L,R2_H,R3_H,R4_H
#define Scanf_R2 R1_H,R2_L,R3_H,R4_H
#define Scanf_R3 R1_H,R2_H,R3_L,R4_H
#define Scanf_R4 R1_H,R2_H,R3_H,R4_L

#define L1_Value GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4)
#define L2_Value GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)
#define L3_Value GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6)
#define L4_Value GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7)

int Scanf_Keys()
{
	int return_value=-1;
	//R1-->Low,R2-->High,R3-->High,R4-->High
	//1,4,7,*
	Scanf_R1;
	if(L1_Value==0)
	{
		delay_ms(20);
		if(L1_Value==0)
		{
			return_value=1;
		}
	}
	
	if(L2_Value==0)
	{
		delay_ms(20);
		if(L2_Value==0)
		{
			return_value=4;
		}
	}

	if(L3_Value==0)
	{
		delay_ms(20);
		if(L3_Value==0)
		{
			return_value=7;
		}
	}

	if(L4_Value==0)
	{
		delay_ms(20);
		if(L4_Value==0)
		{
			return_value=10;
		}
	}	
	
	//R2-->High,R2-->Low,R3-->High,R4-->High
	//2,5,8,0
	Scanf_R2;
	if(L1_Value==0)
	{
		delay_ms(20);
		if(L1_Value==0)
		{
			return_value=2;
		}
	}
	
	if(L2_Value==0)
	{
		delay_ms(20);
		if(L2_Value==0)
		{
			return_value=5;
		}
	}

	if(L3_Value==0)
	{
		delay_ms(20);
		if(L3_Value==0)
		{
			return_value=8;
		}
	}

	if(L4_Value==0)
	{
		delay_ms(20);
		if(L4_Value==0)
		{
			return_value=0;
		}
	}	

	//R2-->High,R2-->High,R3-->Low,R4-->High
	//3,6,9,#
	//3,6,9,15
	Scanf_R3;
	if(L1_Value==0)
	{
		delay_ms(20);
		if(L1_Value==0)
		{
			return_value=3;
		}
	}
	
	if(L2_Value==0)
	{
		delay_ms(20);
		if(L2_Value==0)
		{
			return_value=6;
		}
	}

	if(L3_Value==0)
	{
		delay_ms(20);
		if(L3_Value==0)
		{
			return_value=9;
		}
	}

	if(L4_Value==0)
	{
		delay_ms(20);
		if(L4_Value==0)
		{
			return_value=15;
		}
	}
	
	//R2-->High,R2-->High,R3-->High,R4-->Low
	//a,b,c,d
	//a,b,c,h 
	Scanf_R4;
	if(L1_Value==0)
	{
		delay_ms(20);
		if(L1_Value==0)
		{
			return_value=11;
		}
	}
	
	if(L2_Value==0)
	{
		delay_ms(20);
		if(L2_Value==0)
		{
			return_value=12;
		}
	}

	if(L3_Value==0)
	{
		delay_ms(20);
		if(L3_Value==0)
		{
			return_value=13;
		}
	}

	if(L4_Value==0)
	{
		delay_ms(20);
		if(L4_Value==0)
		{
			return_value=14;
		}
	}
	
	return return_value;
}

void Scanf_Init()
{
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);
	
	//input
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	
	//output
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	
}

/*
3f,6 ,5b,4f,66,6d,7d,7 ,7f,6f,27,4f,7f,27,37,47 1b
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,e ,a ,b ,c ,h ,f
0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,* ,a ,b ,c ,d ,#
0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,13,14,15 16
0x40='_'
*/

  

posted on 2016-02-19 15:21  foggia2004  阅读(264)  评论(0编辑  收藏  举报

导航