完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 yuexiangrenshen 于 2015-4-1 14:37 编辑
打开板子后,数码管始终显示0. 下面是代码,请耐心帮忙看一下. 只有红绿黄灯,东西 南北方向的绿灯均显示60秒 Library IEEE ; use IEEE.std_logic_1164.all ; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENtiTY CONTROLL IS PORT(CLK:IN STD_LOGIC; EN:IN STD_LOGIC; CON:IN STD_LOGIC; COUNTNUM:IN INTEGER RANGE 0 TO 120; A:OUT INTEGER RANGE 0 TO 60; B:OUT INTEGER RANGE 0 TO 60; R1,G1,Y1:OUT STD_LOGIC; R2,G2,Y2:OUT STD_LOGIC); END CONTROLL; ARCHITECTURE behav OF CONTROLL IS SIGNAL m:integer range 0 to 3; begin process(clk,en,con,countnum) variable deng:STD_LOGIC_vector(5 downto 0); begin if (clk'event and clk='1')then if en='1'then if countnum>60 then a<=120-countnum; b<=120-countnum; if countnum>110 then deng:="010100"; else deng:="010100"; a<=110-countnum; end if; end if; else if countnum>0 then b<=60-countnum; a<=60-countnum; if countnum>50 then deng:="001010"; else deng:="100010"; a<=50-countnum; end if; end if; if en='0'then a<=0; b<=0; if con='1'then if m=3 then m<=0; else m<=m+1; end if; if m=0 then deng:="010100"; elsif m=1 then deng:="010100"; elsif m=2 then deng:="001010"; elsif m=3 then deng:="100010"; end if; end if; end if; r1<=deng(5); g1<=deng(4); y1<=deng(3); r2<=deng(2); g2<=deng(1); y2<=deng(0); end if; end if; end process; end behav; Library IEEE ; use IEEE.std_logic_1164.all ; USE IEEE.STD_LOGIC_UNSIGNED.ALL; entity counter is port (clk:IN STD_LOGIC; en:IN STD_LOGIC; reset:IN STD_LOGIC; countnum:buffer integer range 0 to 119); end counter; ARCHITECTURE behav OF counter is begin process(reset,clk) begin if reset='1' then countnum<=0; elsif CLK'EVENT AND CLK='1' then if en='1' then if countnum<119 then countnum<=0; else countnum<= countnum+1; end if; else countnum<=0; end if; end if; end process; end behav; Library IEEE ; use IEEE.std_logic_1164.all ; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY fd IS PORT( EN,CLK:IN STD_LOGIC; COUT:OUT STD_LOGIC); END fd; ARCHITECTURE behav OF FD IS SIGNAL Q:STD_LOGIC; BEGIN PROCESS(CLK,EN) VARIABLE TEMP:INTEGER RANGE 2499999 DOWNTO 0:=0; BEGIN if EN='1' then IF CLK'EVENT AND CLK='1' THEN IF TEMP=2499999 THEN TEMP:=0;Q<=NOT Q; ELSE TEMP:=TEMP+1; END IF; END IF; ELSE Q<='0';TEMP:=0; END IF; END PROCESS; COUT<=Q; END behav; Library IEEE ; use IEEE.std_logic_1164.all ; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY jishu IS PORT (EN: IN STD_LOGIC; T1,T2: IN INTEGER RANGE 0 TO 60; LED1,LED2,LED3,LED4 :OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); END jishu; ARCHITECTURE behav OF jishu IS SIGNAL L1,L2,L3,L4 : INTEGER RANGE 0 TO 9; BEGIN p2:PROCESS(EN,T1,T2) begin IF EN='1' THEN L1<=T1/10;L2<=T1 REM 10; L3<=T2/10;L4<=T2 REM 10; END IF; END PROCESS; P3:PROCESS(L1) BEGIN CASE L1 IS WHEN 0=>LED1<="0000"; WHEN 1=>LED1<="0001"; WHEN 2=>LED1<="0010"; WHEN 3=>LED1<="0011"; WHEN 4=>LED1<="0100"; WHEN 5=>LED1<="0101"; WHEN 6=>LED1<="0110"; WHEN 7=>LED1<="0111"; WHEN 8=>LED1<="1000"; WHEN 9=>LED1<="1001"; WHEN OTHERS=> LED1<="0000"; END CASE; END PROCESS; P4:PROCESS(L2) BEGIN CASE L2 IS WHEN 0=>LED2<="0000"; WHEN 1=>LED2<="0001"; WHEN 2=>LED2<="0010"; WHEN 3=>LED2<="0011"; WHEN 4=>LED2<="0100"; WHEN 5=>LED2<="0101"; WHEN 6=>LED2<="0110"; WHEN 7=>LED2<="0111"; WHEN 8=>LED2<="1000"; WHEN 9=>LED2<="1001"; WHEN OTHERS=> LED2<="0000"; END CASE; END PROCESS; P5:PROCESS(L3) BEGIN CASE L3 IS WHEN 0=>LED3<="0000"; WHEN 1=>LED3<="0001"; WHEN 2=>LED3<="0010"; WHEN 3=>LED3<="0011"; WHEN 4=>LED3<="0100"; WHEN 5=>LED3<="0101"; WHEN 6=>LED3<="0110"; WHEN 7=>LED3<="0111"; WHEN 8=>LED3<="1000"; WHEN 9=>LED3<="1001"; WHEN OTHERS=> LED3<="0000"; END CASE; END PROCESS; P6:PROCESS(L4) BEGIN CASE L4 IS WHEN 0=>LED4<="0000"; WHEN 1=>LED4<="0001"; WHEN 2=>LED4<="0010"; WHEN 3=>LED4<="0011"; WHEN 4=>LED4<="0100"; WHEN 5=>LED4<="0101"; WHEN 6=>LED4<="0110"; WHEN 7=>LED4<="0111"; WHEN 8=>LED4<="1000"; WHEN 9=>LED4<="1001"; WHEN OTHERS=> LED4<="0000"; END CASE; END PROCESS; END behav; Library IEEE ; use IEEE.std_logic_1164.all ; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY yima IS PORT( EN:IN STD_LOGIC; LED1,LED2,LED3,LED4 :IN STD_LOGIC_VECTOR(3 DOWNTO 0); LED7S:OUT STD_LOGIC_VECTOR(27 DOWNTO 0):=(OTHERS=>'1')); END yima; ARCHITECTURE behav OF yima IS SIGNAL REG1:STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL REG2:STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL REG3:STD_LOGIC_VECTOR(6 DOWNTO 0); SIGNAL REG8:STD_LOGIC_VECTOR(6 DOWNTO 0); BEGIN PROCESS(EN,LED1) BEGIN IF EN='1'THEN CASE LED1 IS WHEN "0000" => REG1<="1000000"; WHEN "0001" => REG1<="1111001"; WHEN "0010" => REG1<="0100100"; WHEN "0011" => REG1<="0110000"; WHEN "0100" => REG1<="0011001"; WHEN "0101" => REG1<="0010010"; WHEN "0110" => REG1<="0000010"; WHEN "0111" => REG1<="1111000"; WHEN "1000" => REG1<="0000000"; WHEN "1001" => REG1<="0010000"; WHEN "1010" => REG1<="0001000"; WHEN "1011" => REG1<="0000011"; WHEN "1100" => REG1<="1000110"; WHEN "1101" => REG1<="0100001"; WHEN "1110" => REG1<="0000110"; WHEN "1111" => REG1<="0001110"; WHEN OTHERS=> NULL; END CASE; ELSE REG1<="1111111"; END IF; END PROCESS; PROCESS(EN,LED2) BEGIN IF EN='1'THEN CASE LED2 IS WHEN "0000" => REG2<="1000000"; WHEN "0001" => REG2<="1111001"; WHEN "0010" => REG2<="0100100"; WHEN "0011" => REG2<="0110000"; WHEN "0100" => REG2<="0011001"; WHEN "0101" => REG2<="0010010"; WHEN "0110" => REG2<="0000010"; WHEN "0111" => REG2<="1111000"; WHEN "1000" => REG2<="0000000"; WHEN "1001" => REG2<="0010000"; WHEN "1010" => REG2<="0001000"; WHEN "1011" => REG2<="0000011"; WHEN "1100" => REG2<="1000110"; WHEN "1101" => REG2<="0100001"; WHEN "1110" => REG2<="0000110"; WHEN "1111" => REG2<="0001110"; WHEN OTHERS=> NULL; END CASE; ELSE REG2<="1111111"; END IF; END PROCESS; PROCESS(EN,LED3) BEGIN IF EN='1'THEN CASE LED3 IS WHEN "0000" => REG3<="1000000"; WHEN "0001" => REG3<="1111001"; WHEN "0010" => REG3<="0100100"; WHEN "0011" => REG3<="0110000"; WHEN "0100" => REG3<="0011001"; WHEN "0101" => REG3<="0010010"; WHEN "0110" => REG3<="0000010"; WHEN "0111" => REG3<="1111000"; WHEN "1000" => REG3<="0000000"; WHEN "1001" => REG3<="0010000"; WHEN "1010" => REG3<="0001000"; WHEN "1011" => REG3<="0000011"; WHEN "1100" => REG3<="1000110"; WHEN "1101" => REG3<="0100001"; WHEN "1110" => REG3<="0000110"; WHEN "1111" => REG3<="0001110"; WHEN OTHERS=> NULL; END CASE; ELSE REG3<="1111111"; END IF; END PROCESS; PROCESS(EN,LED4) BEGIN IF EN='1'THEN CASE LED4 IS WHEN "0000" => REG8<="1000000"; WHEN "0001" => REG8<="1111001"; WHEN "0010" => REG8<="0100100"; WHEN "0011" => REG8<="0110000"; WHEN "0100" => REG8<="0011001"; WHEN "0101" => REG8<="0010010"; WHEN "0110" => REG8<="0000010"; WHEN "0111" => REG8<="1111000"; WHEN "1000" => REG8<="0000000"; WHEN "1001" => REG8<="0010000"; WHEN "1010" => REG8<="0001000"; WHEN "1011" => REG8<="0000011"; WHEN "1100" => REG8<="1000110"; WHEN "1101" => REG8<="0100001"; WHEN "1110" => REG8<="0000110"; WHEN "1111" => REG8<="0001110"; WHEN OTHERS=> NULL; END CASE; ELSE REG8<="1111111"; END IF; END PROCESS; LED7S(27 DOWNTO 21)<=REG1; LED7S(20 DOWNTO 14)<=REG2; LED7S(13 DOWNTO 7)<=REG3; LED7S(6 DOWNTO 0)<=REG8; END behav; |
|
相关推荐
21个回答
|
|
这个文件给你参考哈,我的找不到了,是同学的,稍微和我的有点不同,大体思路是一样的。我的只有代码。
最佳答案
|
|
|
|
有没有高手 帮下小女子啊 谢谢啦!
|
|
|
|
时钟频率是多少?
|
|
|
|
你可以写一个tb测试一下
|
|
|
|
没有用到状态机么,去年我也做过这个实验,是要用到状态机的。。
|
|
|
|
四.程序:
(一)30进制倒数计数器 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity hongdeng is port (en,clk,rst: in std_logic; s_ge:out std_logic_vector(3 downto 0); s_shi:out std_logic_vector(3 downto 0); s_cout :out std_logic); end hongdeng; architecture bhv of hongdeng is signal q1: std_logic_vector(3 downto 0); signal q2: std_logic_vector(3 downto 0); begin process(rst,clk,q1,q2,en) begin if rst='0' then q1<="1001";q2<="0010"; elsif clk'event and clk='1' then if en='1' then if q1>0 then q1<=q1-1; else q1<="1001"; if q2>0 then q2<=q2-1; else q2<="0010"; end if; end if; end if; end if; end process; process(clk,q1,q2) begin if clk'event and clk='1' then if (q2="0000" and q1="0000") then s_cout<='1'; else s_cout<='0'; end if; end if; end process; s_shi<=q2 ; s_ge<=q1; end bhv; (二)26进制倒数计数器 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity lvdeng is port(clk,en,rst : in std_logic; h_ge : out std_logic_vector(3 downto 0); h_shi: out std_logic_vector(3 downto 0); b_cout :out std_logic); end lvdeng; architecture bhv of lvdeng is signal q1 : std_logic_vector(3 downto 0); signal q2: std_logic_vector(3 downto 0); begin process(en,clk,q1,q2) begin if rst='0' then q1<="0101" ; q2<="0010"; elsif clk'event and clk='1' then if en='1' then if q1="0000" and q2="0000" then q1<="0101";q2<="0010"; elsif q1>0 then q1<=q1-1; else q1<="1001"; if q2>0 then q2<=q2-1 ; else q2<="0010"; end if; end if; end if; end if; end process; process(clk,q2,q1) begin if clk'event and clk='1' then if (q2="0000" and q1="0000") then b_cout<='1'; else b_cout<='0'; end if;end if; end process; h_shi<=q2 ; h_ge<=q1; end bhv; (三)5进制倒数计数器 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity huangdeng is port(en,clk,rst :in std_logic; chu: out std_logic_vector(3 downto 0); shi: out std_logic_vector(3 downto 0); c_cout: out std_logic ); end huangdeng; architecture one of huangdeng is signal q,q1: std_logic_vector(3 downto 0); begin process(rst,clk,en,q,q1) begin if rst='0' then q<="0010";q1<="0000"; elsif clk'event and clk='1' then if en='1' then if q>0 then q<=q-1; else q<="0010"; end if; end if; end if; end process; process(clk,q,q1) begin if clk'event and clk='1' then if (q="0000" and q1="0000") then c_cout<='1'; else c_cout<='0'; end if; end if; end process; chu<=q;shi<=q1; end one ; (四)显示选择器 library ieee; use ieee.std_logic_1164.all; entity xuanze is port(in1,in2,in3,in4,in5,in6: in std_logic_vector(7 downto 0); h: in std_logic_vector(1 downto 0); out1,out2,out3,out4: out std_logic_vector(7 downto 0)); end xuanze; architecture one of xuanze is begin process(h) begin case h is when "00"=> out1<=in1;out2<=in2;out3<=in5;out4<=in6; when "01"=> out1<=in1;out2<=in2;out3<=in3;out4<=in4; when "10"=> out1<=in5;out2<=in6;out3<=in1;out4<=in2; when "11"=> out1<=in3;out2<=in4;out3<=in1;out4<=in2; when others=>null; end case; end process; end architecture one; (五)状态机控制器 library ieee; use ieee.std_logic_1164.all; entity jtd is port ( clk,rest : in std_logic; kong : out std_logic_vector(1 downto 0); w1,w2,w3 : in std_logic; c1,c2,c3,r1,r2,y1,y2,g1,g2: out std_logic); end jtd; architecture one of jtd is signal q: std_logic_vector(2 downto 0); signal q1:std_logic_vector(1 downto 0); type st is (s0,s1,s2,s3); signal c_st,n_st: st; begin q<=w1&w2&w3; reg: process(rest,clk) begin if rest='0' then c_st<=s0; elsif clk='1' and clk'event then c_st<=n_st; end if; end process reg; com: process(c_st,q) begin case c_st is when s0=> c1<='1';c2<='0';c3<='1';r1<='1';r2<='0';y1<='0';y2<='0';g1<='0';g2<='1';q1<="00"; if q="100" then n_st<=s1; else n_st<=s0; end if; when s1=> c1<='0';c2<='1';c3<='1';r1<='1';r2<='0';y1<='0';y2<='1';g1<='0';g2<='0';q1<="01"; if q="011" then n_st<=s2; else n_st<=s1; end if; when s2=> c1<='1';c2<='0';c3<='1';r1<='0';r2<='1';y1<='0';y2<='0';g1<='1';g2<='0';q1<="10"; if q="100" then n_st<=s3; else n_st<=s2; end if; when s3=> c1<='0';c2<='1';c3<='1';r1<='0';r2<='1';y1<='1';y2<='0';g1<='0';g2<='0';q1<="11"; if q="011" then n_st<=s0; else n_st<=s3; end if; when others=> n_st<=s0; end case; end process com; kong<=q1; end one; |
|
|
|
四.程序: (一)30进制倒数计数器 library ieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; entity hongdeng is port (en,clk,rst:in std_logic; s_ge:out std_logic_vector(3 downto 0); s_shi:out std_logic_vector(3 downto 0); s_cout :out std_logic); end hongdeng; architecture bhvof hongdeng is signal q1: std_logic_vector(3 downto 0); signal q2: std_logic_vector(3 downto 0); begin process(rst,clk,q1,q2,en) begin if rst='0' then q1<="1001";q2<="0010"; elsif clk'eventand clk='1' then if en='1' then if q1>0 then q1<=q1-1; elseq1<="1001"; if q2>0 then q2<=q2-1; elseq2<="0010"; end if; end if; end if; end if; end process; process(clk,q1,q2) begin if clk'event and clk='1' then if (q2="0000" andq1="0000") then s_cout<='1'; else s_cout<='0'; end if; end if; end process; s_shi<=q2 ; s_ge<=q1; end bhv; (二)26进制倒数计数器 library ieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; entity lvdeng is port(clk,en,rst :in std_logic; h_ge : out std_logic_vector(3 downto 0); h_shi: out std_logic_vector(3 downto 0); b_cout :out std_logic); end lvdeng; architecture bhvof lvdeng is signal q1 :std_logic_vector(3 downto 0); signal q2: std_logic_vector(3 downto 0); begin process(en,clk,q1,q2) begin if rst='0' then q1<="0101" ;q2<="0010"; elsif clk'event and clk='1' then if en='1' then if q1="0000" andq2="0000" then q1<="0101";q2<="0010"; elsif q1>0 then q1<=q1-1; else q1<="1001"; if q2>0 then q2<=q2-1 ; elseq2<="0010"; end if; end if; end if; end if; end process; process(clk,q2,q1) begin if clk'event andclk='1' then if(q2="0000" and q1="0000") then b_cout<='1'; else b_cout<='0'; end if;end if; end process; h_shi<=q2 ; h_ge<=q1; end bhv; (三)5进制倒数计数器 library ieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; entity huangdengis port(en,clk,rst :instd_logic; chu: out std_logic_vector(3 downto 0); shi: out std_logic_vector(3 downto 0); c_cout: out std_logic ); end huangdeng; architecture oneof huangdeng is signal q,q1:std_logic_vector(3 downto 0); begin process(rst,clk,en,q,q1) begin if rst='0' thenq<="0010";q1<="0000"; elsif clk'event and clk='1' then if en='1' then if q>0 thenq<=q-1; elseq<="0010"; end if; end if; end if; end process; process(clk,q,q1) begin if clk'event and clk='1' then if (q="0000" andq1="0000") then c_cout<='1'; else c_cout<='0'; end if; end if; end process; chu<=q;shi<=q1; end one ; (四)显示选择器 library ieee; useieee.std_logic_1164.all; entity xuanze is port(in1,in2,in3,in4,in5,in6:in std_logic_vector(7 downto 0); h: in std_logic_vector(1 downto 0); out1,out2,out3,out4: outstd_logic_vector(7 downto 0)); end xuanze; architecture oneof xuanze is begin process(h) begin case h is when "00"=>out1<=in1;out2<=in2;out3<=in5;out4<=in6; when "01"=>out1<=in1;out2<=in2;out3<=in3;out4<=in4; when "10"=>out1<=in5;out2<=in6;out3<=in1;out4<=in2; when "11"=>out1<=in3;out2<=in4;out3<=in1;out4<=in2; when others=>null; end case; end process; end architecture one; (五)状态机控制器 library ieee; use ieee.std_logic_1164.all; entity jtd is port ( clk,rest : in std_logic; kong : out std_logic_vector(1 downto 0); w1,w2,w3 : in std_logic; c1,c2,c3,r1,r2,y1,y2,g1,g2: out std_logic); end jtd; architecture one of jtd is signal q: std_logic_vector(2 downto 0); signal q1:std_logic_vector(1 downto 0); type st is (s0,s1,s2,s3); signal c_st,n_st: st; begin q<=w1&w2&w3; reg: process(rest,clk) begin ifrest='0' then c_st<=s0; elsif clk='1' and clk'event then c_st<=n_st; endif; endprocess reg; com: process(c_st,q) begin case c_st is when s0=>c1<='1';c2<='0';c3<='1';r1<='1';r2<='0';y1<='0';y2<='0';g1<='0';g2<='1';q1<="00"; ifq="100" then n_st<=s1; else n_st<=s0; end if; when s1=>c1<='0';c2<='1';c3<='1';r1<='1';r2<='0';y1<='0';y2<='1';g1<='0';g2<='0';q1<="01"; ifq="011" then n_st<=s2; else n_st<=s1; end if; when s2=>c1<='1';c2<='0';c3<='1';r1<='0';r2<='1';y1<='0';y2<='0';g1<='1';g2<='0';q1<="10"; ifq="100" then n_st<=s3; else n_st<=s2; end if; when s3=>c1<='0';c2<='1';c3<='1';r1<='0';r2<='1';y1<='1';y2<='0';g1<='0';g2<='0';q1<="11"; ifq="011" then n_st<=s0; else n_st<=s3; end if; when others=> n_st<=s0; end case; end process com; kong<=q1; end one; |
|
|
|
从分频器上上看时钟应该是5M吧
|
|
|
|
|
|
|
|
沉默的小宇宙OK 发表于 2015-3-26 22:19 你好,我不太明白你写的5 16 30进制是什么意思。 你发的是交通灯的程序吗 |
|
|
|
我看了程序,关于c1c2c3那里 我不太明白,进制是不同情况下,灯显示的时间。 能不能麻烦你把,电路图给我发一下,有助于我对程序的理解。谢谢了 |
|
|
|
要把你从晶振上得到的输入时钟(你的是50M的话)要分频得到1Hz频率,给你的30秒,24秒,5秒倒计时计时使用。不然刷新太看,人眼无法观察到变化。 |
|
|
|
比如 我 不理解30进制q1赋值的四位二进制码 是什么意思。 这个程序除了需要我再写一个分频器,还用别的东西吗?能不能給我一個电路图,这样我有助于理解 |
|
|
|
学习了。。。。。。。。。。。。。。。。。。。。
|
|
|
|
|
|
|
|
比如 我 不理解30进制q1赋值的四位二进制码 是什么意思。它的原理是什么,如果我要设置倒计时是60秒,该如何写?有电路图吗,能否看一下电路图,这样便于理解
|
|
|
|
这样十位与个位的计数速度不是一样的吗?
|
|
|
|
谢谢你了,给我提供了很大的帮助,在后续的进程中,如果我遇到了问题,可能还要请教你的,最后再一次谢谢了!
|
|
|
|
你好,我按照你的作了程序,但是JTD的部分 ,有问题,因为时钟的问题,数码管上的计数从s1就开始错了。 能帮我解决以下吗? |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
837 浏览 0 评论
1623 浏览 0 评论
447 浏览 0 评论
618 浏览 0 评论
638 浏览 0 评论
1208 浏览 23 评论
5448 浏览 113 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-1 03:32 , Processed in 1.035499 second(s), Total 109, Slave 90 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号