VHDL程序设计题,100F

VHDL程序设计题,100F,第1张

一 bcd加法器。 两位BCD数加法器其事用8位的二进制数加法器就可以了,以下是我最近几天衡敬才学的 , 呵呵, 我是EDA的 菜鸟呢

library IEEE

use IEEE.std_logic_1164.all

use ieee.numeric_std.all

entity bcdadder is

port (a: in std_logic_vector(7 downto 0)

b: in std_logic_vector(7 downto 0)

cin : in std_logic

sum : out std_logic_vector(7 downto 0)

cout : out std_logic)

end bcdadder

architecture badder of bcdadder is

signal result : unsigned (8 downto 0)

signal carry : unsigned (8 downto 0)

constant zeros: unsigned (7 downto 0) := (others=>庆绝'0')

begin

carry <=(zeros &cin )

result <=('0'誉拦姿 &unsigned(a) )+ ('0' &unsigned(b))+carry

sum<= std_logic_vector(result(7 downto 0))

cout <= result (8)

end architecture badder

编译通过,我还没仿真测试呢

后两个晚点写给你,太晚了,虽然明天是周日

VHDL设计一拆做个双进程状态机,原程序如下(后面的图是仿真结果):

LIBRARY ieee

use ieee.std_logic_1164.all

use ieee.std_logic_arith.all

use ieee.std_logic_unsigned.all

entity dou_state is

port(clk,rst : in std_logic

      din    : in std_logic_vector(1 downto 0)

      dout   : out std_logic_vector(3 downto 0))

end dou_state

architecture arch of dou_state is

type state_type is (s0,s1,s2,s3)

signal state : state_type

begin

P1: process(clk,rst)

begin

if rst='0' then

state <= s0

dout  <= "0000"

elsif clk'event and clk='1' then

case state is

when s0 =>

   if din = "10" then

      state <= s1

   else

      state <= s0

      dout <= "1001"

   end if

when s1 =>

   if din = "11" then

      state <= s2

   else

      state <= s1

      dout <= "0101"

   脊御扮end 樱灶if

when s2 =>

   if din = "01" then

      state <= s3

   else

      state <= s2

      dout <= "1100"

    end if

when s3 =>

   if din = "00" then

      state <= s0

   else

      state <= s3

      dout <= "0010"

   end if

when others =>

   NULL

end case

end if

end process

end arch


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12564388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存