📄 新建 文本文档.txt
字号:
附录I:
控制模块程序
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity kong is
Port ( left,right : in STD_LOGIC;
lft,rit,lr : out STD_LOGIC);
end kong;
architecture Behavioral of kong is
begin
process(left,right)
variable a:std_logic_vector(1 downto 0);
begin
a:=left&right;
case a is
when"00"=>lft<='0';
rit<='0';
lr<='0';
when"10"=>lft<='1';
rit<='0';
lr<='0';
when"01"=>lft<='0';
rit<='1';
lr<='0';
when others=>rit<='1';
lft<='1';
lr<='1';
end case;
end process;
end Behavioral;
附录II:
灯左转的程序
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity lfta is
Port ( clk,en,lr : in STD_LOGIC;
l2,l0,l1 : out STD_LOGIC);
end lfta;
architecture Behavioral of lfta is
begin
process(clk,en,lr)
variable tmp:std_logic_vector(2 downto 0);
begin
if lr='1' then
tmp:="111";
elsif en='0' then
tmp:="000";
elsif clk'event and clk='1' then
if tmp="000" then
tmp:="001";
else
tmp:=tmp(1 downto 0)&'0';
end if;
end if;
l2<=tmp(2);
l1<=tmp(1);
l0<=tmp(0);
end process;
end Behavioral;
附录III:
灯右转的程序
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity rita is
Port ( clk,en,lr : in STD_LOGIC;
r1,r2,r0 : out STD_LOGIC);
end rita;
architecture Behavioral of rita is
begin
process(clk,en,lr)
variable tmp:std_logic_vector(2 downto 0);
begin
if lr='1' then
tmp:="111";
elsif en='0' then
tmp:="000";
elsif clk'event and clk='1' then
if tmp="000" then
tmp:="100";
else
tmp:='0'&tmp(2 downto 1);
end if;
end if;
r2<=tmp(2);
r1<=tmp(1);
r0<=tmp(0);
end process;
end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -