初级会员 
  
	- 积分
 - 90
 
        - 金钱
 - 90 
 
       - 注册时间
 - 2015-3-31
 
      - 在线时间
 - 0 小时
 
 
 
 | 
 
 
 楼主 |
发表于 2015-9-15 21:44:16
|
显示全部楼层
 
 
 
回复【2楼】Admin:
 ---------------------------------
 key.c
 #include "stm32f10x.h"
 #include "key.h"
 #include "sys.h" 
 #include "delay.h"
 
 unsigned char result1,result2,t1,t2;
 
 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++);
 }
 }
 
 uint8_t rdkey()
 {uint8_t scan1,scan2,keycode,j;
 
 t1=0x000f;
 t2=0x00f0;
 KEY1_Init();
 GPIOA->BSRR=t1;
 GPIOA->BRR = (~t1)& 0x00f0;
 result1 = (GPIO_ReadInputData(GPIOA));
 if((result1&0x000f)!=0x000f)
 { delayms(30);
 result1 = (GPIO_ReadInputData(GPIOA));
 if((result1&0x000f)!=0x000f)
 {
 KEY1_Init();
 GPIOA->BSRR=t2;
 GPIOA->BRR = (~t2)& 0x00f0;
 result2 = (GPIO_ReadInputData(GPIOA));
 keycode=result1|result2;
 for(j=0;j<=15;j++)
 {if (keycode==keys[j])
 {key=j;
 return(key);
 }
 }
 }
 }
 else GPIOA->BRR =0xff;
 return (16);
 } 
 
 /*void main( int)
 {while(1)
 {
 t1=0x000f;
 KEY1_Init();
 GPIOA->BSRR=t1;
 GPIOA->BRR = (~t1)& 0x00f0;
 	result1 = (GPIO_ReadInputData(GPIOA));
 if((result1&0x000f)!=0x000f)
 {
 rdkey();
 }
 }}*/ |   
 
 
 
 |