#include "keypad.h" #include "delay.h" #include "led.h" //void KEY_Init(void) //{ // GPIO_InitTypeDef GPIO_InitStructure; // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); // GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; // GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; // GPIO_Init(GPIOE,&GPIO_InitStructure); //} //u8 KEY_Scan(void) //{ // if((KEY0==0)||(KEY1==0)||(KEY2==0)||(KEY3==0)) // { // delay_ms(20); // if(KEY0==0){while(KEY0==0);return 1;} // else if(KEY1==0){while(KEY1==0);return 2;} // else if(KEY2==0){while(KEY2==0);return 3;} // else if(KEY3==0){while(KEY3==0);return 4;} // } // return 0; //} //ÐÐÖÃΪÊäÈë ĬÈÏΪ1 ÁÐÖÃΪÊä³öĬÈÏΪ0 ɨÃèÐÐ void HL_Init_HScan(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;//ÐÐ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;//ÁÐ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_ResetBits(GPIOB,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); } //ÐÐÖÃΪÊä³ö ĬÈÏΪ0 ÁÐÖÃΪÊäÈëĬÈÏΪ1 ɨÃèÁÐ void HL_Init_LScan(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_ResetBits(GPIOB,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11); } u8 HL_Scan(void) { u16 temp=0; u8 key; HL_Init_HScan(); temp=GPIO_ReadInputData(GPIOB); temp&=0x0f00; //¼ì²âÐÐÖеÄ0 if(temp==0x0e00)//µÚÒ»ÐÐÓа´¼ü±»°´Ï { key=1 ; } else if(temp==0x0d00) { key=2;LED0=1; } else if(temp==0x0b00) { key=3;LED0=1; } else if(temp==0x0700) { key=4;LED0=1; } HL_Init_LScan(); temp=GPIO_ReadInputData(GPIOB); temp&=0xf000;//µÃµ½¸ßËÄλ ¼´ÁÐÊý¾Ý if((temp==0xe000)&&(key!=0))//µÚÒ»Áб»°´Ï { key=(key-1)*4+1; }else if((temp==0xd000)&&(key!=0)) { key=(key-1)*4+2; }else if((temp==0xb000)&&(key!=0)) { key=(key-1)*4+3; }else if((temp==0x7000)&&(key!=0)) { key=(key-1)*4+4; } else key=0; return key; } |