刚开始学,突然不太清楚数码管动态显示问题了,写的程序不能同时显示4位数码管,时间还是听精确的
晶振50M
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
EN
tiTY CLOCK1 IS
PORT(CLK:IN STD_LOGIC;
DATAOUT:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
EN_COM:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END ENTITY;
ARCHITECTURE BEHAVIORAL OF CLOCK1 IS
SIGNAL CLK1,CLK2:STD_LOGIC;
SIGNAL DATA:STD_LOGIC_VECTOR(7 DOWNTO 0);
signal EN:STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL COUNTER:INTEGER RANGE 0 TO 9;
signal counter1:integer range 0 to 9;
signal counter2:integer range 0 to 5;
signal counter3:integer range 0 to 9;
signal counter4:integer range 0 to 5;
SIGNAL FIRST,SECOND,THIRD,LAST:STD_LOGIC:='0';
SIGNAL SEG:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
DATAOUT<=DATA;
EN_COM<=EN;
seg<=third & second & first & LAST;
PROCESS(CLK)
VARIABLE X:INTEGER RANGE 0 TO 24999999;
BEGIN
IF clk'event and clk='1' THEN
IF X<24999999 THEN
X:=X+1;
ELSE
X:=0;
CLK1<=NOT CLK1;
END IF;
END IF;
END PROCESS;
process(clk)
VARIABLE y:INTEGER RANGE 0 TO 2000000;
BEGIN
IF clk'event and clk='1' THEN
IF y<2000000 THEN
y:=y+1;
ELSE
y:=0;
CLK2<=NOT CLK2;
END IF;
END IF;
END PROCESS;
PROCESS(CLK1,LAST)
BEGIN
IF RISING_EDGE(CLK1)THEN
IF(counter1=9 OR LAST='1')THEN
COUNTER1<=0;
FIRST<='1';
ELSE
FIRST<='0';
counter1<=counter1+1;
END IF;
END IF;
END PROCESS;
PROCESS(FIRST)
BEGIN
IF first='1' THEN
IF counter2=5 THEN
counter2<=0;
SECOND<='1';
ELSE
SECOND<='0';
counter2<=counter2+1;
END IF;
END IF;
END PROCESS;
PROCESS(SECOND)
BEGIN
IF second='1' THEN
IF counter3=9 THEN
counter3<=0;
THIRD<='1';
ELSE
THIRD<='0';
counter3<=counter3+1;
END IF;
END IF;
END PROCESS;
PROCESS(THIRD)
BEGIN
IF third='1' THEN
IF counter4=5 THEN
counter4<=0;
LAST<='1';
ELSE
LAST<='0';
counter4<=counter4+1;
END IF;
END IF;
END PROCESS;
process(clk2,seg)
begin
if rising_edge(clk2) then
case seg is
when "0001" => en <= "1110";
when "0010" => en <= "1101";
when "0100" => en <= "1011";
when "1000" => en <= "0111";
when others => en <= "1110";
end case;
end if;
end process;
PROCESS(EN)
BEGIN
CASE EN IS
WHEN "1110"=> COUNTER <=COUNTER1;
WHEN "1101"=> COUNTER <=COUNTER2;
WHEN "1011"=> COUNTER <=COUNTER3;
WHEN "0111"=> COUNTER <=COUNTER4;
when others=> counter <=0;
END CASE;
end process;
PROCESS(counter)
BEGIN
CASE COUNTER IS
WHEN 0=> DATA <="01000000"; -- 0
WHEN 1=> DATA <="01111001"; -- 1
WHEN 2=> DATA <="00100100"; -- 2
WHEN 3=> DATA <="00110000"; -- 3
WHEN 4=> DATA <="00011001";
WHEN 5=> DATA <="00010010";
WHEN 6=> DATA <="00000010";
WHEN 7=> DATA <="01111000";
WHEN 8=> DATA <="00000000";
WHEN 9=> DATA <="00010000";
END CASE;
end process;
END BEHAVIORAL;
一周热门 更多>