|
设计一个运算器,可实现输入的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; |
|