2013-03-11 217 views
3

我想单独设置一个std_logic_vector的位,以便轻松设置单个位或一组位的注释。以下是我有:VHDL std_logic_vector索引与“downto”

signal DataOut : std_logic_vector(7 downto 0); 
... 
DataOut <= (      5=>'1',  -- Instruction defined 
            4=>'1',  -- Data length control bit, high=8bit bus mode selected 
            3=>'1',  -- Display Line Number ctrl bit, high & N3 option pin to VDD=3 lines display 
            2=>'0',  -- Double height font type control byte, not selected 
            1 downto 0=>"01", -- Select Instruction table1 
            others=>'0' -- for bits 6,7 
            ); 

不过,我有一个问题与“DOWNTO”的声明,我得到采用Xilinx ISE以下错误:

Type std_ulogic does not match with a string litteral 

任何解决方案,以避免使用等效

1=>'0', 
0=>'1', 

并允许我逐块设置?

回答

7

当A是数组的元素时,赋值X downto Y => 'A'正确。例如,该片段是正确的:

1 downto 0 => '1', 

而且这个片段是错误的:

1 downto 0 => "01", 

因此,你的任务是非法的。当你的代码,你可以分配为:

DataOut <= (      5 downto 3 =>'1',  
            2 downto 1 =>'0',  
            0 => '1', 
            others=>'0' 
            ); 

如果您想访问/通过阵列的费尔德分配,可以使用串联:

DataOut <= Something_0 & Something_1 & "01"; 

虽然Something_*std_logic_vector

2

做到这一点:

DataOut(7 downto 6)<="00"; 
DataOut(5)<='1'; 
DataOut(4)<='1'; 
DataOut(3)<='1'; 
DataOut(2)<='1'; 
DataOut(1 downto 0)<="01"; 
+0

是,它是一种解决方案,但与'1 =>'0'相同, 0 =>'1','。如果你只是想初始化矢量,例如,这是更好,但还不完美... – feronjb 2013-03-11 11:55:02

+0

将位1..0设置为零,可以使用“,... 1 downto 0 =>'0',...”(与“其他”相同)。 – baldyHDL 2013-03-11 12:50:44

3

另一个答案是用“&”,它失去了命名关联的清晰度串联,虽然你可以使用命名常量恢复一些自我文档的

constant Instr_Defined : std_ulogic := '1'; 
constant Bus_8_Bit  : std_ulogic := '1'; 

DataOut <= "00" & Instr_Defined 
       & Bus_8_Bit 
       & '1'  -- description 
       & '0'  -- ditto 
       & "01"; 

另一个答案是编写一个函数来创建指令:这可以使主流程非常简单明了,同时保持指令编码完全独立并且在一个地方,例如在任何地方使用,你需要知道的指令格式(也许在一个汇编程序以及对CPU)包

DataOut <= Encode_Instruction(Instr_Defined, Bus_8_Bit, Font_Mode); 

这是确定使用任何上述技术,但是冗长的,函数体。越明确越详细越好;它不会让主设计混乱,所以除非改变指令格式,否则你很少看它。