📄 lxjclock.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity lxjclock is
port(clk,reset,busy,ctrl,choose:in std_logic; --时钟信号和复位信号
yout:out std_logic_vector(7 downto 0);
req:out std_logic;
alert:out std_logic
);
end lxjclock;
architecture a of lxjclock is
signal Q5,Q4,Q3,Q2,Q1,Q0,Qh,Qm :std_logic_vector(3 downto 0);
signal enmin,enhour:std_logic;
signal q:std_logic_vector(13 downto 0); --分频信号
signal p:std_logic_vector(8 downto 0);
signal clkp,clks,clkscan,clkb: std_logic; --1s时钟,扫描时钟
type state is (s0,s1,s2,s3,s4,s5);
signal p_state,n_state:state;
signal x,y,a,xx,yy,as:std_logic_vector(7 downto 0);
signal asout:std_logic_vector(3 downto 0);
signal n:std_logic_vector(1 downto 0);
signal nn:std_logic_vector(5 downto 0);
signal w,w1,r,b:std_logic;
begin
--***************************分频**********************************
--process (clk) is --分频
--begin
-- if clk'event and clk='1' then
-- if q=9999999 then --choose 20MHz
-- q<="000000000000000000000000"; --23位
-- clks<=not clks; --1Hz
-- else
-- q<=q+'1';
-- end if;
-- clkscan<=q(6); --扫描时钟
-- clkb<=q(18);
-- end if;
--end process;
--*****************************************************************
process (clk) is --分频
begin
if clk'event and clk='1' then --时钟频率5MHz
q<=q+'1';
end if;
clkp<=q(12); --610.35Hz
clkb<=q(13);
clkscan<=q(4);
end process;
process (clkp)is
begin
if clkp'event and clkp='1' then
if p=304 then
p<="000000000";
clks<=not clks; --1Hz
else
p<=p+'1';
end if;
end if;
end process;
--****************************时钟*********************************
process(clks)is
begin
if clks'event and clks='1' then
if ctrl='0' then
if Q0 = "1001" then --秒
Q0<="0000";
if Q1 = "0101" then --分
Q1<="0000";
if Q2 = "1001" then
Q2<="0000";
if Q3 = "0101" then
Q3<="0000";
if Q5="0010" and Q4="0011" then --时
Q5<="0000";Q4<="0000";
else
if Q4="1001" then
Q4<="0000";Q5<=Q5+'1';
else
Q4<=Q4+'1';
end if;
end if;
else
Q3<=Q3+1;
end if;
else
Q2<=Q2+'1';
end if;
else
Q1<=Q1+1;
end if;
else
Q0<=Q0+'1';
end if;
elsif ctrl='1' then
if choose='0' then
if Q2= "1001" then
Q2<="0000";
if Q3="0101" then
Q3<="0000";
else
Q3<=q3+'1';
end if;
else
Q2<=Q2+'1';
end if;
elsif choose='1' then
if Q5="0010" and Q4="0011" then --时
Q5<="0000";Q4<="0000";
else
if Q4="1001" then
Q4<="0000";
Q5<=Q5+'1';
else
Q4<=Q4+'1';
end if;
end if;
end if;
end if;
end if;
end process;
alert<='1' when Q3="0000" and Q2="0000" and Q1="0000" and Q0="0000"; --整点报时
--***************************扫描显示*******************************
process(clkb)is
begin
if clkb'event and clkb='1' then
b<=not b; --显示信号
end if;
end process;
process (clkscan) is --扫描
begin
if reset = '1' then --清屏
yout<=x"f4";
elsif clkscan'event and clkscan='1' then
if busy = '0' then
n<=n+'1';
if b='0' then
case n is --送入动态字符
when "00"=>yout<=x"f1";w<='0';
when "01"=>yout<=x;
when "10"=>yout<=y;w<='1';
when "11"=>yout<=a;
when others=>null;
end case;
else
case n is --送入静态字符
when "00"=>yout<=x"f1";w1<='0';
when "01"=>yout<=xx;
when "10"=>yout<=yy;w1<='1';
when "11"=>yout<=as;
when others=>null;
end case;
end if;
req<='1';r<='1';
else
req<='0';r<='0';
end if;
end if;
end process;
process(r) is
begin
if r'event and r='1' then --req上升沿转换状态
p_state<=n_state;
nn<=nn+'1';
end if;
end process;
process (w) is
begin
if w'event and w='1' then
case p_state is
when s0=> x<=x"04";y<=x"10";asout<= Q5; n_state<=s1; --hour
when s1=> x<=x"05";y<=x"10";asout<= Q4; n_state<=s2; --hour
when s2=> x<=x"07";y<=x"10";asout<= Q3; n_state<=s3; --minute
when s3=> x<=x"08";y<=x"10";asout<= Q2; n_state<=s4; --minute
when s4=> x<=x"0a";y<=x"10";asout<= Q1; n_state<=s5; --second
when s5=> x<=x"0b";y<=x"10";asout<= Q0; n_state<=s0; --second
when others =>n_state<=s0;
end case;
case asout is --数据表
when "0000" => a<=x"30";
when "0001" => a<=x"31";
when "0010" => a<=x"32";
when "0011" => a<=x"33";
when "0100" => a<=x"34";
when "0101" => a<=x"35";
when "0110" => a<=x"36";
when "0111" => a<=x"37";
when "1000" => a<=x"38";
when "1001" => a<=x"39";
when others=>null;
end case;
end if;
end process;
process(w1) is
begin
if w1'event and w1='0' then
case nn is
when "000000" => xx<=x"00";yy<=x"04";as<=x"24"; --'$'"
when "000001" => xx<=x"01";yy<=x"04";as<=x"24"; --'$'
when "000010" => xx<=x"03";yy<=x"04";as<=x"42"; --'B'
when "000011" => xx<=x"04";yy<=x"04";as<=x"65"; --'e'
when "000100" => xx<=x"05";yy<=x"04";as<=x"6a"; --'j'
when "000101" => xx<=x"06";yy<=x"04";as<=x"69"; --'i'
when "000110" => xx<=x"07";yy<=x"04";as<=x"6e"; --'n'
when "000111" => xx<=x"08";yy<=x"04";as<=x"67"; --'g'
when "001000" => xx<=x"09";yy<=x"04";as<=x"54"; --'T'
when "001001" => xx<=x"0a";yy<=x"04";as<=x"69"; --'i'
when "001010" => xx<=x"0b";yy<=x"04";as<=x"6d"; --'m'
when "001011" => xx<=x"0c";yy<=x"04";as<=x"65"; --'e'
when "001100" => xx<=x"0e";yy<=x"04";as<=x"24"; --'$'
when "001101" => xx<=x"0f";yy<=x"04";as<=x"24"; --'$'
when "001110" => xx<=x"00";yy<=x"10";as<=x"2a"; --'*'
when "001111" => xx<=x"0f";yy<=x"10";as<=x"2a";
when "010000" => xx<=x"00";yy<=x"1c";as<=x"2a";
when "010001" => xx<=x"01";yy<=x"1c";as<=x"2a";
when "010010" => xx<=x"02";yy<=x"1c";as<=x"2a";
when "010011" => xx<=x"03";yy<=x"1c";as<=x"2a";
when "010100" => xx<=x"04";yy<=x"1c";as<=x"2a";
when "010101" => xx<=x"05";yy<=x"1c";as<=x"2a";
when "010110" => xx<=x"06";yy<=x"1c";as<=x"2a";
when "010111" => xx<=x"07";yy<=x"1c";as<=x"2a";
when "011000" => xx<=x"08";yy<=x"1c";as<=x"2a";
when "011001" => xx<=x"09";yy<=x"1c";as<=x"2a";
when "011010" => xx<=x"0a";yy<=x"1c";as<=x"2a";
when "011011" => xx<=x"0b";yy<=x"1c";as<=x"2a";
when "011100" => xx<=x"0c";yy<=x"1c";as<=x"2a";
when "011101" => xx<=x"0d";yy<=x"1c";as<=x"2a";
when "011110" => xx<=x"0e";yy<=x"1c";as<=x"2a";
when "011111" => xx<=x"0f";yy<=x"1c";as<=x"2a";--'*'
when "100000" => xx<=x"06";yy<=x"10";as<=x"3a";--":"
when "100001" => xx<=x"09";yy<=x"10";as<=x"3a";--":"
when others => null;
end case;
end if;
end process;
end a;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -