LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY Clock IS
PORT(
down,up,clk_28M:IN STD_LOGIC;
stop1,pun:BUFFER STD_LOGIC;
sec0,sec1:BUFFER STD_LOGIC_VECTOR(7 DOWNTO 0);
min0,min1:BUFFER STD_LOGIC_VECTOR(7 DOWNTO 0);
hour0,hour1:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
day0,day1:BUFFER STD_LOGIC_VECTOR(7 DOWNTO 0);
mon0,mon1:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
year0,year1:OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END ENTITY Clock;
ARCHITECTURE bhv OF Clock IS
SIGNAL clk,clk1,clk_60s_m,clk_60m_h,clk_24h_d,clk_day,clk_mon,clk_year,t:STD_LOGIC;
SIGNAL adj_bit: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL v60s,v60s1,v60m,v60m1:STD_LOGIC_VECTOR(5 DOWNTO 0);
SIGNAL v24h,v24h1:STD_LOGIC_VECTOR(5 DOWNTO 0);
SIGNAL vday,vday1,vmon,vmon1,vyear,vyear1:STD_LOGIC_VECTOR(5 DOWNTO 0):="000001";
SIGNAL a1s,a2s,a3s,a4s,a5s,a6s,punt:STD_LOGIC_VECTOR(2 DOWNTO 0);
SIGNAL stop,dis_MonAndYear,sec_rst,min_rst,hour_rst,day_rst,mon_rst,year_rst:STD_LOGIC;
BEGIN
DIS_Mon_YEAR:
PROCESS(up,down) BEGIN --need the "down" and "up"is '1' in default
IF down='0' AND stop='0'THEN
dis_MonAndYear<='1'; ELSE
dis_MonAndYear<='0';
END IF;
END PROCESS;
Punctually:
process(v60m,punt)
variable b:integer range 4 downto 0;
begin
if v60m="000000" THEN b:=1;END IF;
IF b=1 THEN pun<='0';END IF;
IF punt=2 THEN pun<='1';b:=0;t<='1'; end if;
IF punt=0 THEN t<='0';END IF;
end process;
ADJUST1: PROCESS(up) BEGIN
IF up' EVENT AND up='0' THEN
adj_bit<=adj_bit+1;stop<='1';stop1<='1';
IF adj_bit = 6 THEN
adj_bit<="0000";stop<='0';stop1<='0';
END IF;
END IF;
END PROCESS;
ADJUST2:PROCESS(down) BEGIN
IF down' EVENT AND down='0' THEN
CASE adj_bit IS
WHEN "0001"=>v60s1<="000001";
WHEN "0010"=>v60m1<="000001";
WHEN "0011"=>v24h1<="000001";
WHEN "0100"=>vday1<="000011";
WHEN "0101"=>vmon1<="000010";
WHEN "0110"=>vyear1<="000010";
WHEN OTHERS=>NULL;
END CASE;
END IF;
IF v60s1="000001" AND sec_rst='1' THEN v60s1<="000000"; END IF;
IF v60m1="000001" AND min_rst='1' THEN v60m1<="000000"; END IF;
IF v24h1="000001" AND hour_rst='1' THEN v24h1<="000000"; END IF;
IF vday1="000011" AND day_rst='1' THEN vday1<="000001"; END IF;
IF vmon1="000010" AND mon_rst='1' THEN vmon1<="000001"; END IF;
IF vyear1="000010" AND year_rst='1' THEN vyear1<="000001";END IF;--need the "down" is '1' in default
END PROCESS;
ASI_DIS:
PROCESS(clk1) BEGIN
IF clk' EVENT AND clk='1' THEN
IF adj_bit = 1 THEN a1s <=a1s+1 ;ELSE a1s<="000";END IF ;
IF adj_bit = 2 THEN a2s <=a2s+1 ;ELSE a2s<="000";END IF ;
IF adj_bit = 3 THEN a3s <=a3s+1 ;ELSE a3s<="000";END IF ;
IF adj_bit = 4 THEN a4s <=a4s+1 ;ELSE a4s<="000";END IF ;
IF adj_bit = 5 THEN a5s <=a5s+1 ;ELSE a5s<="000";END IF ;
IF adj_bit = 6 THEN a6s <=a6s+1 ;ELSE a6s<="000";END IF ;
if pun='0' then punt<=punt+1; end if;
IF t='1' THEN punt<="000"; END IF;
END IF;
END PROCESS;
CLK1_1: PROCESS(clk_28M)
VARIABLE v28,v14:INTEGER range 2799999 DOWNTO 0; --++++++++
BEGIN
IF clk_28M' EVENT AND clk_28M='1' --++++++++
THEN
IF v28=2799999 THEN v28:=0;clk<='1'; --++++++++
ELSE v28:=v28+1;clk<='0';
END IF;
IF v14=1399999 THEN v14:=0;clk1<='1'; --++++++++
ELSE v14:=v14+1;clk1<='0';
END IF;
END IF;
END PROCESS;
SEC: PROCESS(clk,v60s1,v60m1)
BEGIN
IF clk' EVENT AND clk='1'
THEN
IF stop='0'OR v60s1="000001" THEN
sec_rst<='1';
if v60s=59 THEN v60s<="000000";clk_60s_m<='1';--59
ELSE v60s<=v60s+1;clk_60s_m<='0';-------------__--1
END IF;
END IF;
IF v60s1="000000" THEN sec_rst<='0';END IF;
END IF;
IF stop='1' THEN clk_60s_m<=clk;END IF;
END PROCESS;
DIS_SEC:PROCESS(v60s,a1s,vmon,dis_MonAndYear)
VARIABLE v,v1:STD_LOGIC_VECTOR(5 DOWNTO 0);
BEGIN
IF dis_MonAndYear='0' THEN
IF a1s=2 OR adj_bit=0 OR adj_bit=2 OR adj_bit=3 OR adj_bit=4THEN -----==========
IF v60s<10
then sec1<="11000000";v:=v60s;END IF;
IF v60s>9 AND v60s<20
then sec1<="11111001";v:=v60s-10;END IF;
IF v60s>19 AND v60s<30
then sec1<="10100100";v:=v60s-20;END IF;
IF v60s>29 AND v60s<40
then sec1<="10110000";v:=v60s-30;END IF;
IF v60s>39 AND v60s<50
then sec1<="10011001";v:=v60s-40;END IF;
IF v60s>49 AND v60s<60
then sec1<="10010010";v:=v60s-50;END IF;
CASE v is
WHEN"000000"=>sec0<="11000000";
WHEN"000001"=>sec0<="11111001";
WHEN"000010"=>sec0<="10100100";
WHEN"000011"=>sec0<="10110000";
WHEN"000100"=>sec0<="10011001";
WHEN"000101"=>sec0<="10010010";
WHEN"000110"=>sec0<="10000010";
WHEN"000111"=>sec0<="11111000";
WHEN"001000"=>sec0<="10000000";
WHEN"001001"=>sec0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 1 THEN sec1<="11111111";sec0<="11111111";END IF;
END IF;
END IF;
IF a5s=2 OR dis_MonAndYear='1'THEN
sec0<="11111111";sec1<="11111111";
IF vmon<10
THEN sec1<="11000000";v1:=vmon;END IF;
IF vmon<20 AND vmon>9
THEN sec1<="11111001";v1:=vmon-10; END IF;
IF vmon<30 AND vmon>19
THEN sec1<="10100100";v1:=vmon-20;END IF;
IF vmon<32 AND vmon>29
THEN sec1<="10100100";v1:=vmon-30;END IF;
CASE v1 is
WHEN"000000"=>sec0<="11000000";
WHEN"000001"=>sec0<="11111001";
WHEN"000010"=>sec0<="10100100";
WHEN"000011"=>sec0<="10110000";
WHEN"000100"=>sec0<="10011001";
WHEN"000101"=>sec0<="10010010";
WHEN"000110"=>sec0<="10000010";
WHEN"000111"=>sec0<="11111000";
WHEN"001000"=>sec0<="10000000";
WHEN"001001"=>sec0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 5 THEN sec0<="11111111";sec1<="11111111";END IF;
END IF;
END PROCESS;
MIN: PROCESS(clk_60s_m,v60m1)
BEGIN
IF clk_60s_m' EVENT AND clk_60s_m='1'THEN
IF stop='0'OR v60m1="000001" THEN
min_rst<='1';
IF v60m=59 THEN v60m<="000000";clk_60m_h<='1';--59
ELSE v60m<=v60m+1;clk_60m_h<='0';
END IF;
END IF;
IF v60m1="000000" THEN min_rst<='0';END IF;
END IF;
IF stop='1' THEN clk_60m_h<=clk;END IF;
END PROCESS;
DIS_MIN:PROCESS(v60m,vyear)
VARIABLE v,v1:STD_LOGIC_VECTOR(5 DOWNTO 0);
BEGIN
IF dis_MonAndYear='0' THEN
IF a2s=2 OR adj_bit=0 OR adj_bit=1 OR adj_bit=3 OR adj_bit=4 THEN
if v60m<10
then min1<="11000000";v:=v60m;END IF;
IF v60m>9 AND v60m<20
then min1<="11111001";v:=v60m-10;END IF;
IF v60m>19 AND v60m<30
then min1<="10100100";v:=v60m-20;END IF;
IF v60m>29 AND v60m<40
then min1<="10110000";v:=v60m-30;END IF;
IF v60m>39 AND v60m<50
then min1<="10011001";v:=v60m-40;END IF;
IF v60m>49 AND v60m<60
then min1<="10010010";v:=v60m-50;END IF;
CASE v is
WHEN"000000"=>min0<="11000000";
WHEN"000001"=>min0<="11111001";
WHEN"000010"=>min0<="10100100";
WHEN"000011"=>min0<="10110000";
WHEN"000100"=>min0<="10011001";
WHEN"000101"=>min0<="10010010";
WHEN"000110"=>min0<="10000010";
WHEN"000111"=>min0<="11111000";
WHEN"001000"=>min0<="10000000";
WHEN"001001"=>min0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 2 THEN min1<="11111111";min0<="11111111";END IF;
END IF;
END IF;
IF a6s=2 OR dis_MonAndYear='1'THEN
if vyear<10
then min1<="11000000";v1:=vyear;END IF;
IF vyear>9 AND vyear<20
then min1<="11111001";v1:=vyear-10;END IF;
IF vyear>19 AND vyear<30
then min1<="10100100";v1:=vyear-20;END IF;
IF vyear>29 AND vyear<40
then min1<="10110000";v1:=vyear-30;END IF;
IF vyear>39 AND vyear<50
then min1<="10011001";v1:=vyear-40;END IF;
CASE v1 is
WHEN"000000"=>min0<="11000000";
WHEN"000001"=>min0<="11111001";
WHEN"000010"=>min0<="10100100";
WHEN"000011"=>min0<="10110000";
WHEN"000100"=>min0<="10011001";
WHEN"000101"=>min0<="10010010";
WHEN"000110"=>min0<="10000010";
WHEN"000111"=>min0<="11111000";
WHEN"001000"=>min0<="10000000";
WHEN"001001"=>min0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 6 THEN min0<="11111111";min1<="11111111";END IF;
END IF;
END PROCESS;
HOUR: PROCESS(clk_60m_h)
BEGIN
IF clk_60m_h'EVENT AND clk_60m_h='1'THEN
IF stop='0'OR v24h1="000001" THEN
hour_rst<='1';
IF v24h=23 THEN v24h<="000000";clk_24h_d<='1';--23
ELSE v24h<=v24h+1;clk_24h_d<='0';
END IF;
END IF;
IF v24h1="000000" THEN hour_rst<='0';END IF;
END IF;
IF stop='1' THEN clk_24h_d<=clk;END IF;
END PROCESS;
DIS_HOUR:
PROCESS(v24h)
VARIABLE v:STD_LOGIC_VECTOR(5 DOWNTO 0);BEGIN
IF dis_MonAndYear='0' THEN
IF a3s=2 OR adj_bit=0 OR adj_bit=2 OR adj_bit=1 OR adj_bit=4 THEN
IF v24h<10
THEN hour1<="11000000";v:=v24h;END IF;
IF v24h<20 AND v24h>9
THEN hour1<="11111001";v:=v24h-10; END IF;
IF v24h<24 AND v24h>19
THEN hour1<="10100100";v:=v24h-20;END IF;
CASE v is
WHEN"000000"=>hour0<="11000000";
WHEN"000001"=>hour0<="11111001";
WHEN"000010"=>hour0<="10100100";
WHEN"000011"=>hour0<="10110000";
WHEN"000100"=>hour0<="10011001";
WHEN"000101"=>hour0<="10010010";
WHEN"000110"=>hour0<="10000010";
WHEN"000111"=>hour0<="11111000";
WHEN"001000"=>hour0<="10000000";
WHEN"001001"=>hour0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 3 THEN hour1<="11111111";hour0<="11111111";END IF;
END IF;
END IF;
IF dis_MonAndYear='1' THEN hour1<="11111111";hour0<="11111111";END IF;
END PROCESS;
DAY: PROCESS(clk_24h_d,vmon)
BEGIN
IF clk_24h_d'EVENT AND clk_24h_d='1' THEN
IF vday1="000001" THEN day_rst<='0';END IF;
IF stop='0'OR vday1="000011" THEN
day_rst<='1'; --t0
IF vmon=1 OR vmon=3 OR vmon=5 OR vmon=7 OR vmon=8 OR vmon=10 OR vmon=12 THEN
IF vday=31 THEN vday<="000001";clk_day<='1';
ELSE vday<=vday+1;clk_day<='0';
END IF;
END IF;
IF vmon=4 OR vmon=6 OR vmon=9 OR vmon=11 THEN
IF vday=30 THEN vday<="000001";clk_day<='1';
ELSE vday<=vday+1;clk_day<='0';
END IF;
END IF;
IF vmon=2 THEN
IF ((vyear AND "000011")="000000")THEN
IF vday=28 THEN vday<="000001";clk_day<='1';
ELSE vday<=vday+1;clk_day<='0';
END IF;
else
IF vday=29 THEN vday<="000001";clk_day<='1';
ELSE vday<=vday+1;clk_day<='0';
END IF;
END IF;
END IF;
END IF;
END IF;
IF stop='1' THEN clk_day<=clk;END IF;
END PROCESS;
DIS_DAY:
PROCESS(vday)
VARIABLE v:STD_LOGIC_VECTOR(5 DOWNTO 0);BEGIN
IF dis_MonAndYear='0' THEN
IF a4s=2 OR adj_bit=0 OR adj_bit=2 OR adj_bit=3 OR adj_bit=1 THEN
IF vday<10
THEN day1<="11000000";v:=vday;END IF;
IF vday<20 AND vday>9
THEN day1<="11111001";v:=vday-10; END IF;
IF vday<30 AND vday>19
THEN day1<="10100100";v:=vday-20;END IF;
IF vday<32 AND vday>29
THEN day1<="10110000";v:=vday-30;END IF;
CASE v is
WHEN"000000"=>day0<="11000000";
WHEN"000001"=>day0<="11111001";
WHEN"000010"=>day0<="10100100";
WHEN"000011"=>day0<="10110000";
WHEN"000100"=>day0<="10011001";
WHEN"000101"=>day0<="10010010";
WHEN"000110"=>day0<="10000010";
WHEN"000111"=>day0<="11111000";
WHEN"001000"=>day0<="10000000";
WHEN"001001"=>day0<="10010000";
WHEN OTHERS=>NULL;
END CASE;
ELSE IF adj_bit = 4 THEN day0<="11111111";day1<="11111111";END IF;
END IF;
END IF;
IF dis_MonAndYear='1'THEN day0<="11111111";day1<="11111111";END IF;
END PROCESS;
MON: PROCESS(clk_day)
BEGIN
IF clk_day'EVENT AND clk_day='1'THEN
IF stop='0'OR vmon1="000010" THEN
mon_rst<='1';
IF vmon=12 THEN vmon<="000001";clk_mon<='1';
ELSE vmon<=vmon+1;clk_mon<='0';
END IF;
END IF;
IF vmon1="000001" THEN mon_rst<='0';END IF;
END IF; --======test2
IF stop='1' THEN clk_mon<=clk;END IF;
END PROCESS;
YEAR: PROCESS(clk_mon)
BEGIN
IF clk_mon'EVENT AND clk_mon='1'THEN
IF stop='0'OR vyear1="000010" THEN
year_rst<='1';
IF vyear=50 THEN vyear<="000001";--clk_year<='1';
ELSE vyear<=vyear+1;--clk_year<='0';
END IF;
END IF;
IF vyear1="000001" THEN year_rst<='0';END IF;
END IF;
END PROCESS;--黄冈师范
END ARCHITECTURE bhv;
用的是学校的DE-2,显示年月日,时分秒,两个按键,一个是切换位 一个是调时间 按6下就可以回到正常的时间显示,没到一个整点就报时:lol刚刚写出来