这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 高校专区 » 周师电子设计创新社区 » 第五次作业

共1条 1/1 1 跳转至

第五次作业

菜鸟
2014-10-31 18:03:21     打赏
3-5

条件赋值语句

LIBRARY IEEE;


USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY decoder3to8 IS

port( DIN: IN STD_LOGIC_VECTOR(2 DOWNTO 0);

DOUT: OUT BIT_VECTOR(7 DOWNTO 0));

END decoder3to8;

ARCHITECTURE behave OF decoder3to8 IS

BEGIN

WITH CONV_INTEGER(DIN) SELECT

DOUT<="00000001" WHEN 0,

"00000010" WHEN 1,

"00000100" WHEN 2,

"00001000" WHEN 3,

"00010000" WHEN 4,

"00100000" WHEN 5,

"01000000" WHEN 6,

"10000000" WHEN 7,

UNAFFECTED WHEN OTHERS;

END behave;

 2 ):case 语句

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY decoder3to8 IS

port( DIN: IN STD_LOGIC_VECTOR(2 DOWNTO 0);

DOUT: OUT BIT_VECTOR(7 DOWNTO 0));

END decoder3to8;

ARCHITECTURE behave OF decoder3to8 IS

BEGIN

PROCESS (DIN)

BEGIN

CASE CONV_INTEGER(DIN) IS

WHEN 0 => DOUT<="00000001";

WHEN 1 => DOUT<="00000010";

WHEN 2 => DOUT<="00000100";

WHEN 3 => DOUT<="00001000";

WHEN 4 => DOUT<="00010000";

WHEN 5 => DOUT<="00100000";

WHEN 6 => DOUT<="01000000";

WHEN 7 => DOUT<="10000000";

WHEN OTHERS => NULL;

END CASE;

END PROCESS;

END behave;

 3 ):if_else 语句

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY decoder3to8 IS

port( DIN: IN STD_LOGIC_VECTOR(2 DOWNTO 0);

DOUT: OUT BIT_VECTOR(7 DOWNTO 0));

END decoder3to8;

ARCHITECTURE behave OF decoder3to8 IS

BEGIN

PROCESS (DIN)

BEGIN

IF CONV_INTEGER(DIN)=0 THEN DOUT<="00000001";

ELSIF CONV_INTEGER(DIN)=1 THEN DOUT<="00000010";

ELSIF CONV_INTEGER(DIN)=2 THEN DOUT<="00000100";

ELSIF CONV_INTEGER(DIN)=3 THEN DOUT<="00001000";

ELSIF CONV_INTEGER(DIN)=4 THEN DOUT<="00010000";

ELSIF CONV_INTEGER(DIN)=5 THEN DOUT<="00100000";

ELSIF CONV_INTEGER(DIN)=6 THEN DOUT<="01000000";

ELSIF CONV_INTEGER(DIN)=7 THEN DOUT<="10000000";

END IF;

END PROCESS;

END behave;

 4 ):移位操作符

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY decoder3to8 IS

port( DIN: IN STD_LOGIC_VECTOR(2 DOWNTO 0);

DOUT: OUT BIT_VECTOR(7 DOWNTO 0));

END decoder3to8;

ARCHITECTURE behave OF decoder3to8 IS

BEGIN

DOUT<="00000001" SLL CONV_INTEGER(DIN);

END behave;

3-14

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY vote_7 IS

PORT( DIN: IN STD_LOGIC_VECTOR(6 DOWNTO 0);

G_4: OUT STD_LOGIC;

CNTH: OUT STD_LOGIC_VECTOR(2 DOWNTO 0));

END vote_7;

ARCHITECTURE BHV OF vote_7 IS

BEGIN

PROCESS(DIN)

VARIABLE Q: STD_LOGIC_VECTOR(2 DOWNTO 0);

BEGIN

Q:="000";

FOR n IN 0 TO 6 LOOP

IF(DIN(n)='1') THEN Q:=Q+1; END IF;

END LOOP;

CNTH<=Q;

IF Q>=4 THEN G_4<='1'; ELSE G_4<='0'; END IF;

END PROCESS;

END BHV;

猜你关注: 无觅关联推荐[?]
宽压输入(1.8V-28V)升压控制器(MAX668)
共1条 1/1 1   
快速回复主题
  • 用户名:wengkai
  • 标题:
  • 内容:
  •  温馨提示:若您所发内容较多,耗时很长,建议您在发送前copy文档,以免出现错误导致文档丢失。
  • 验证码:
 

关于我们 - 广告服务 - 企业会员服务 - 网站地图 - 联系我们 - 征稿 - 友情链接 - 手机EEPW

Copyright ©2002 ELECTRONIC ENGINEERING & PRODUCT WORLD. All rights reserved.
《电子产品世界》杂志社 版权所有 北京东晓国际技术信息咨询有限公司


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]