用VHDL语言编写程序
条件如下:Clk时钟信号为48MHZ。要求程序在电路板上运行时8个LED小灯从最低位开始每隔0.5秒依次亮一个,即开始是最低位小灯亮,其他的灯是灭的,过0.5秒第二个灯是...
条件如下:
Clk时钟信号为48MHZ。要求程序在电路板上运行时8个LED小灯从最低位开始每隔0.5秒依次亮一个,即开始是最低位小灯亮,其他的灯是灭的,过0.5秒第二个灯是亮的,其他全灭。如此依次往下亮。当到第8个(即最后一个)灯灭后,所有8个灯全亮。然后过0.5秒又是第一个灯亮。如此循环下去。
希望哪位高人精通VHDL语言,帮小弟编下这个程序,采纳加分!!!
谢谢谢谢!!!!!!
顺便说下,这个程序一定能在Xilinx-ISE上运行成功。
再次感谢!! 展开
Clk时钟信号为48MHZ。要求程序在电路板上运行时8个LED小灯从最低位开始每隔0.5秒依次亮一个,即开始是最低位小灯亮,其他的灯是灭的,过0.5秒第二个灯是亮的,其他全灭。如此依次往下亮。当到第8个(即最后一个)灯灭后,所有8个灯全亮。然后过0.5秒又是第一个灯亮。如此循环下去。
希望哪位高人精通VHDL语言,帮小弟编下这个程序,采纳加分!!!
谢谢谢谢!!!!!!
顺便说下,这个程序一定能在Xilinx-ISE上运行成功。
再次感谢!! 展开
3个回答
展开全部
我用quartusⅡ已编译并且仿真都对的,我写的是0亮1灭,如果实际情况与这相反,你自己倒一下。
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_SIGNED.ALL;
USE IEEE.numeric_std.all;
ENTITY test IS
PORT (clock: in std_logic; -----clock1加48MHz的信号
row: out std_logic_vector(0 to 7));
END test;
ARCHITECTURE behave OF test IS
CONSTANT fp_clka:INTEGER:=12000000; ---扫描信号频率为2Hz
SIGNAL a: INTEGER RANGE 0 TO 12000001;
signal saomiao :integer range 0 to 9;
SIGNAL clka: std_logic;
BEGIN
PROCESS (clock)
BEGIN
IF rising_edge(clock) THEN
IF a<fp_clka then --clka
a<=a+1;
clka<=clka;
ELSE
a<=0;
clka<= NOT clka;
end if;
end if;
end process;
process(clka)
BEGIN
IF rising_edge(clka) THEN
saomiao<=saomiao+1;
if saomiao=9 then
saomiao<=0;
end if;
case saomiao is ---'1'代表不亮,'0'代表亮
when 0 =>row<="01111111";
when 1 =>row<="10111111";
when 2 =>row<="11011111";
when 3 =>row<="11101111";
when 4 =>row<="11110111";
when 5 =>row<="11111011";
when 6 =>row<="11111101";
when 7 =>row<="11111110";
when 8 =>row<="00000000";
when others =>row<="11111111";
END CASE;
END IF;
end process;
END behave;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_SIGNED.ALL;
USE IEEE.numeric_std.all;
ENTITY test IS
PORT (clock: in std_logic; -----clock1加48MHz的信号
row: out std_logic_vector(0 to 7));
END test;
ARCHITECTURE behave OF test IS
CONSTANT fp_clka:INTEGER:=12000000; ---扫描信号频率为2Hz
SIGNAL a: INTEGER RANGE 0 TO 12000001;
signal saomiao :integer range 0 to 9;
SIGNAL clka: std_logic;
BEGIN
PROCESS (clock)
BEGIN
IF rising_edge(clock) THEN
IF a<fp_clka then --clka
a<=a+1;
clka<=clka;
ELSE
a<=0;
clka<= NOT clka;
end if;
end if;
end process;
process(clka)
BEGIN
IF rising_edge(clka) THEN
saomiao<=saomiao+1;
if saomiao=9 then
saomiao<=0;
end if;
case saomiao is ---'1'代表不亮,'0'代表亮
when 0 =>row<="01111111";
when 1 =>row<="10111111";
when 2 =>row<="11011111";
when 3 =>row<="11101111";
when 4 =>row<="11110111";
when 5 =>row<="11111011";
when 6 =>row<="11111101";
when 7 =>row<="11111110";
when 8 =>row<="00000000";
when others =>row<="11111111";
END CASE;
END IF;
end process;
END behave;
展开全部
请问下灯是0亮还是1亮,引脚配置需要你自己弄下了。
若为1亮则有:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity LEDcontrol is ----定义实体名为 LEDcontrol
port(
CLK :in std_logic; ----输入时钟
LED8 :out std_logic_vector(7 downto 0)----8位输出
);
end entity LEDcontrol;
architecture LEDC of LEDcontrol is
signal n :integer range 0 to 23999999;---------24000000 分频
signal m :integer range 0 to 9;
signal C500ms :std_logic;-------内0.5s时钟
begin
------------------------------------------------------------------------------------------------------------
CLK_500ms:process(CLK) ---- 输入时钟分频
begin
if CLK'event and CLK='1' then
if n<12000000 then
n<=n+1;
CP1ms<='0'; ---- 低电平持续0.25s
elsif n<23999999 then
n<=n+1;
CP1ms<='1'; ---- 高电平持续0.25s
else
n<=0;
end if;
end if;
end process CLK_500ms;
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
LED_CON:process(C500ms) ---- 点灯控制
begin
if C500ms'event and C500ms='1' then
if m<9 then
if m=0 then
LED8 <= "00000001"; ----0亮的话改成"11111110"就可以了,以下类似
m <= m + 1;
elsif m=1 then
LED8 <= "00000010";
m <= m + 1;
elsif m=2 then
LED8 <= "00000100";
m <= m + 1;
elsif m=3 then
LED8 <= "00001000";
m <= m + 1;
elsif m=4 then
LED8 <= "00010000";
m <= m + 1;
elsif m=5 then
LED8 <= "00100000";
m <= m + 1;
elsif m=6 then
LED8 <= "01000000";
m <= m + 1;
elsif m=7 then
LED8 <= "10000000";
m <= m + 1;
elsif m=8 then
LED8 <= "11111111";
m <= m + 1;
else
LED8 <= "00000000";
m <= 0;
end if;
end if;
end process LED_CON;
------------------------------------------------------------------------------------------------------------
end LEDC;
若为1亮则有:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity LEDcontrol is ----定义实体名为 LEDcontrol
port(
CLK :in std_logic; ----输入时钟
LED8 :out std_logic_vector(7 downto 0)----8位输出
);
end entity LEDcontrol;
architecture LEDC of LEDcontrol is
signal n :integer range 0 to 23999999;---------24000000 分频
signal m :integer range 0 to 9;
signal C500ms :std_logic;-------内0.5s时钟
begin
------------------------------------------------------------------------------------------------------------
CLK_500ms:process(CLK) ---- 输入时钟分频
begin
if CLK'event and CLK='1' then
if n<12000000 then
n<=n+1;
CP1ms<='0'; ---- 低电平持续0.25s
elsif n<23999999 then
n<=n+1;
CP1ms<='1'; ---- 高电平持续0.25s
else
n<=0;
end if;
end if;
end process CLK_500ms;
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
LED_CON:process(C500ms) ---- 点灯控制
begin
if C500ms'event and C500ms='1' then
if m<9 then
if m=0 then
LED8 <= "00000001"; ----0亮的话改成"11111110"就可以了,以下类似
m <= m + 1;
elsif m=1 then
LED8 <= "00000010";
m <= m + 1;
elsif m=2 then
LED8 <= "00000100";
m <= m + 1;
elsif m=3 then
LED8 <= "00001000";
m <= m + 1;
elsif m=4 then
LED8 <= "00010000";
m <= m + 1;
elsif m=5 then
LED8 <= "00100000";
m <= m + 1;
elsif m=6 then
LED8 <= "01000000";
m <= m + 1;
elsif m=7 then
LED8 <= "10000000";
m <= m + 1;
elsif m=8 then
LED8 <= "11111111";
m <= m + 1;
else
LED8 <= "00000000";
m <= 0;
end if;
end if;
end process LED_CON;
------------------------------------------------------------------------------------------------------------
end LEDC;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我用quartusⅡ已编译并且仿真都对的,我写的是0亮1灭,如果实际情况与这相反,你自己倒一下。
LIBRARY
IEEE;
USE
IEEE.STD_LOGIC_1164.ALL;
USE
IEEE.STD_LOGIC_SIGNED.ALL;
USE
IEEE.numeric_std.all;
ENTITY
test
IS
PORT
(clock:
in
std_logic;
-----clock1加48MHz的信号
row:
out
std_logic_vector(0
to
7));
END
test;
ARCHITECTURE
behave
OF
test
IS
CONSTANT
fp_clka:INTEGER:=12000000;
---扫描信号频率为2Hz
SIGNAL
a:
INTEGER
RANGE
0
TO
12000001;
signal
saomiao
:integer
range
0
to
9;
SIGNAL
clka:
std_logic;
BEGIN
PROCESS
(clock)
BEGIN
IF
rising_edge(clock)
THEN
IF
a<fp_clka
then
--clka
a<=a+1;
clka<=clka;
ELSE
a<=0;
clka<=
NOT
clka;
end
if;
end
if;
end
process;
process(clka)
BEGIN
IF
rising_edge(clka)
THEN
saomiao<=saomiao+1;
if
saomiao=9
then
saomiao<=0;
end
if;
case
saomiao
is
---'1'代表不亮,'0'代表亮
when
0
=>row<="01111111";
when
1
=>row<="10111111";
when
2
=>row<="11011111";
when
3
=>row<="11101111";
when
4
=>row<="11110111";
when
5
=>row<="11111011";
when
6
=>row<="11111101";
when
7
=>row<="11111110";
when
8
=>row<="00000000";
when
others
=>row<="11111111";
END
CASE;
END
IF;
end
process;
END
behave;
LIBRARY
IEEE;
USE
IEEE.STD_LOGIC_1164.ALL;
USE
IEEE.STD_LOGIC_SIGNED.ALL;
USE
IEEE.numeric_std.all;
ENTITY
test
IS
PORT
(clock:
in
std_logic;
-----clock1加48MHz的信号
row:
out
std_logic_vector(0
to
7));
END
test;
ARCHITECTURE
behave
OF
test
IS
CONSTANT
fp_clka:INTEGER:=12000000;
---扫描信号频率为2Hz
SIGNAL
a:
INTEGER
RANGE
0
TO
12000001;
signal
saomiao
:integer
range
0
to
9;
SIGNAL
clka:
std_logic;
BEGIN
PROCESS
(clock)
BEGIN
IF
rising_edge(clock)
THEN
IF
a<fp_clka
then
--clka
a<=a+1;
clka<=clka;
ELSE
a<=0;
clka<=
NOT
clka;
end
if;
end
if;
end
process;
process(clka)
BEGIN
IF
rising_edge(clka)
THEN
saomiao<=saomiao+1;
if
saomiao=9
then
saomiao<=0;
end
if;
case
saomiao
is
---'1'代表不亮,'0'代表亮
when
0
=>row<="01111111";
when
1
=>row<="10111111";
when
2
=>row<="11011111";
when
3
=>row<="11101111";
when
4
=>row<="11110111";
when
5
=>row<="11111011";
when
6
=>row<="11111101";
when
7
=>row<="11111110";
when
8
=>row<="00000000";
when
others
=>row<="11111111";
END
CASE;
END
IF;
end
process;
END
behave;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询