集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 968|回复: 0

课程设计,不懂啊~~~~~求救,关于VHDL语言的

[复制链接]
cailibo541936 发表于 2012-6-12 10:13:36 | 显示全部楼层 |阅读模式
设计一个运算器,可实现输入的2个一位十进制数的加、减运算。任务和要求:输入提供的十个数字键,先转化为8421码,再运
算,输入的数据和输出结果都要在七段数码管显示出来

从程序员网站上找到了源代码,但是自己查了很多资料还是不明白
源代码如下,求各位大神们,能不能多备注一下  好让我理解啊~~~(自己已经备注了一点)
还有一些问题,比如七段数码显示,它的是八位的(貌似8位是连接起来的),但是跟我们教材上的不一样(教材7位)
还有port的各个名称的作用是干啥的?不明白~~~~
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity segment is
    Port ( clk : in  STD_LOGIC;
                         row : in  STD_LOGIC_VECTOR (1 downto 0);
                         key:in std_logic_vector(7 downto 0);
           num : in  STD_LOGIC_VECTOR (15 downto 0);
                          dot :in std_logic;
           com : out  STD_LOGIC_VECTOR (3 downto 0);
           cs : out  STD_LOGIC;
           d : out  STD_LOGIC_VECTOR (7 downto 0));
end segment;

architecture Behavioral of segment is
signal scanclk:std_logic_vector(1 downto 0);
signal scan:std_logic_vector(27 downto 0);
signal seg1,seg2,seg3,seg4,seg:std_logic_vector(7 downto 0);

begin

process(clk)
begin
if rising_edge(clk)then
scan<=scan+'1';                    --非阻塞赋值
end if;
scanclk<=scan(8 downto 7);
end process;
process(row)
begin
if row="01"or row="10"  then

  cs<='0';
d<=key;             --<=运算在库ieee的程序包use IEEE.STD_LOGIC_ARITH.ALL;
else
cs<='1';
d<=seg;
end if;
end process;
process(scanclk)
begin
case scanclk is
when"00"=>
--com<="1110";
com<="0001";
seg<=seg1;
when"01"=>
--com<="1101";
com<="0010";
seg<=seg2(7 downto 5)&dot&seg2(3 downto 0);        --&位连接符seg
when"10"=>
--com<="1011";
com<="0100";
seg<=seg3;
when"11"=>
--com<="0111";
com<="1000";
seg<=seg4;
when others=>
--com<="1111";
com<="0000";
seg<="11111111";
end case;

end process;

  

process(num)
  begin
  case num(3 downto 0) is
    when"0000"=>seg1<="00010001";
         when"0001"=>seg1<="11010111";
         when"0010"=>seg1<="00110010";
         when"0011"=>seg1<="10010010";
         when"0100"=>seg1<="11010100";
         when"0101"=>seg1<="10011000";
         when"0110"=>seg1<="00011000";
         when"0111"=>seg1<="11010011";
         when"1000"=>seg1<="00010000";
         when"1001"=>seg1<="10010000";
        when others=>seg1<="11101111";
  end case;
end process;
process(num)
  begin
  case num(7 downto 4) is
    when"0000"=>seg2<="00010001";
         when"0001"=>seg2<="11010111";
         when"0010"=>seg2<="00110010";
         when"0011"=>seg2<="10010010";
         when"0100"=>seg2<="11010100";
         when"0101"=>seg2<="10011000";
         when"0110"=>seg2<="00011000";
         when"0111"=>seg2<="11010011";
         when"1000"=>seg2<="00010000";
         when"1001"=>seg2<="10010000";
         when others=>seg2<="11101111";
  end case;
end process;
process(num)
begin
   if num(11 downto 8)="1011"then
        seg3<="11111110";
        else
        seg3<="11111111";
        end if;
end process;
process(num)
  begin
  case num(15 downto 12) is

when"1010"=>seg4<="11010110";
         when"1011"=>seg4<="11111110";
        when"1100"=>seg4<="01010100";
when"1101"=>seg4<="10111010";
        when others=>seg4<="11111111";
  end case;
end process;



end Behavioral;
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-7-1 05:49 , Processed in 0.084426 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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