Crane 
				 
    
 
				 Search 
				Loading
					 
				分类 
				 
				随机文章 
				 
				标签云 
				
    ArchLinux
    Earth
    Fringe
    Gtalk
    Internet
    LFS
    Love
    RegEx
    STL
    Trick
    VHDL
    abs
    c
    c++
    code
    css
    echofon
    firefox
    fun
    g++
    game
    gcc
    geek
    google
    grep
    hack
    linux
    math
    md5
    nginx
    php
    program
    python
    reader
    script
    sed
    shell
    tcpdump
    usaco
    vim
    vimperator
    virus
    wikipedia
    windows
    二进制
    位运算
    危机边缘
    哥德尔
    大牛
    希尔伯特
    数据结构
    日期
    时间
    星期五
    正则表达式
    漫画
    生活
    电影
    程序员
    算法
    维基
    编程
    网络
    美剧
    菜鸟
    越狱
    输入法
    黑色
  
					 
				最新评论 
				 
				链接 
				 
				功能 
				 
				VHDL编程之可逆计数器
数字逻辑学了一个学期,始终都是一堆的门元件和触发器接来接去,实在是搞得人有点晕乎,到了最后大规模集成电路的时候,终于不用(好像也不可能)那些方法了,话说coding the world不是没有道理的,这大规模的电路设计最后还是得软件来搞,可惜还没到CPLD/FPGA的地步,我们就搞了一个用VHDL做的4位(其实用VHDL 的话这个位数只是个数字而已)可逆计数器,觉得蛮有意思,代码丢在这里,万一以后想到查呢?
题目是这样的:
设计一个能清0,置数和进位输出的增1/减1的4位二进制计数器。
输入信号clr为清0端,低电平有效,信号ld为置数端,也是低电平有效,将A,B,C,D的输入值送到计数器中,并立即在Qa,Qb,Qc,Qd中输出。输入信号m为模式选择端,m=1时为加1计数,m=0时为减1计数。当cp端输入一个上升沿信号时进行一次计数,有进位/借位时qcc输出一个负脉冲。
代码如下
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity counte is
port(cp,clr,ld,m:in std_logic;
abcd:in std_logic_vector(3 downto 0);
qcc:out std_logic;
qcount:out std_logic_vector(3 downto 0));
end;
architecture count of counte is
begin
process(cp,clr,ld)
begin
if(clr='0')then
qcount<="0000";
if(m='0')then
qcc<='0';
end if;
elsif(ld='0')then
if(abcd="0000" and m='0')then
qcount<=abcd;
qcc<='0';
elsif(abcd="1111" and m='1')then
qcount<=abcd;
qcc<='0';
else
qcount<=abcd;
qcc<='1';
end if;
elsif(cp'event and cp='1')then
if(qcount="1110" and m='1')then
qcount<="1111";
qcc<='0';
elsif(m='1')then
qcount<=qcount+1;
qcc<='1';
end if;
if(qcount="0001" and m='0')then
qcount<="0000";
qcc<='0';
elsif(m='0')then
qcount<=qcount-1;
qcc<='1';
end if;
                        
end if;
end process;
end count;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity counte is
port(cp,clr,ld,m:in std_logic;
abcd:in std_logic_vector(3 downto 0);
qcc:out std_logic;
qcount:out std_logic_vector(3 downto 0));
end;
architecture count of counte is
begin
process(cp,clr,ld)
begin
if(clr='0')then
qcount<="0000";
if(m='0')then
qcc<='0';
end if;
elsif(ld='0')then
if(abcd="0000" and m='0')then
qcount<=abcd;
qcc<='0';
elsif(abcd="1111" and m='1')then
qcount<=abcd;
qcc<='0';
else
qcount<=abcd;
qcc<='1';
end if;
elsif(cp'event and cp='1')then
if(qcount="1110" and m='1')then
qcount<="1111";
qcc<='0';
elsif(m='1')then
qcount<=qcount+1;
qcc<='1';
end if;
if(qcount="0001" and m='0')then
qcount<="0000";
qcc<='0';
elsif(m='0')then
qcount<=qcount-1;
qcc<='1';
end if;
end if;
end process;
end count;
其中字母基本上和上面要求对应,就是上边的qcount对应Qa,Qb,Qc,Qd。
感觉这样的begin和end的配对,而且整个程序看起来和PASCAL还是有点像的。
2019年10月28日 02:47
I have a question for you if you can guide me that would be amazing. I am working online as a blogger. Can you tell me what to do next about the Wordpress blogs and uniqueness of stuff?
2019年12月01日 09:47
Different platforms can help you to learn some techniques but you can do the best job over here by finding possible solutions. We may guide you to check out my page and help others as well. This is one of the finest and useful technique to guide others, I hope you would like my suggestions in many ways.
2020年1月21日 03:18
Do you have some information which would guide you to write articles actually I want to write for online companies and my core area of concern is to help them through my website for free, do you want to know that they are offering a chance to save some money here, come and grab this offer?
2020年4月13日 12:38
That is impressive and unique as well. I want to know more about your platform if you can help me that would be awesome. Till then, I would say you ought to share more and more pictures with us on this blog.