?? state.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity State is
port(
Clk_20M:in std_logic; --20M時鐘,用于分頻
Ctrl:in std_logic_vector(2 downto 0); --模式選擇控制,用S1撥盤實現
Tone:in integer range 0 to 21; --音符
Dout:out std_logic_vector(6 downto 0); --數碼管數據信號
Leds:out std_logic_vector(5 downto 0); --數碼管選通信號
Key_Leds:out std_logic_vector(7 downto 0) --輸出音階的LED顯示
);
end State;
architecture code of State is
signal Clk_div,Clk_free:std_logic;
signal L0,L1,L2,L3,L4,L5,Tem:std_logic_vector(4 downto 0);
signal D45: std_logic_vector(4 downto 0):="10101";
begin
process(Clk_20M)
variable cnt:std_logic_vector(10 downto 0);
variable free_t:std_logic_vector(22 downto 0);
begin
if Clk_20M'event and Clk_20M='1' then
cnt:=cnt+'1';
free_t:=free_t+'1';
if free_t="11111111111100000000000" then
Clk_free<='1';
else
if free_t="11111111111111111111111" then
Clk_free<='0';
end if;
end if;
if cnt="11111111111" then
Clk_div<='1';
else
if cnt="11111111110" then
Clk_div<='0';
end if;
end if;
end if;
end process;
process(Clk_div)
variable choice:std_logic_vector(2 downto 0);
begin
if Clk_div'event and Clk_div='0' then
case choice is
when "000" =>Leds<="011111";Tem<=L5;choice:="001";
when "001" =>Leds<="101111";Tem<=L4;choice:="010";
when "010" =>Leds<="110111";Tem<=L3;choice:="011";
when "011" =>Leds<="111011";Tem<=L2;choice:="100";
when "100" =>Leds<="111101";Tem<=L1;choice:="101";
when "101" =>Leds<="111110";Tem<=L0;choice:="000";
when others =>Leds<="111111";
end case;
case Ctrl is
when "001" =>L3<="01010";L2<="00110";L1<="01100";L0<="00111"; --HAND
when "010" =>L3<="01101";L2<="01011";L1<="00110";L0<="10000"; --PLAY
when "100" =>L3<="00110";L2<="01111";L1<="01110";L0<="00111"; --AUTO
when others =>L3<="01001";L2<="00110";L1<="01000";L0<="01000"; --FREE
end case;
end if;
end process;
process(Tem)
begin
Key_Leds<="00000000";
case Tem is
when "00000" =>Dout<="0000001";Key_Leds<="10000001"; --top
when "00001" =>Dout<="0000010";Key_Leds<="11000011"; --r1
when "00010" =>Dout<="0000100";Key_Leds<="11100111"; --r2
when "00011" =>Dout<="0001000";Key_Leds<="11111111"; --bottom
when "00100" =>Dout<="0010000";Key_Leds<="11100111"; --l2
when "00101" =>Dout<="0100000";Key_Leds<="11000011"; --l1
when "00110" =>Dout<="1110111"; --A,R
when "00111" =>Dout<="0111111"; --D,O
when "01000" =>Dout<="1111001"; --E
when "01001" =>Dout<="1110001"; --F
when "01010" =>Dout<="1110110"; --H
when "01011" =>Dout<="0111000"; --L
when "01100" =>Dout<="0110111"; --N
when "01101" =>Dout<="1110011"; --P
when "01110" =>Dout<="0000111"; --T
when "01111" =>Dout<="0111110"; --U
when "10000" =>Dout<="1101110"; --Y
when "10001" =>Dout<="0000001"; --HIGH
when "10010" =>Dout<="1000000"; --MIDDLE
when "10011" =>Dout<="0001000"; --LOW
when "10100" =>Dout<="0000110";Key_Leds<="00000011"; --1
when "10101" =>Dout<="1011011";Key_Leds<="00000111"; --2
when "10110" =>Dout<="1001111";Key_Leds<="00001111"; --3
when "10111" =>Dout<="1100110";Key_Leds<="00011111"; --4
when "11000" =>Dout<="1101101";Key_Leds<="00111111"; --5
when "11001" =>Dout<="1111101";Key_Leds<="01111111"; --6
when "11010" =>Dout<="0000111";Key_Leds<="11111111"; --7
when others =>Dout<="0000000";Key_Leds<="00000000";
end case;
end process;
process(Tone,Clk_free,Ctrl)
begin
if(Ctrl="001" or Ctrl="010" or Ctrl="100") then
case Tone is
when 1 =>L4<="10100";L5<="10011"; --1
when 2 =>L4<="10101";L5<="10011"; --2
when 3 =>L4<="10110";L5<="10011"; --3
when 4 =>L4<="10111";L5<="10011"; --4
when 5 =>L4<="11000";L5<="10011"; --5
when 6 =>L4<="11001";L5<="10011"; --6
when 7 =>L4<="11010";L5<="10011"; --7
when 8 =>L4<="10100";L5<="10010"; --8
when 9 =>L4<="10101";L5<="10010"; --9
when 10 =>L4<="10110";L5<="10010"; --10
when 11 =>L4<="10111";L5<="10010"; --11
when 12 =>L4<="11000";L5<="10010"; --12
when 13 =>L4<="11001";L5<="10010"; --13
when 14 =>L4<="11010";L5<="10010"; --14
when 15 =>L4<="10100";L5<="10001"; --15
when 16 =>L4<="10101";L5<="10001"; --16
when 17 =>L4<="10110";L5<="10001"; --17
when 18 =>L4<="10111";L5<="10001"; --18
when 19 =>L4<="11000";L5<="10001"; --19
when 20 =>L4<="11001";L5<="10001"; --20
when 21 =>L4<="11010";L5<="10001"; --21
when others =>L4<="11111";L5<="11111"; --OTHERS
end case;
else
if Clk_free'event and Clk_free='1' then
if(D45="00101") then
D45<="00000";
else
D45<=D45+1;
end if;
L4<=D45;L5<=D45;
end if;
end if;
end process;
end code;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -