你还是没有理解什么是硬件描述语.,打个比方,就类似数电,是由实际电路搭起来的,所以必须考虑时序.
for....loop是一个不需要时钟的并行输出语句.你估计和C的for什么的搞混了.
重新给你个参考程序吧,这个能达到串转并的效果.建议你拷贝了仿真看一下,然后把代码看懂了,再动手写你自己的.
entity for_loop is
port(
clk : in std_logic;
serial: out std_logic;
out1: out std_logic_vector(0 to 3)
);
end for_loop;
architecture Behavioral of for_loop is
signal i :integer range 0 to 4:=0;
signal n :integer range 0 to 3:=0;
signal initial: std_logic:='0';
signal o1:std_logic_vector(0 to 3):="0001";
begin
out1<=o1;
initial_case :process(i) is --初始化配置
begin
case i is
when 0 => o1<="0001";
when 1 => o1<="0010";
when 2 => o1<="0100";
when 3 => o1<="1000";
when 4 => initial<='1';
when others =>null;
end case;
end process initial_case;
main:process(clk)
begin
if clk='1' and clk'event then
if initial='0' then --初始化,并转串输出
serial<=o1(n);
if n=3 then
n<=0;
i<=i+1;
else
n<=n+1;
end if;
end if; --初始化完成
else
--从这里开始写控制代码了--
end if;
end process main;
end Behavioral; |