EDA中的数字时钟用VHDL语言怎么做

2024-11-26 19:16:16
推荐回答(1个)
回答(1):

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity dongtai is
port(clk,rest:in std_logic;
seg,led:out std_logic_vector(7 downto 0));
end dongtai;

architecture action of dongtai is
signal counter,counter2,counter3,counter4,counter5,counter7,counter8,counter9:integer:=0;
signal counter1:std_logic_vector(7 downto 0);
begin

clock:process
variable tmp,tmp1,count,count2,count3,count4,count5,count7,count8,count9:integer:=0;
begin
wait until clk='1';
tmp:=tmp+1;
tmp1:=tmp1+1;

if(tmp1=50000000)then
count2:=count2+1;
counter2<=count2;
tmp1:=0;------111
if(count2=10)then
count2:=0;
count3:=count3+1;
counter3<=count3;---222
if(count3=6)then
count3:=0;
count4:=count4+1;
counter4<=count4;---444
if(count4=10)then
count4:=0;
count5:=count5+1;
counter5<=count5;---555
if(count5=6)then
count5:=0;
count7:=count7+1;
counter7<=count7;----777
if(count7=10)then
count7:=0;
count8:=count8+1;
counter8<=count8;----8888
if(count8>3)then
count8:=0;
end if;
end if;
end if;
end if;
end if;
end if;
end if;
if(count8=2 and count7=3 and count5=5 and count4=9 and count3=5 and count2=9 )then
tmp:=0;
tmp1:=0;
count:=0;
count2:=0;
count3:=0;
count4:=0;
count5:=0;
count7:=0;
count8:=0;
count9:=0;
counter<=0;
counter2<=0;
counter3<=0;
counter4<=0;
counter5<=0;
counter7<=0;
counter8<=0;
counter9<=0;
end if;
if(tmp=250)then
count:=count+1;
counter<=count;
tmp:=0;
if(count=8)then
count:=0;
end if;
end if;
end process clock;

scan:process(counter)
variable tmp:std_logic_vector(7 downto 0);
begin
case counter is
when 1=>tmp:="11111110";
when 2=>tmp:="11111101";
when 3=>tmp:="11111011";
when 4=>tmp:="11110111";
when 5=>tmp:="11101111";
when 6=>tmp:="11011111";
when 7=>tmp:="10111111";
when 8=>tmp:="01111111";
when others=>tmp:="11111111";
end case;
seg<=tmp;
counter1<=tmp;
end process scan;

yima:process(counter1,counter2,counter3,counter4,counter5,counter7,counter8)
variable tmp:std_logic_vector(7 downto 0);
begin
case counter1 is

when "11111110"=>
case counter2 is -------111
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when 4 =>tmp:="10011001";
when 5 =>tmp:="10010010";
when 6 =>tmp:="10000010";
when 7 =>tmp:="11111000";
when 8 =>tmp:="10000000";
when 9 =>tmp:="10010000";
when others=>tmp:="11000000";
end case;

when "11111101"=>
case counter3 is -----222
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when 4 =>tmp:="10011001";
when 5 =>tmp:="10010010";

when others=>tmp:="11000000";
end case;

when "11111011"=>
case counter2 is ----333
when 0 =>tmp:="11111111";
when 1 =>tmp:="10111111";
when 2 =>tmp:="11111111";
when 3 =>tmp:="10111111";
when 4 =>tmp:="11111111";
when 5 =>tmp:="10111111";
when 6 =>tmp:="11111111";
when 7 =>tmp:="10111111";
when 8 =>tmp:="11111111";
when 9 =>tmp:="10111111";
when others=>tmp:="11111111";
end case;

when "11110111"=>
case counter4 is ----444
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when 4 =>tmp:="10011001";
when 5 =>tmp:="10010010";
when 6 =>tmp:="10000010";
when 7 =>tmp:="11111000";
when 8 =>tmp:="10000000";
when 9 =>tmp:="10010000";
when others=>tmp:="11000000";
end case;

when "11101111"=>
case counter5 is ----555
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when 4 =>tmp:="10011001";
when 5 =>tmp:="10010010";

when others=>tmp:="11000000";
end case;

when "11011111"=>
case counter2 is ----666
when 0 =>tmp:="11111111";
when 1 =>tmp:="10111111";
when 2 =>tmp:="11111111";
when 3 =>tmp:="10111111";
when 4 =>tmp:="11111111";
when 5 =>tmp:="10111111";
when 6 =>tmp:="11111111";
when 7 =>tmp:="10111111";
when 8 =>tmp:="11111111";
when 9 =>tmp:="10111111";
when others=>tmp:="11111111";
end case;

when "10111111"=>
if(counter8<2)then
case counter7 is ----777
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when 4 =>tmp:="10011001";
when 5 =>tmp:="10010010";
when 6 =>tmp:="10000010";
when 7 =>tmp:="11111000";
when 8 =>tmp:="10000000";
when 9 =>tmp:="10010000";
when others=>tmp:="11000000";
end case;
end if;
if(counter8=2)then
case counter7 is ----777
when 0 =>tmp:="11000000";
when 1 =>tmp:="11111001";
when 2 =>tmp:="10100100";
when 3 =>tmp:="10110000";
when others=>tmp:="11000000";
end case;
end if;

when "01111111"=>
case counter8 is ----888
when 0 =>tmp:="11000000";--0
when 1 =>tmp:="11111001";--1
when 2 =>tmp:="10100100";--2
when others=>tmp:="11000000";
end case;

when others=>tmp:="11111111";
end case;
led<=tmp;
end process yima;

end action;
比较长!但比较好理解吧!