EDA与VHDL知识点总结与期末考试试卷及答案
四、VHDL程序改错:(10分)
01 LIBRARY IEEE ;
02 USE IEEE.STD_LOGIC_1164.ALL ;
03 USE IEEE.STD_LOGIC_UNSIGNED.ALL;
04 ENTITY LED7CNT IS
05 PORT ( CLR : IN STD_LOGIC;
06 CLK : IN STD_LOGIC;
07 LED7S : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ) ; 08 END LED7CNT;
09 ARCHITECTURE one OF LED7CNT IS
10 SIGNAL TMP : STD_LOGIC_VECTOR(3 DOWNTO 0);
11 BEGIN
12 CNT:PROCESS(CLR,CLK)
13 BEGIN
14 IF CLR = '1' THEN
15 TMP <= 0;
16 ELSE IF CLK'EVENT AND CLK = '1' THEN 17 TMP <= TMP + 1;
18 END IF;
19 END PROCESS;
20 OUTLED:PROCESS(TMP)
21 BEGIN
22 CASE TMP IS
23 WHEN "0000" => LED7S <= "0111111" ; 24 WHEN "0001" => LED7S <= "0000110" ; 25 WHEN "0010" => LED7S <= "1011011" ; 26 WHEN "0011" => LED7S <= "1001111" ; 27 WHEN "0100" => LED7S <= "1100110" ; 28 WHEN "0101" => LED7S <= "1101101" ; 29 WHEN "0110" => LED7S <= "1111101" ; 30 WHEN "0111" => LED7S <= "0000111" ; 31 WHEN "1000" => LED7S <= "1111111" ; 32 WHEN "1001" => LED7S <= "1101111" ; 33 WHEN OTHERS => LED7S <= (OTHERS => '0'); 34 END CASE;
35 END PROCESS;
36 END one;
在程序中存在两处错误,试指出,并说明理由:
提示:在MAX+PlusII 10.2上编译时报出的第一条错误为:
Error:Line 15: File ***/led7cnt.vhd: Type error: type in waveform element must be “std_logic_vector”
第 15 行, 错误:整数0不能直接赋值给TMP矢量
改正:TMP <= (OTHERS => ‘0’);