[問題] VHDL dip switch 呈現七段顯示器

看板PLT (程式語言與理論)作者 (蹦蹦跳跳)時間17年前 (2007/11/11 17:17), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
利用Dip0~5 輸入BCD碼 然後七段顯示顯示結果 EX:11111 =>31 00001 =>1 00010 = 2 00011 = 3 00100 = 4 00101 = 5 00110 = 6 00111 = 7 01000 = 8 01001 = 9 01010 = 10 01011 = 11 01100 = 12 01101 = 13 01110 = 14 01111 = 15 10000 = 16 10001 = 17 10010 = 18 10011 = 19 10100 = 20 10101 = 21 10110 = 22 10111 = 23 11000 = 24 11001 = 25 11010 = 26 11011 = 27 11100 = 28 11101 = 29 11110 = 30 11111 = 31 這段程式碼要怎樣改加入呢 SEGMENT <= "00000" when "0000", --0 還要再用if DIP(4 downto 0) = "00000" then SEGMENT <= "00000" when "0000", --0 是這樣嗎 如果是的話 以下31種都是用這種方法嗎 那要加在哪邊呢 謝謝 對VHDL還是不太熟呀 --**************************************** --* Counter From 00 To 31 And Display * --* In Scanning Seven Segment LED * --* Filename : SEGMENT_COUNT_00_23.VHD * --**************************************** library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity SEGMENT_COUNT_00_31 is Port ( CLK : in std_logic; RESET : in std_logic; POINTER : out std_logic; ENABLE : out std_logic_vector(6 downto 1); SEGMENT : out std_logic_vector(6 downto 0)); end SEGMENT_COUNT_00_23; architecture Behavioral of SEGMENT_COUNT_00_23 is signal COUNT_24 : std_logic; signal CLEAR : std_logic; signal SCAN_CLK : std_logic; signal COUNT_CLK : std_logic; signal POSITION : std_logic_vector(6 downto 1); signal DIVIDER : std_logic_vector(24 downto 1); signal COUNT_BCD : std_logic_vector(7 downto 0); signal DECODE_BCD : std_logic_vector(3 downto 0); begin --*************************** --* Time Base Generation * --*************************** process (CLK,RESET) begin if RESET = '0' then DIVIDER <= "000000000000000000000000"; elsif CLK'event and CLK = '1' then DIVIDER <= DIVIDER + 1; end if; end process; SCAN_CLK <= DIVIDER(15); COUNT_CLK <= DIVIDER(24); --********************************** --* Counter Range From 00 to 31 * --********************************** process (COUNT_CLK,CLEAR) begin if CLEAR = '0' then COUNT_BCD <= "00000000"; elsif COUNT_CLK'event and COUNT_CLK = '1' then if COUNT_BCD(3 downto 0) = "1001" then COUNT_BCD(3 downto 0) <= "0000"; COUNT_BCD(7 downto 4) <= COUNT_BCD(7 downto 4) + 1; else COUNT_BCD(3 downto 0) <= COUNT_BCD(3 downto 0) + 1; end if; end if; end process; CLEAR <= RESET and COUNT_24; COUNT_24 <= '0' when COUNT_BCD(7 downto 0) = "00100100" else '1'; --********************************************* --* Decide Seven Segment's Display Location * --********************************************* process (SCAN_CLK,RESET) begin if RESET = '0' then POSITION <= "111110"; elsif SCAN_CLK'event and SCAN_CLK = '1' then POSITION <= "1111" & POSITION(1) & POSITION(2); end if; end process; ENABLE <= POSITION; --********************************************* --* Decide Seven Segment's Display Location * --********************************************* process (POSITION,COUNT_BCD) begin case POSITION is when "111110" => DECODE_BCD <= COUNT_BCD(3 downto 0); when "111101" => DECODE_BCD <= COUNT_BCD(7 downto 4); when others => null; end case; end process; --*********************************** --* BCD To Seven Segment Decoder * --*********************************** with DECODE_BCD select SEGMENT <= "1000000" when "0000", --0 "1111001" when "0001", --1 "0100100" when "0010", --2 "0110000" when "0011", --3 "0011001" when "0100", --4 "0010010" when "0101", --5 "0000010" when "0110", --6 "1111000" when "0111", --7 "0000000" when "1000", --8 "0010000" when "1001", --9 "1111111" when others; POINTER <= '1'; end Behavioral; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.127.49.48

11/17 22:01, , 1F
when 不能放在if裡面吧?
11/17 22:01, 1F
文章代碼(AID): #17DiYZU_ (PLT)
文章代碼(AID): #17DiYZU_ (PLT)