首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

FPGA矩阵键盘(2)

FPGA矩阵键盘(2)

  •   Proc_Scan:process(Clk_5ms)  
  •     begin  
  •         if(rising_edge(Clk_5ms)) then  
  •             case Current_Scan is  
  •                 when st_scan1 =>  
  •                     Key_Scan <= "1110";  
  •                     Current_Scan <= st_scan2;  
  •                 when st_scan2 =>  
  •                     Key_Scan <= "1101";  
  •                     Current_Scan <= st_scan3;  
  •                 when st_scan3 =>  
  •                     Key_Scan <= "1011";  
  •                     Current_Scan <= st_scan4;  
  •                 when st_scan4 =>  
  •                     Key_Scan <= "0111";  
  •                     Current_Scan <= st_scan1;  
  •             end case;  
  •         end if;  

  •     end process Proc_Scan;  

  •     KeyScan <= Key_Scan;  
  •     Key_Decode <= Key_Scan & Keyin;  

  •     Proc_Keyboard:process(Clk_2ms,Reset)  
  •     variable cnt_btn : integer range 0 to 50000 := 0;  
  •     begin  
  •         if(Reset = '1') then  
  •             LED <=   x"1";  
  •             Current_Key <= st_key1;  
  •         elsif(falling_edge(Clk_2ms)) then  
  •             case Current_Key is  
  •                 when st_key1 =>              --Check whether any keys are pressed  
  •                     if((Keyin and "1111") = "1111") then   
  •                         Current_Key <= st_key1;  
  •                     else  
  •                         Current_Key <= st_key2;  
  •                     end if;  
  •                 when st_key2 =>              --keys debouncing  
  •                     if((Keyin and "1111") = "1111") then   
  •                         Current_Key <= st_key1;  
  •                     else  
  •                         case Key_Decode is  
  •                             when "11101110" => LED <= "0001";  
  •                             when "11101101" => LED <= "0010";  
  •                             when "11101011" => LED <= "0011";  
  •                             when "11100111" => LED <= "1010";  
  •                             when "11011110" => LED <= "0100";  
  •                             when "11011101" => LED <= "0101";  
  •                             when "11011011" => LED <= "0110";  
  •                             when "11010111" => LED <= "1011";  
  •                             when "10111110" => LED <= "0111";  
  •                             when "10111101" => LED <= "1000";  
  •                             when "10111011" => LED <= "1001";  
  •                             when "10110111" => LED <= "1100";  
  •                             when "01111110" => LED <= "1110";  
  •                             when "01111101" => LED <= "0000";  
  •                             when "01111011" => LED <= "1111";  
  •                             when "01110111" => LED <= "1101";                                                              when others     => null;      
  •                         end case;  
  •                     end if;  
  •                         Current_Key <= st_key3;  
  •                 when st_key3 =>          --Check whether the pressed keys are released  
  •                     if((Keyin and "1111") /= "1111") then   
  •                         Current_Key <= st_key3;  
  •                     else  
  •                         Current_Key <= st_key4;  
  •                     end if;  
  •                 when st_key4 =>              --keys debouncing  
  •                     if((Keyin and "1111") /= "1111") then   
  •                         Current_Key <= st_key3;  
  •                     else  
  •                         LED <=   x"0";  
  •                         Current_Key <= st_key1;  
  •                     end if;  
  •             end case;  
  •         end if;  
  •     end process Proc_Keyboard;  

  • end Behavioral;  
继承事业,薪火相传
返回列表