aiany1019的个人空间 https://blog.eetop.cn/39586 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

问题

已有 675 次阅读| 2007-1-17 15:15

天气: 晴朗
心情: 高兴

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;

高手帮小弟看一下这个代码的问题,小弟没用过包集合。谢谢


点赞

发表评论 评论 (2 个评论)

Guest 2007-4-9 13:48
http://9eccf8ca6b24cb1dea44075882cb4493-t.rh5t5bf.info <a href="http://9eccf8ca6b24cb1dea44075882cb4493-h.rh5t5bf.info">9eccf8ca6b24cb1dea44075882cb4493</a> [url]http://9eccf8ca6b24cb1dea44075882cb4493-b1.rh5t5bf.info[/url] [url=http://9eccf8ca6b24cb1dea44075882cb4493-b2.rh5t5bf.info]9eccf8ca6b24cb1dea44075882cb4493[/url] [u]http://9eccf8ca6b24cb1dea44075882cb4493-b3.rh5t5bf.info[/u] 0c4df95de00b5aa0f800bcc958a3b7df
Guest 2007-5-1 09:36
http://5e0428cb8d3e13a4b27fe1ec6c927f82-t.k90u0h.info <a href="http://5e0428cb8d3e13a4b27fe1ec6c927f82-h.k90u0h.info">5e0428cb8d3e13a4b27fe1ec6c927f82</a> [url]http://5e0428cb8d3e13a4b27fe1ec6c927f82-b1.k90u0h.info[/url] [url=http://5e0428cb8d3e13a4b27fe1ec6c927f82-b2.k90u0h.info]5e0428cb8d3e13a4b27fe1ec6c927f82[/url] [u]http://5e0428cb8d3e13a4b27fe1ec6c927f82-b3.k90u0h.info[/u] 86b4eaaaf8201e29470f084ce1d2d695

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 4

    评论
  • 47

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-17 09:17 , Processed in 0.024916 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部