集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: encounter

用VHDL写一个动态显示?想用四个LED动态显示我的数据输入是11位BCD码现在想显示

[复制链接]
HDL 发表于 2010-6-26 11:58:20 | 显示全部楼层
很标准的
ups 发表于 2010-6-26 13:23:45 | 显示全部楼层
好程序  顶
HDL 发表于 2010-6-26 15:19:17 | 显示全部楼层
好是好,你们觉得这程序对楼主有帮助吗?
usd 发表于 2010-6-26 15:58:34 | 显示全部楼层
--------------------------------------------------------------------------------<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_unsigned.all;<br>
use ieee.std_logic_arith.all;<br>
entity shaomiao is<br>
&nbsp; &nbsp;generic(size:integer:=4);<br>
&nbsp; &nbsp;port(d0,d1,d2,d3:in std_logic_vector(3 downto 0);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clk:in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dout: out std_logic_vector(6 downto 0);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cs:&nbsp;&nbsp;inout std_logic_vector(size-1 downto 0));<br>
end shaomiao;<br>
architecture behavior of shaomiao is<br>
type state is (s0,s1,s2,s3);<br>
signal prestate,nexstate:state;<br>
signal A:std_logic_vector(3 downto 0);<br>
begin<br>
&nbsp; &nbsp;process(clk)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp; if(clk'event and clk='1')then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;prestate&lt;=nexstate; <br>
&nbsp; &nbsp;&nbsp; &nbsp; end if;<br>
&nbsp; &nbsp;end process;<br>
&nbsp; &nbsp;process(prestate)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;case prestate is<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s0=&gt;nexstate&lt;=s1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s1=&gt;nexstate&lt;=s2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s2=&gt;nexstate&lt;=s3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when others=&gt;nexstate&lt;=s0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end case;<br>
&nbsp; &nbsp;end process;<br>
&nbsp; &nbsp;process(prestate)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;case prestate is<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s0=&gt;A&lt;=d0;cs&lt;="0111";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s1=&gt;A&lt;=d1;cs&lt;="1011";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when s2=&gt;A&lt;=d2;cs&lt;="1101";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when others=&gt;A&lt;=d3;cs&lt;="1110";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end case;<br>
&nbsp; &nbsp;end process;<br>
&nbsp; &nbsp;process(A)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;case A is<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0000"=&gt;dout&lt;="1111110";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0001"=&gt;dout&lt;="0110000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0010"=&gt;dout&lt;="1101101";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0011"=&gt;dout&lt;="1111001";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0100"=&gt;dout&lt;="0110011";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0101"=&gt;dout&lt;="1011011";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0110"=&gt;dout&lt;="0011111";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"0111"=&gt;dout&lt;="1110000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"1000"=&gt;dout&lt;="1111111";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when"1001"=&gt;dout&lt;="1111011";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;when others =&gt;dout&lt;="0000000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end case;<br>
&nbsp; &nbsp;end process;<br>
end behavior;
usb 发表于 2010-6-26 17:00:39 | 显示全部楼层
还不错<br>
<br>
我的程序都没人帮我弄
AAT 发表于 2010-6-26 18:36:43 | 显示全部楼层
不错<br>

       
interi 发表于 2010-6-26 19:54:17 | 显示全部楼层
你可以看一下标号是SHOW的这个进程,我没空写,这是我以前坐的!<br>
LIBRARY IEEE;<br>
USE IEEE.STD_LOGIC_1164.ALL;<br>
USE IEEE.STD_LOGIC_UNSIGNED.ALL;<br>
ENTITY JSXS IS<br>
PORT(CLR,CLK,EN: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp;&nbsp;SEL: OUT STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
&nbsp; &nbsp;&nbsp;&nbsp;LED8D: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));<br>
END ENTITY JSXS;<br>
ARCHITECTURE ART OF JSXS IS<br>
SIGNAL CLK1S: STD_LOGIC;<br>
SIGNAL D3,D2,D1,D0: STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
SIGNAL D: STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
BEGIN<br>
CLKDIV1S
       
ROCESS(CLR,CLK)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; VARIABLE NCLK: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; VARIABLE CNT: INTEGER RANGE 0 TO 249999;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF CLR='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;NCLK:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSIF CLK'EVENT AND CLK='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF CNT=249999 THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;NCLK:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CNT:=CNT+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;NCLK:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; CLK1S&lt;=NCLK;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; END PROCESS CLKDIV1S;<br>
CNT3600
       
ROCESS(CLR,EN,CLK1S)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE Q3,Q2,Q1,Q0: STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; IF CLR='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q3:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q2:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q1:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q0:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ELSIF CLK1S'EVENT AND CLK1S='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF EN='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF Q0="1001" THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q0:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; IF Q1="0101" THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q1:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF Q2="1001" THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Q2:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF Q3="0101" THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q3:="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q3:=Q3+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Q2:=Q2+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Q1:=Q1+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q0:=Q0+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;D3&lt;=Q3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;D2&lt;=Q2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;D1&lt;=Q1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;D0&lt;=Q0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END PROCESS CNT3600;<br>
SHOW
       
ROCESS(CLK,D3,D2,D1,D0)<br>
&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE CNT: INTEGER RANGE 0 TO 3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE Q: STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE WEI: STD_LOGIC_VECTOR(3 DOWNTO 0);<br>
&nbsp; &nbsp;&nbsp; &nbsp;BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp; IF CLK'EVENT AND CLK='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp; CNT:=CNT+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;CASE CNT IS<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN 0=&gt;WEI:="1110";Q:=D0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN 1=&gt;WEI:="1101";Q:=D1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN 2=&gt;WEI:="1011";Q:=D2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN 3=&gt;WEI:="0111";Q:=D3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END CASE;<br>
&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;D&lt;=Q;<br>
&nbsp; &nbsp;&nbsp; &nbsp;SEL&lt;=WEI;<br>
&nbsp; &nbsp;&nbsp; &nbsp;END PROCESS SHOW;<br>
YMROCESS(D)<br>
&nbsp; &nbsp;BEGIN<br>
&nbsp; &nbsp; CASE D&nbsp;&nbsp;IS<br>
&nbsp; &nbsp; WHEN "0000"=&gt;LED8D&lt;="11111100";<br>
&nbsp; &nbsp; WHEN "0001"=&gt;LED8D&lt;="01100000";<br>
&nbsp; &nbsp; WHEN "0010"=&gt;LED8D&lt;="11011010";<br>
&nbsp; &nbsp; WHEN "0011"=&gt;LED8D&lt;="11110010";<br>
&nbsp; &nbsp; WHEN "0100"=&gt;LED8D&lt;="01100110";<br>
&nbsp; &nbsp; WHEN "0101"=&gt;LED8D&lt;="10110110";<br>
&nbsp; &nbsp; WHEN "0110"=&gt;LED8D&lt;="10111110";<br>
&nbsp; &nbsp; WHEN "0111"=&gt;LED8D&lt;="11100000";<br>
&nbsp; &nbsp; WHEN "1000"=&gt;LED8D&lt;="11111110";<br>
&nbsp; &nbsp; WHEN "1001"=&gt;LED8D&lt;="11110110";<br>
&nbsp; &nbsp; WHEN OTHERS=&gt;NULL;<br>
&nbsp; &nbsp; END CASE;<br>
&nbsp; &nbsp;END PROCESS YM;<br>
END ARCHITECTURE ART
亲你可拉倒吧 发表于 2011-10-26 12:07:11 | 显示全部楼层
保留着以后用
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-24 15:37 , Processed in 0.138944 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表