VHDL 怎么把16进制转成10进制
例如有一个std_logic_vector(7downto0),0x00~0xFF的,想转换成std_logic_vector(11downto0),0~255也就是象B...
例如有一个std_logic_vector(7 downto 0),0x00~0xFF的,想转换成std_logic_vector(11 downto 0),0~255
也就是象BCD码一样 展开
也就是象BCD码一样 展开
展开全部
给你个函数,0x00~0xFF转换成0~255
function HEX2DEC(data_in : std_logic_vector(7 downto 0)) return std_logic_vector is
variable data : std_logic_vector(7 downto 0);
variable data_out : std_logic_vector(11 downto 0);
begin
data := data_in;
if data >= 200 then
data_out(11 downto 8) := x"2";
data := data - 200;
elsif data >= 100 then
data_out(11 downto 8) := x"1";
data := data - 100;
else
data_out(11 downto 8) := x"0";
data := data;
end if;
if data >= 90 then
data_out(7 downto 4) := x"9";
data := data - 90;
elsif data >= 80 then
data_out(7 downto 4) := x"8";
data := data - 80;
elsif data >= 70 then
data_out(7 downto 4) := x"7";
data := data - 70;
elsif data >= 60 then
data_out(7 downto 4) := x"6";
data := data - 60;
elsif data >= 50 then
data_out(7 downto 4) := x"5";
data := data - 50;
elsif data >= 40 then
data_out(7 downto 4) := x"4";
data := data - 40;
elsif data >= 30 then
data_out(7 downto 4) := x"3";
data := data - 30;
elsif data >= 20 then
data_out(7 downto 4) := x"2";
data := data - 20;
elsif data >= 10 then
data_out(7 downto 4) := x"1";
data := data - 10;
else
data_out(7 downto 4) := x"0";
data := data;
end if;
data_out(3 downto 0) := data(3 downto 0);
return data_out;
end HEX2DEC;
function HEX2DEC(data_in : std_logic_vector(7 downto 0)) return std_logic_vector is
variable data : std_logic_vector(7 downto 0);
variable data_out : std_logic_vector(11 downto 0);
begin
data := data_in;
if data >= 200 then
data_out(11 downto 8) := x"2";
data := data - 200;
elsif data >= 100 then
data_out(11 downto 8) := x"1";
data := data - 100;
else
data_out(11 downto 8) := x"0";
data := data;
end if;
if data >= 90 then
data_out(7 downto 4) := x"9";
data := data - 90;
elsif data >= 80 then
data_out(7 downto 4) := x"8";
data := data - 80;
elsif data >= 70 then
data_out(7 downto 4) := x"7";
data := data - 70;
elsif data >= 60 then
data_out(7 downto 4) := x"6";
data := data - 60;
elsif data >= 50 then
data_out(7 downto 4) := x"5";
data := data - 50;
elsif data >= 40 then
data_out(7 downto 4) := x"4";
data := data - 40;
elsif data >= 30 then
data_out(7 downto 4) := x"3";
data := data - 30;
elsif data >= 20 then
data_out(7 downto 4) := x"2";
data := data - 20;
elsif data >= 10 then
data_out(7 downto 4) := x"1";
data := data - 10;
else
data_out(7 downto 4) := x"0";
data := data;
end if;
data_out(3 downto 0) := data(3 downto 0);
return data_out;
end HEX2DEC;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询