标题:
请问有TFT彩屏显示矩阵按键键值程序吗 求帮助
[打印本页]
作者:
sacredyy
时间:
2018-5-3 17:20
标题:
请问有TFT彩屏显示矩阵按键键值程序吗 求帮助
在TFT上显示矩阵按键对应的数字
作者:
18783482071
时间:
2018-7-9 10:58
#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; }
作者:
18783482071
时间:
2018-7-9 10:58
#include "led.h" #include "key.h" #include "delay.h" #include "usart1.h" #include "usart2.h" int main(void) { u8 keyval=0; LED_Init(); // KEY_Init(); delay_init(); NVIC_Configuration(); USART1_Init(115200); USART2_Init(115200); while(1) { keyval=HL_Scan(); if(keyval!=0) printf("\r\nkeyval:%d\r\n",keyval); switch(keyval) { case 1:LED2=0; break; case 2:LED2=!LED2; break; case 3:LED3=0; break; case 4:LED3=!LED3; break; case 5:LED0=0; break; case 6:LED0=!LED0; break; case 7:LED1=0; break; case 8:LED1=!LED1; break; case 9:LED4=0; break; case 10:LED4=!LED4; break; case 11:LED5=0; break; case 12:LED5=!LED5; break; case 13:LED6=0; break; case 14:LED6=!LED6; break; case 15:LED7=0; break; case 16:LED7=!LED7; break; default: break; } // delay_ms(20); } }
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1