*數字電子鐘程序
數碼管的掃描顯示: LIBRARY IEEE; USE *_LOGIC_*; -字模輸出模塊 USE *_LOGIC_*; ENTITY SEL IS PORT(CLK:IN STD_LOGIC; Q:OUT STD_LOGIC_VECTOR(2 DOWNTO 0)); --輸入選通信號 END SEL; ARCHITECTURE SELA OF SEL IS BEGIN PROCESS(CLK) VARIABLE CNT:STD_LOGIC_VECTOR(2 DOWNTO 0); BEGIN IF CLK'EVENT AND CLK='1' THEN CNT:=CNT+1; END IF; Q<=CNT; END PROCESS; END SELA; G:整點報時功能: library ieee; --整點報時模塊 use *_logic_*; entity sst is port(h1,h0,m1,m0,s1,s0:in std_logic_vector(3 downto 0); q1,q0:in std_logic; -輸入分,秒信號和時鐘信號 q: out std_logic); --輸出兩個不同頻率的音頻信號 end sst; architecture sss_arc of sst is signal q3,q4:std_logic; begin process(m1,m0,s1,s0) begin if h1="0000" and h0<"0111" then q3<='0'; q4<='0'; elsif m1="0101"and m0="1001"and s1="0101" then if s0="0000"or s0="0010"or s0="0100" or s0="0110" or s0="1000" then q3<='1' ; else --當計時到達59'50" 52" 54" 56" 58"鳴叫,鳴叫頻率為500HZ, q3<='0'; end if; end if; if h1="0000" and h0<"0111" then q3<='0'; q4<='0'; elsif m1="0000" and m0="0000"and s1="0000" and s0="0000" then q4<='1'; 當整點時為最后一聲整點報時,頻率為1k HZ, else q4<='0'; end if; end process; q<=(q3 and q0)or(q4 and q1); end sss_arc; G:鬧鐘功能模塊: LIBRARY IEEE; USE *_LOGIC_*; ENTITY NAL IS PORT(M1,M0,H1,H0:IN STD_LOGIC_VECTOR(3 DOWNTO 0); en: in STD_LOGIC; Q:OUT STD_LOGIC); END NAL; ARCHITECTURE NAO OF NAL IS BEGIN PROCESS(M1,M0,H1,H0,EN) BEGIN IF EN='0' THEN IF H0="1000"AND H1="0000" AND M1="0000" AND M0="0000" THEN Q<='1'; ELSE Q<='0'; END IF; ELSE Q<='0'; end if; END PROCESS; END NAO;。
2.求高手幫忙編一段EDA程序,數字鐘的
//以下代碼只包含分和秒,如果需要小時,可自行添加
module clock(clk,dig_r,seg_r);
input clk;
output [7:0]dig_r;
output [7:0]seg_r;
reg sec;
reg [7:0]dig_r;
reg [7:0]seg_r;
reg [24:0]count;
reg [15:0]hour;
reg [3:0]disp_dat;
always @(posedge clk)
begin
count=count+1'b1;
if(count==25'd24000000)
begin
count=25'd0;
sec=~sec;
end
end
always @(negedge sec)
begin
hour[3:0]=hour[3:0]+1'b1;
if(hour[3:0]==4'ha)
begin
hour[3:0]=4'h0;
hour[7:4]=hour[7:4]+1'b1;
if(hour[7:4]==4'h6)
begin
hour[7:4]=4'h0;
hour[11:8]=hour[11:8]+1'b1;
if(hour[11:8]==4'ha)
begin
hour[11:8]=4'h0;
hour[15:12]=hour[15:12]+1'b1;
if(hour[15:12]==4'h6)
hour[15:12]=4'h0;
end
end
end
end
always @(posedge clk)
begin
case(count[17:15])
3'd0:disp_dat=hour[3:0];
3'd1:disp_dat=hour[7:4];
3'd2:disp_dat=4'ha;
3'd3:disp_dat=hour[11:8];
3'd4:disp_dat=hour[15:12];
3'd5:disp_dat=4'ha;
3'd6:disp_dat=8'h00;
3'd7:disp_dat=8'h00;
endcase
case(count[17:15])
3'd0:dig_r=8'b11111110;
3'd1:dig_r=8'b11111101;
3'd2:dig_r=8'b11111011;
3'd3:dig_r=8'b11110111;
3'd4:dig_r=8'b11101111;
3'd5:dig_r=8'b11111111;
3'd6:dig_r=8'b11111111;
3'd7:dig_r=8'b11111111;
endcase
end
always @(posedge clk)
begin
case(disp_dat)
4'h0:seg_r=8'hc0;
4'h1:seg_r=8'hf9;
4'h2:seg_r=8'ha4;
4'h3:seg_r=8'hb0;
4'h4:seg_r=8'h99;
4'h5:seg_r=8'h92;
4'h6:seg_r=8'h82;
4'h7:seg_r=8'hf8;
4'h8:seg_r=8'h80;
4'h9:seg_r=8'h90;
4'ha:seg_r=8'hbf;
default:seg_r=8'hff;
endcase
end
endmodule
3.求eda數字鐘設計程序
*ck(元件例化 頂層文件)
Library ieee;
Use *_logic_*;
Use *_logic_*;
Use *_logic_*;
Entity topclock is
Port(clk,clr,en,m1,h1:in std_logic;
alarm:out std_logic;
secs,secg,mins,ming,hours,hourg:buffer std_logic_vector(3 downto 0));
End;
2. 秒模塊程序
library ieee;
use *_logic_*;
use *_logic_*;
entity SECOND is
port(clk,clr:in std_logic;
sec1,sec0:out std_logic_vector(3 downto 0);
co:out std_logic);
end SECOND;
architecture SEC of SECOND is
begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);
begin
if clr='1' then
cnt1:="0000";
cnt0:="0000";
elsif clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then
co="101") then
,
secs=>secs,secg=>secg,clks=>clk, cout1=>a);
u2:min1 port map(clr=>clr,alarm=>alarm,
mins=>mins,ming=>ming,clkm=>b,enmin=>c);
u3:hour1 port map(clr=>clr,
hours=>hours,hourg=>hourg,clkh=>d);
u4:madapt port map(en=>en,m1=>m1,clk=>clk,secin=>a,minset=>b);
u5:hadapt port map(en=>en,h1=>h1,clk=>clk,minin=>c,hourset=>d);
end;
*用VHDL語言寫數字時鐘
second:process (clks) is --秒
begin
if reset='1' then
Q1<="0000";Q0<="0000";
elsif clks'event and clks='1' then
if Q0 = "1001" then
Q0<="0000";
if Q1 = "0101" then
Q1<="0000";
else
Q1<=Q1+1;
end if;
else
Q0<=Q0+'1';
end if;
end if;
end process;
enmin<='1' when Q1="0000" and Q0="0000";
minute:process (enmin) is --分
begin
if reset='1' then
Q3<="0000";Q2<="0000";
elsif setmin='1' then
Q3<=a1;Q2<=a0;
elsif enmin'event and enmin='1' 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;
end if;
end process;
enhour<='1' when Q3="0000" and Q2="0000";
alert<='1' when Q3="0000" and Q2="0000" and Q1="0000" and Q0="0000"; --整點報時
hour:process (enhour) is --時
begin
if reset='1' then
Q5<="0000";Q4<="0000";
elsif sethour='1' then
Q5<=a1;Q4<=a0;
elsif enhour'event and enhour='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 process;
5.求 EDA 的 數字時鐘 程序
輸入1Hz的時鐘作為秒信號,秒計數滿60后向分計數進1,分計數滿60后向時計數進1。當計數到24:60:60自動回到00:00:00;
library ieee;
use *_logic_*;
entity clock is
port(clk:in std_logic;--輸入1Hz的時鐘作為秒信號
clr:in std_logic;--異步清零信號
s:out integer range 0 to 60;--秒
min:out integer range 0 to 60;--分
h:out integer range 0 to 24--時
);
end clock;
architecture clock of clock is
begin
process(clk,clr)
variable count1 :integer range 0 to 60;--秒計數
variable count2 :integer range 0 to 60;--分計數
variable count3 :integer range 0 to 24;--時計數
begin
s
*設計數字時鐘
2. 微秒模塊采用VHDL語言輸入方式,以時鐘clk,清零信號clr以及暫停信號STOP為進程敏感變量,程序如下:library ieee;use *_logic_*;use *_logic_*;entity MINSECONDb isport(clk,clrm,stop:in std_logic;----時鐘/清零信號 secm1,secm0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------輸出/進位信號end MINSECONDb;architecture SEC of MINSECONDb issignal clk1,DOUT2:std_logic;beginprocess(clk,clrm)variable cnt1,cnt0:std_logic_vector(3 downto 0);---計數 VARIABLE COUNT2 :INTEGER RANGE 0 TO 10 ;beginIF CLK'EVENT AND CLK='1'THEN IF COUNT2>=0 AND COUNT2<10 THEN COUNT2:=COUNT2+1; ELSE COUNT2:=0; DOUT2<= NOT DOUT2; END IF; END IF;if clrm='1' then----當clr為1時,高低位均為0cnt1:="0000";cnt0:="0000";elsif clk'event and clk='1' then if stop='1' then cnt0:=cnt0; cnt1:=cnt1; end if;if cnt1="1001" and cnt0="1000" then----當記數為98(實際是經過59個記時脈沖)co<='1';----進位cnt0:="1001";----低位為9elsif cnt0<"1001" then----小于9時cnt0:=cnt0+1;----計數--elsif cnt0="1001" then--clk1<=not clk1;elsecnt0:="0000";if cnt1<"1001" then----高位小于9時cnt1:=cnt1+1;elsecnt1:="0000";co<='0';end if;end if;end if;secm1<=cnt1;secm0<=cnt0;end process;end SEC;3. 秒模塊程序清單library ieee;use *_logic_*;use *_logic_*;entity SECOND isport(clk,clr:in std_logic;----時鐘/清零信號 sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------輸出/進位信號end SECOND;architecture SEC of SECOND isbeginprocess(clk,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);---計數beginif clr='1' then----當ckr為1時,高低位均為0cnt1:="0000";cnt0:="0000";elsif clk'event and clk='1' thenif cnt1="0101" and cnt0="1000" then----當記數為58(實際是經過59個記時脈沖)co<='1';----進位cnt0:="1001";----低位為9elsif cnt0<"1001" then----小于9時cnt0:=cnt0+1;----計數elsecnt0:="0000";if cnt1<"0101" then----高位小于5時cnt1:=cnt1+1;elsecnt1:="0000";co<='0';end if;end if;end if;sec1<=cnt1;sec0<=cnt0;end process;end SEC;4. 分模塊程序清單 library ieee;use *_logic_*;use *_logic_*;entity MINUTE isport(clk,en:in std_logic; min1,min0:out std_logic_vector(3 downto 0); co:out std_logic);end MINUTE;architecture MIN of MINUTE isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clk'event and clk='1' thenif en='1' thenif cnt1="0101" and cnt0="1000" thenco<='1';cnt0:="1001";elsif cnt0<"1001" thencnt0:=cnt0+1;elsecnt0:="0000";if cnt1<"0101" thencnt1:=cnt1+1;elsecnt1:="0000";co<='0';end if;end if;end if;end if;min1<=cnt1;min0<=cnt0;end process;end MIN;5. 時模塊程序清單library ieee;use *_logic_*;use *_logic_*;entity HOUR isport(clk,en:in std_logic;----輸入時鐘/高電平有效的使能信號 h1,h0:out std_logic_vector(3 downto 0));----時高位/低位end HOUR;architecture hour_arc of HOUR isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);----記數beginif clk'event and clk='1' then---上升沿觸發if en='1' then---同時“使能”為1if cnt1="0010" and cnt0="0011" thencnt1:="0000";----高位/低位同時為0時cnt0:="0000";elsif cnt0<"1001" then----低位小于9時,低位記數累加cnt0:=cnt0+1;elsecnt0:="0000";cnt1:=cnt1+1;-----高位記數累加end if;end if;end if;h1<=cnt1;h0<=cnt0;end process;end hour_arc; 6. 動態掃描模塊 library ieee;use *_logic_*;use *_logic_*;use *_logic_*;entity SELTIME is port( clk:in std_logic;------掃描時鐘 secm1,secm0,sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-----分別為秒個位/時位;分個位/ daout:out std_logic_vector(3 downto 0);----------------輸出 sel:out std_logic_vector(2 downto 0));-----位選信號end SELTIME;architecture fun of SELTIME is signal count:std_logic_vector(2 downto 0);----計數信號begin sel<=count; process(clk) begin if(clk'event and clk='1') then if(count>="111") then count<="000"; else count<=count+1; end if; end if; case count is when"111"=>daout<= secm0;----秒個位 when"110"=>daout<= secm1;----秒十位 when"101"=>daout<= sec0;----分個位 when"100"=>daout<= sec1;----分十位 when"011"=>daout<=min0; ----時個位 when"010"=>daout<=min1;----時十位 when"001"=>daout<=h0; when others =>daout<=h1; end case; end process;end fun;7. 報時模塊library ieee;use *_logic_*;entity ALERT isport(m1,m0,s1,s0:in std_logic_vector(3 downto 0);------輸入秒、分。
7.求 EDA 的 數字時鐘 程序
輸入1Hz的時鐘作為秒信號,秒計數滿60后向分計數進1,分計數滿60后向時計數進1。
當計數到24:60:60自動回到00:00:00;library ieee;use *_logic_*;entity clock isport(clk:in std_logic;--輸入1Hz的時鐘作為秒信號 clr:in std_logic;--異步清零信號 s:out integer range 0 to 60;--秒 min:out integer range 0 to 60;--分 h:out integer range 0 to 24--時 );end clock;architecture clock of clock is beginprocess(clk,clr)variable count1 :integer range 0 to 60;--秒計數variable count2 :integer range 0 to 60;--分計數variable count3 :integer range 0 to 24;--時計數begins<=count1;min<=count2;h<=count3;if(clr='1')thencount1:=0;count2:=0;count3:=0;elsif(clk'event and clk='1')thencount1:=count1+1;if (count1=60)then count1:=0; count2:=count2+1; if(count2=60)then count2:=0; count3:=count3+1; if(count3=24)then count3:=0; end if; end if;end if;end if;end process;end clock;。
*用VHDL語言寫數字時鐘
second:process (clks) is --秒 begin if reset='1' then Q1 elsif clks'event and clks='1' then if Q0 = "1001" then Q0 if Q1 = "0101" then Q1 else Q1 end if; else Q0 end if; end if; end process; enmin minute:process (enmin) is --分 begin if reset='1' then Q3 elsif setmin='1' then Q3 elsif enmin'event and enmin='1' then if Q2 = "1001" then Q2 if Q3 = "0101" then Q3 else Q3 end if; else Q2 end if; end if; end process; enhour alert hour:process (enhour) is --時 begin if reset='1' then Q5 elsif sethour='1' then Q5 elsif enhour'event and enhour='1' then if Q5="0010" and Q4="0011" then Q5 else if Q4="1001" then Q4 else Q4 end if; end if; end if; end process;。
9.
我不是學姐,答案我就不幫你做了,給你一些提示,希望你能獨立完成.1:先選對計數器,根據需要選擇4位,8位,32位(如果沒有32位的計數器可以用2個16位的計數器級聯起來,第一級的計數器的高位輸出驅動第二級的計數器始終)2:10進制,12進制,60進制的計數器怎么做?你需要一個比較器,比較器輸入端比較counter的值和一個preset value,如果兩個值相等,則輸出一,否則輸出0,用這個比較信號來控制counter的復位信號,注意有些復位是低電平有效3:有了上面的這些計數器以后怎么做時鐘?用級聯的方式把上面這些計數器串聯起來,也就是說用function generator 產生一個10Hz的頻率分秒的比較器輸出當作秒的時鐘輸入(enable也可以),同樣的道理,秒的計數器的比較器出入做分的計數器的十種輸入.。
轉載請注明出處華閱文章網 » eda數字鐘代碼簡短