用if语句实现38译码器(用if语句设计38译码器)

http://www.itjxue.com  2023-01-25 21:08  来源:未知  点击次数: 

用IF语句编写3-8译码器 谢了

3-8译码器,用VHDL语言写的,感觉用case 语句比IF 更易表达

1ibrary ieee ;

use ieee.std-logic-1164.all;

entity eda i s

port(

a,b,c:in std-logic;

d :out std-logic-vector (7 downto 0)

) ;

end eda;

architecture behaviour of eda is

begin

case (c,b ,a) is

when “000”=>d<=“0000000l”;

when “00l”=>d<=“00000010”;

when “0l0”=>d<=“00000100”;

when “011”=>d<=“0000l000”;

when “l00”=>d<=“000l0000”;

when “l0l”=>d<=“00l00000”;

when “l10”=>d<=“01000000”;

when others =>d<=“10000000”; end case;

end behaviour;

利用VHDL的if条件语句描述3线-8线译码器

3-8译码器不是优先权结构,不应当采用IF语句来描述,而应当采用CASE语句来描述。

因为IF语句被综合后会产生带有优先权结构的多级组合逻辑电路,而CASE语句被综合后则会产生不带优先权结构的单级多路选择器,硬件上会更快,占用硬件资源会更少,更符合3-8译码器的逻辑。

8-3优先权编码器应当采用IF语句来描述,而3-8译码器则应当采用CASE语句来描述。

用Verilog语言设计一个3-8译码器~(要求分别用case语句和if_else语句各写一份~)

module decoder38(

input [2:0]code,

output reg[7:0]result

);

always@(*)

begin

case(code)

3'b000: result = 8'h01;

3'b001: result = 8'h02;

3'b010: result = 8'h04;

3'b011: result = 8'h08;

3'b100: result = 8'h10;

3'b101: result = 8'h20;

3'b110: result = 8'h40;

3'b111: result = 8'h80;

endcase

end

endmodule

module decoder38(

input [2:0]code,

output reg[7:0]result

);

always@(*)

begin

if(code[2])

if(code[1])

if(code[0])

result = 8'h80;

else

result = 8'h40;

else

if(code[0])

result = 8'h20;

else

result = 8'h10;

else

else

if(code[1])

if(code[0])

result = 8'h08;

else

result = 8'h04;

else

if(code[0])

result = 8'h02;

else

result = 8'h01;

else

end

endmodule

工作原理

使用Verilog描述硬件的基本设计单元是模块(module)。构建复杂的电子电路,主要是通过模块的相互连接调用来实现的。模块被包含在关键字module、endmodule之内。实际的电路元件。Verilog中的模块类似C语言中的函数,它能够提供输入、输出端口,可以实例调用其他模块,也可以被其他模块实例调用。模块中可以包括组合逻辑部分、过程时序部分。

以上内容参考:百度百科-Verilog HDL

用Verilog语言设计一个3-8译码器~(要求分别用case语句和if_case语句各写一份~)

module decoder38(

input [2:0]code,

output reg[7:0]result

);

always@(*)

begin

case(code)

3'b000: result = 8'h01;

3'b001: result = 8'h02;

3'b010: result = 8'h04;

3'b011: result = 8'h08;

3'b100: result = 8'h10;

3'b101: result = 8'h20;

3'b110: result = 8'h40;

3'b111: result = 8'h80;

endcase

end

endmodule

module decoder38(

input [2:0]code,

output reg[7:0]result

);

always@(*)

begin

if(code[2])

if(code[1])

if(code[0])

result = 8'h80;

else

result = 8'h40;

else

if(code[0])

result = 8'h20;

else

result = 8'h10;

else

else

if(code[1])

if(code[0])

result = 8'h08;

else

result = 8'h04;

else

if(code[0])

result = 8'h02;

else

result = 8'h01;

else

end

endmodule

VHDL 语言的38译码器和4选一数据选择器的CASE语句和IF语句的程序怎么编啊?

啥变量,要求都没有,我就随便写个格式吧

CASE 好像这样

CASE d IS

WHEN”000”=q=”0111111”;

WHEN”001”=q=”0000110”;

WHEN”010”=q=”1011011”;

...

WHEN OTHERS=q=”0000000”

END CASE;

IF 好像这样

IF D='000' THEN

Q='000';

ELSE

IF D='001' THEN

Q='001'

END IF;

END IF;

(责任编辑:IT教学网)

更多

推荐网站策划文章