1、 integer range 0 to 512; variable q1: std_logic; if clk1024 event and clk1024=1 then if count1=512 then q1:=not q1; count1:=0; else count1:=count1+1; end if; clk1=q1;end process; process(clk1024) variable count512: integer range 0 to 1; variable q512: begin if clk1024 if count512=1 then q512:=not q5
2、12; count512: else count512:=count512+1; clk512=q512;end cml; 22 校时电路(jiaoshi)本模块要实现的功能是:正常计时、校时、校分在每个状态下都会产生不同控制信号实现相应的功能。校时管脚图代码:entity jiaoshi is port(rst,rvs,select_rvs,mtime,mclkin,hclkin: hclkout,mclkout: end jiaoshi; architecture cml of jiaoshi is signal h_m:std_logic; begin p1:process(rst,rv
3、s,hclkin,mclkin,h_m,mtime) if rst=0 null; elsif rvs= then hclkout=hclkin; mclkout=mCLKin; elsif h_m=mtime; elsemclkout=mclkin;p2:process(select_rvs) if select_rvsevent and select_rvs= h_m=not h_m;end process ;管脚图仿真图2.3 时计数器(hour)分计数器(mine)秒计数器(second) 时计数器管脚图 时代码: library ieee;entity hour isport(rst
4、,hclk: hour0,hour1:buffer std_logic_vector(3 downto 0 )end hour;architecture cml of hour isprocess(rst,hclk,hour0,hour1) hour0=0000; hour1 elsif hclkevent and hclk= if hour0=0011 and hour1=0010 elsif hour0=1001=hour1+1;=hour0+1; end process ;分计数器管脚图分代码:entity mine isport(rst,mclk: mco:out std_logic;
5、 min0,min1:end mine;architecture cml of mine issignal min0_t,min1_t:std_logic_vector(3 downto 0 );process(rst,mclk,min0,min1) min0 min1 elsif mclkevent and mclk= if min0=0101 and min1= mco= elsif min0= and min0=min1+1;=min0+1; 秒计数器管脚图 秒代码:entity second isport(rst,sclk: sco: sec0,sec1:end second;arch
6、itecture cml of second issignal sec0_t,sec1_t:process(rst,sclk,sec0,sec1) sec0 sec1 elsif sclkevent and sclk= if sec0= and sec1= sco elsif sec0= and sec0=sec1+1;=sec0+1;2.4 校时闪烁电路(flashnjiaoshi)如果正在进行校时,flashjiaoshi将实现使当前正在校时项(小时或分钟)以1Hz的频率闪烁,以便于操知道正在被校正。 校时闪烁电路管脚图entity flashjiaoshi isport(rst,sclk
7、,rvs,select_rvs: hour0in,hour1in,min0in,min1in:in std_logic_vector(3 downto 0 ); hour0out,hour1out,min0out,min1out :out std_logic_vector(3 downto 0 )end flashjiaoshi;architecture cml of flashjiaoshi isprocess(rst,sclk,rvs,hour0in,hour1in,min0in,min1in,h_m) hour0out=hour0in; hour1out=hour1in; min0out
8、=min0in; min1out=min1in; hour1out if sclk= min0out min1out1111 IF sCLK=end process p1;process(select_rvs) h_mend if;end process p2;2.5 整点报时电路 整点报时管脚图entity baoshi is port( clk1024,clk512 : in std_logic; min0,min1 , sec0,sec1 : in std_logic_vector (3 downto 0); speak : out std_logic);end baoshi;archi
9、tecture cml of baoshi isspeakdata=h1;select_sig1000111111 end case; if order= then order else orderseg7 1111111end cml ;2.7数字钟整体设计 (top)本数字钟的设计包括分频器、去抖动电路、校时电路、“时、分、秒”计数器、校时闪烁电路和译码显示电路。以上已经有了各个功能模块的实现方法,现在将各个模块综合在一起,构成一个完整的数字钟。entity top isport(clk1024,key,reset: keyin:in std_logic_vector(1 downto 0
10、 ); select_sigout:out std_logic_vector(5 downto 0 ); seg7out: speak:end top;architecture cml of top is component fenpin is end component fenpin ;component jiaoshi is end component jiaoshi;component hour isend component hour;component minute isend component minute;component second isend component sec
11、ond;component flashjiaoshi isend component flashjiaoshi;component xianshi isend component xianshi;component baoshi isend component baoshi;signal scanCLKSig :signal secCLKSig :signal hCLKSig0,hCLKSig1 :signal mCLKSig0,mCLKSig1 :signal sec1Sig,sec0Sig : std_logic_vector(3 downto 0);signal min1Sig0,min
12、0Sig0 :signal min1Sig1,min0Sig1 :signal hour1Sig0,hour0Sig0 :signal hour1Sig1,hour0Sig1 :beginU1: fenpin PORT MAP(clk1024=clk1024,clk512=scanCLKSig,clk1=secCLKSig);U2: jiaoshi PORT MAP(rst=reset, rvs=key, select_rvs=keyin(0), mtime=keyin(1), hclkin=hCLKSig0,mclkin=mCLKSig0,hclkout=hCLKSig1,mclkout=mCLKSig1);U3:hour PORT MAP(rst=reset, hCLK=hCLKSig1, hour1=hour1Sig0, hour0=hour0Sig0);U4: minute PORT MAP(rst=reset, mclk=mCLKSig1, mco=hCLKSig0, min1=min1Sig0, min0=min0Sig0);U5: second PORT MAP(rst=reset, sCLK
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1