搜索
bottom↓
回复: 1

CPLD关于变量不能赋值的问题!!帮忙看一下。

[复制链接]

出0入0汤圆

发表于 2011-5-8 20:18:04 | 显示全部楼层 |阅读模式
我觉得发代码来问问题是一件比较麻烦的一件事情。不过没源代码又不知怎么描述这么奇怪的一个问题。全贴出来吧,希望大家能指点一下。这个原本是想做一个24进制的计数器,稍做修改就能实现可变模。但是就在十六进制数转成数码管显示的时候出现了一点问题。下面那个datashi的变量赋值无效。只有datage行。工程文件(Quartus II 4.1写的。)也上传了。刚学VHDL,还不是很习惯,经常会带进C语言的思想,大家指导一下。谢谢!


counter.rarourdev_638307Q7UGSC.rar(文件大小:164K) (原文件名:counter.rar)

(这个与附件一样的方便大家:http://u.115.com/file/bhd7h1pr)


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity counter is
        port (clk,rst,en,load: in std_logic;
                        segduan : out std_logic_vector(6 downto 0);           --段选
                        segwei  : out std_logic_vector(3 downto 0);             --位选
                        setdata : in std_logic_vector(5 downto 0));      --置数输入
end entity counter;

architecture cnter of counter is
        signal bcddspd : std_logic_vector(3 downto 0);       --BCD码段显示
        signal cntclk1 : std_logic_vector(4 downto 0);                 --数时钟
        signal q : std_logic_vector(5 downto 0);                         --计数
       
begin
        p_ctclk:process (clk)
        begin
        if (clk'event and clk='1')then
                if cntclk1 = 31 then cntclk1 <= "00000";
                else cntclk1<=cntclk1+1;
                end if;
        end if;
        end process p_ctclk;
       

        p_cnt:process(cntclk1(4),rst,en,load) begin         --计数器
        if rst='0' then q<=(others=>'0');
        elsif cntclk1(4)'event and cntclk1(4)='1' then
                if en ='1' then
                        if (load='0')then q<=setdata; else
                                if q<24 then q<=q+1;
                                else q<=(others=>'0');
                                end if;
                        end if;
                end if;       
        end if;
        end process p_cnt;
       
        p_cvt:process (q,clk,rst)
        variable datage,datashi:std_logic_vector(3 downto 0);
        begin
        if (clk'event and clk='1')then
                --转换数码管显示
--                datage:=q(3 downto 0);
                datage:='0'&'0'&q(5 downto 4);
--                datashi:='0'&'0'&q(5 downto 4);
--                if datashi>"1001" then
--                        datashi:=datashi-"1010";
--                        datage:=datage+'1';
--                end if;
--                if datage>"1001" then
--                datage:=datage-"1010";
--                end if;
        end if;
--        if(rst = '0')then --复位清零
--        segwei<="0000";
--        elsif clk = '1' then segwei<="0001";bcddspd<=datage;
--        else segwei<="0010";bcddspd<=datashi;
--        end if;
        end process p_cvt;

        p_dspd:process(bcddspd) begin
        case bcddspd is --送段选数据
        when "0000" => segduan<="0111111"; when "0001" => segduan<="0000110";
        when "0010" => segduan<="1011011"; when "0011" => segduan<="1001111";
        when "0100" => segduan<="1100110"; when "0101" => segduan<="1101101";
        when "0110" => segduan<="1111101"; when "0111" => segduan<="0000111";
        when "1000" => segduan<="1111111"; when "1001" => segduan<="1101111";
        when "1010" => segduan<="1110111"; when "1011" => segduan<="1111100";
        when "1100" => segduan<="0111001"; when "1101" => segduan<="1011110";
        when "1110" => segduan<="1111001"; when "1111" => segduan<="1110001";
        when others => segduan<="0000000";
        end case;
        end process p_dspd;
end architecture cnter;

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 15:26

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表