?? wangyicheng.vhd
字號:
-------------------------------------------------
---作者:四院四隊 王毅誠(200404015010)
------------------------------------------------
------------------------------------------------
--程序名稱:多功能時鐘設計
--實現功能:
--1.時鐘時分秒顯示
--2.時間調整功能
--3.定時鬧時功能
--輸入:inclk為24MHz
--------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity szz is
port(inclk:in std_logic;
md3:in std_logic;
md1:in std_logic;
md2:in std_logic_vector(1 downto 0);
speak:out std_logic;
EN:out std_logic;
dout:out std_logic_vector(7 downto 0);
selout:out std_logic_vector(3 downto 0));
end szz;
architecture one of szz is
signal clk:std_logic;
signal clk1:std_logic;
signal clk2:std_logic;
signal clk3:std_logic;
signal sel:std_logic_vector(2 downto 0);
signal hou1:std_logic_vector(3 downto 0);
signal hou2:std_logic_vector(3 downto 0);
signal min1:std_logic_vector(3 downto 0);
signal min2:std_logic_vector(3 downto 0);
signal seth1:std_logic_vector(3 downto 0);
signal seth2:std_logic_vector(3 downto 0);
signal setm1:std_logic_vector(3 downto 0);
signal setm2:std_logic_vector(3 downto 0);
signal sec1:std_logic_vector(3 downto 0);
signal sec2:std_logic_vector(3 downto 0);
signal h1:std_logic_vector(3 downto 0);
signal h2:std_logic_vector(3 downto 0);
signal m1:std_logic_vector(3 downto 0);
signal m2:std_logic_vector(3 downto 0);
signal s1:std_logic_vector(3 downto 0);
signal s2:std_logic_vector(3 downto 0);
-------------------------------------------------
begin
---------------------------------------------分頻出4種信號
divf:process(inclk)
variable a,b,c,d:integer;
begin
if inclk'event and inclk='1' then
if a=12E2 then
clk1<=not clk1;
a:=0;
else a:=a+1;
end if;
if b=24E6 then
clk<=not clk;
b:=0;
else b:=b+1;
end if;
if c=16#6A88# then
clk2<=not clk2;
c:=0;
else c:=c+1;
end if;
if d=16#5DC0# then
clk3<=not clk3;
d:=0;
else d:=d+1;
end if;
end if;
end process;
----------------------------------------------模4計數
choice:process(clk1)
begin
if clk1'event and clk1='1' then
if sel="011" then
sel<="000";
else
sel<=sel+1;
end if;
end if;
end process choice;
-----------------------------------------------小時十位
h110:process(clk,hou2,min1,min2,sec1,sec2,md1,md2)
begin
if clk'event and clk='1' then
if (hou1="0010" and hou2="0011")and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then
hou1<="0000";
elsif hou1="0010"and hou2="0011"and md1='0' and md2="01" then--當時間為23點且處于校時狀態時
hou1<="0000";
elsif (hou2="1001"and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001"))or (hou2="1001"and md1='0' and md2="01") then
hou1<=hou1+1;
end if;
end if;
end process h110;
-----------------------------------------------小時個位
h220:process(clk,min1,min2,sec1,sec2,md1,md2,hou1)
begin
if clk'event and clk='1' then
if (hou1="0010" and hou2="0011")and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then
hou2<="0000";
elsif hou2="1001"and(min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then
hou2<="0000";
elsif (hou2="1001"and md1='0' and md2="01")or (hou1="0010"and hou2="0011") then
hou2<="0000";--md<='1';
elsif ((min1="0101" and min2="1001") and (sec1="0101" and sec2="1001"))or (md1='0' and md2="01") then
hou2<=hou2+1;--speak<=clk;
end if;
end if;
end process h220;
-----------------------------------------------分鐘十位
m110:process(clk,min2,sec1,sec2,md1,md2)
begin
if clk'event and clk='1' then
if (min1="0101" and min2="1001") and (sec1="0101" and sec2="1001") then
min1<="0000";
elsif min1="0101"and min2="1001"and (md1='0' and md2="10")then
min1<="0000";
elsif (min2="1001"and (sec1="0101" and sec2="1001")) or (min2="1001"and md1='0' and md2="10")then
min1<=min1+1;
end if;
end if;--end if;
end process m110;
----------------------------------------------分鐘個位
m220:process(clk,sec1,sec2,md1,md2)
begin
if clk'event and clk='1' then
if min2="1001"and (sec1="0101" and sec2="1001")then
min2<="0000";
elsif min2="1001"and (md1='0' and md2="10")then
min2<="0000";
elsif (sec1="0101" and sec2="1001") or(md1='0' and md2="10")then
min2<=min2+1;
end if;
end if;
end process m220;
---------------------------------------------秒十位
s110:process(clk)
begin
if clk'event and clk='1' then
if (sec1="0101" and sec2="1001")then
sec1<="0000";
else if sec2="1001"then
sec1<=sec1+1;
end if;
end if;end if;
end process s110;
--------------------------------------------秒個位
s220:process(clk)
begin
if clk'event and clk='1' then
if sec2="1001" then
sec2<="0000";
else sec2<=sec2+1;
end if;
end if;
end process s220;
-------------------------------------------時間設置小時部分
sethour1:process(clk,seth2)
begin
if clk'event and clk='1' then
if seth1="0010"and seth2="0011" then
seth1<="0000";
elsif seth2="1001" then
seth1<=seth1+1;
end if;
end if;
end process sethour1;
-------------------------------------------
sethour2:process(clk,md1,md2,seth1)
begin
if clk'event and clk='1' then
if (seth1="0010"and seth2="0011")or seth2="1001"then
seth2<="0000";
elsif md1='1' and md2="10" then
seth2<=seth2+1;
end if;
end if;
end process sethour2;
-------------------------------------------時間設置分鐘部分
setmin1:process(clk,setm2)
begin
if clk'event and clk='1' then
if setm1="0101"and setm2="1001"then
setm1<="0000";
elsif setm2="1001"then
setm1<=setm1+1;
end if;
end if;
end process setmin1;
----------------------------------------------
setmin2:process(clk,md1,md2)
begin
if clk'event and clk='1'then
if setm2="1001"then
setm2<="0000";
elsif md1='1' and md2="01"then
setm2<=setm2+1;
end if;
end if;
end process setmin2;
--------------------------------------------
--------------------------------------------鬧鈴
speaker:process(clk1,hou1,hou2,min1,min2)
begin
if clk1'event and clk1='1'then
if seth1=hou1 and seth2=hou2 and setm1=min1 and setm2=min2 then
speak<=clk2;
else speak<='0';
end if;
end if;
end process speaker;
-------------------------------------------
-------------------------------------------
disp:process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2)
begin
EN<='0';
if sel="000" and md3='0' then
selout<="1000";
case h1 is
when "0000"=>dout<="11000000";--0
when "0001"=>dout<="11111001";--1
when "0010"=>dout<="10100100";--2
when others =>dout<="10111111";--"-"
end case;
elsif sel="001" and md3='0' then
selout<="0100";
case h2 is
when "0000"=>dout<="01000000";--0.
when "0001"=>dout<="01111001";
when "0010"=>dout<="00100100";
when "0011"=>dout<="00110000";--3.
when "0100"=>dout<="00011001";
when "0101"=>dout<="00010010";
when "0110"=>dout<="00000010";--6.
when "0111"=>dout<="01111000";
when "1000"=>dout<="00000000";
when "1001"=>dout<="00010000";
when others=>dout<="00111111";
end case;
elsif sel="010" and md3='0' then
selout<="0010";
case m1 is
when "0000"=>dout<="11000000";--0.
when "0001"=>dout<="11111001";
when "0010"=>dout<="10100100";
when "0011"=>dout<="10110000";--3.
when "0100"=>dout<="10011001";
when "0101"=>dout<="10010010";
when others=>dout<="10111111";
end case;
elsif sel="011" and md3='0' then
selout<="0001";
case m2 is
when "0000"=>dout<="11000000";--0
when "0001"=>dout<="11111001";
when "0010"=>dout<="10100100";
when "0011"=>dout<="10110000";--3
when "0100"=>dout<="10011001";
when "0101"=>dout<="10010010";
when "0110"=>dout<="10000010";--6
when "0111"=>dout<="11111000";
when "1000"=>dout<="10000000";
when "1001"=>dout<="10010000";
when others=>dout<="10111111";
end case;
elsif sel="000" and md3='1' then
selout<="0010";
case s1 is
when "0000"=>dout<="11000000";--0
when "0001"=>dout<="11111001";
when "0010"=>dout<="10100100";
when "0011"=>dout<="10110000";--3
when "0100"=>dout<="10011001";
when "0101"=>dout<="10010010";
when others=>dout<="10111111";
end case;
elsif sel="001" and md3='1' then
selout<="0001";
case s2 is
when "0000"=>dout<="11000000";--0
when "0001"=>dout<="11111001";
when "0010"=>dout<="10100100";
when "0011"=>dout<="10110000";--3
when "0100"=>dout<="10011001";
when "0101"=>dout<="10010010";
when "0110"=>dout<="10000010";--6
when "0111"=>dout<="11111000";
when "1000"=>dout<="10000000";
when "1001"=>dout<="10010000";
when others=>dout<="10111111";
end case;
elsif sel="010" and md3='1' then
selout<="0100";
dout<="01111111" ;
end if;
if md1='0' then---------------計時時間顯示和設置模式
h1<=hou1;h2<=hou2;
m1<=min1;m2<=min2;
s1<=sec1;s2<=sec2;
else -----------鬧鈴時間現實和設置模式
h1<=seth1;h2<=seth2;
m1<=setm1;m2<=setm2;
s1<="1111";s2<="1111";
end if;
end process disp;
------------------------------------------
end one;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -