|
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
package thfir6td_pkg is
type std_logic_vector_arrray is array(natural range<>)of std_logic_vector(7 downto 0 );
function "/" (l:integer;r:integer)return integer;
function "mod"(L:integer;R:integer)return integer;
function get1(num:integer range 0 to 255)return integer;
function get10(num:integer range 0 to 255)return integer;
function get100(num:integer range 0 to 255)return integer;
function getledeode(digit:integer range 0 to 9)return std_logic_vector;
function getapcode(num:integer range 0 to 15)return std_logic_vector;
function getsqrt(num:integer range 0 to 255)return integer;
end thfir6td_pkg;
package body thfir6td_pkg is
function "/"(l:integer;r:integer) return integer is
variable ll,rr:integer;
variable quotient:integer;
begin
ll:=l;
rr:=r;
quotient := 0;
for I in 1 to 10 loop
if ll >= rr then
ll:= ll-rr;
quotient:= quotient+1;
end if;
end loop;
return quotient;
end;
function "mod"(l:integer;r:integer) return integer is
variable ll,rr:integer;
variable residue:integer;
begin
ll:=l;
rr:=r;
residue := 0;
for I in 1 to 10 loop
if ll >= rr then
ll:= ll-rr;
end if;
end loop;
residue:=LL;
return residue;
end;
function get1(num:integer range 0 to 255) return integer is
variable result : integer range 0 to 9;
begin
result := num mod 10;
return result;
end;
function get10(num : integer range 0 to 255) return integer is
variable result : integer range 0 to 9;
begin
result :=(num mod 100)/10;
return result;
end;
function get100(num : integer range 0 to 255) return integer is
variable result : integer range 0 to 9;
begin
result := num/100;
return result;
end;
function getledcode(digit : integer range 0 to 9) return std_logic_vector is
variable result : std_logic_vector(6 downto 0);
begin
case digit is
when 0=> result := "1111110";
when 1=> result := "0001100";
when 2=> result := "0110111";
when 3=> result := "0011111";
when 4=> result := "1001101";
when 5=> result := "1011011";
when 6=> result := "1111011";
when 7=> result := "0001110";
when 8=> result := "1111111";
when 9=> result := "1001111";
when others => result:="0000000";
end case;
return result;
end;
function getapcode(num : integer range 0 to 15) return std_logic_vector is
variable result : std_logic_vector (15 downto 0);
begin
result :="0000000000000000";
result(num) := '1';
return result;
end;
function getsqrt(num : integer range 0 to 255) return integer is
variable result : integer range 0 to 15;
begin
if num <64 then --0~64
if num <16 then --0~16
if num <4 then --0~4
if num <1 then --0~1
result := 0;
else --1~4
result := 1;
end if;
else --4~16
if num <9 then --4~9
result := 2;
else --9~16
result := 3;
end if;
end if;
else --16~64
if num <36 then --16~36
if num <25 then --16~25
result := 4;
else --25~36
result := 5;
end if;
else --36~64
if num <49 then --36~49
result := 6;
else --49~64
result := 7;
end if;
end if;
end if;
else --64~256
if num <144 then --64~144
if num <100 then --64~100
if num <81 then --64~81
result := 8;
else --81~100
result := 9;
end if;
else --100~144
if num <121 then --100~121
result := 10;
else --121~144
result := 11;
end if;
end if;
else --144~256
if num <196 then --144~196
if num <169 then --144~169
result := 12;
else --169~196
result := 13;
end if;
else --196~256
if num <225 then --196~225
result := 14;
else --225~256
result :=15;
end if;
end if;
end if;
end if;
return result;
end;
end thfir6td_pkg;
高手帮小弟看一下这个代码的问题,小弟没用过包集合。谢谢