用vhdl语言编写 就是显示时间的那个“8”,有八个“8”,么的能让第一个亮了,第二个亮的时候,第一个还是亮

 我来答
沨_
2010-10-21 · TA获得超过1753个赞
知道小有建树答主
回答量:493
采纳率:66%
帮助的人:322万
展开全部
你说的是七段数码管的动态扫描显示吧。
其实并没有必要让他们一起亮,依次点亮显示即可,但是由于切换的速度很快,由于人的视觉暂留作用,根本看不出是依次点亮的。给你个历程看看吧,下面是一个最简单的交通灯的程序。

其中LEDOut是输出的段码,就是对应的8字的笔画,具体对应关系见segment encoding 那一段。PROCESS( LED )就是字段译码进程,当然也有硬件的译码器。DigitSelect就是数码管的位选,变量Refresh相当于一个计时器,它控制着显示的时序(点亮相应位数的数码管的时候送出相应的段码)

---------------------------------------------------------------------------------------------------
--*************************************************************************************************
-- CreateDate : 2007-07-12
-- ModifData : 2007-07-12
-- Description : LED4 Display
-- Author : Explorer01
-- Version : V1.0
--*************************************************************************************************
---------------------------------------------------------------------------------------------------

-- VHDL library Declarations
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;

---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- The Entity Declarations
ENTITY LED4 IS
PORT
(
RESET: IN STD_LOGIC;
GCLKP1: IN STD_LOGIC;
GCLKP2: IN STD_LOGIC;
beep: OUT STD_LOGIC;
light: OUT std_logic_vector(7 DOWNTO 0);
LEDOut: OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
DigitSelect: OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END LED4;

---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- The Architecture of Entity Declarations
ARCHITECTURE LED4_arch OF LED4 IS
SIGNAL LED: STD_LOGIC_VECTOR(3 downto 0);
SIGNAL Refresh: STD_LOGIC_VECTOR(1 downto 0);

SIGNAL Period1uS, Period1mS, Period1S, ClockScan: STD_LOGIC;
signal count3: std_logic_vector(3 downto 0);
signal count10: std_logic_vector(3 downto 0);
signal yellow: std_logic;
signal stage: std_logic_vector(1 downto 0);
BEGIN

-------------------------------------------------
-- Encoder
-- HEX-to-seven-segment decoder
-- segment encoding
-- 0
-- ---
-- 5 | | 1
-- --- <- 6
-- 4 | | 2
-- ---
-- 3
PROCESS( LED )
BEGIN
CASE LED IS
when "0000"=>LEDOut<= "00111111"; --'0'
when "0001"=>LEDOut<= "00000110"; --'1'
when "0010"=>LEDOut<= "01011011"; --'2'
when "0011"=>LEDOut<= "01001111"; --'3'
when "0100"=>LEDOut<= "01100110"; --'4'
when "0101"=>LEDOut<= "01101101"; --'5'
when "0110"=>LEDOut<= "01111101"; --'6'
when "0111"=>LEDOut<= "00000111"; --'7'
when "1000"=>LEDOut<= "01111111"; --'8'
when "1001"=>LEDOut<= "01101111"; --'9'
when "1010"=>LEDOut<= "01110111"; --'A'
when "1011"=>LEDOut<= "01111100"; --'b'
when "1100"=>LEDOut<= "00111001"; --'C'
when "1101"=>LEDOut<= "01011110"; --'d'
when "1110"=>LEDOut<= "01111001"; --'E'
when "1111"=>LEDOut<= "01110001"; --'F'
when others=>LEDOut<= "XXXXXXXX"; --' '
END CASE;
END PROCESS;

-------------------------------------------------
-- Scan
-- PROCESS( ClockScan, clock )
-- BEGIN
-- IF ClockScan = '0' THEN clock <= '0';
-- ELSE clock <= '1';
-- END IF;
-- END PROCESS;
------------------------------------------------------------------------------
-- Clock
PROCESS( GCLKP1, Period1uS, Period1mS )
VARIABLE Count : STD_LOGIC_VECTOR(3 DOWNTO 0);
VARIABLE Count1 : STD_LOGIC_VECTOR(9 DOWNTO 0);
VARIABLE Count2 : STD_LOGIC_VECTOR(9 DOWNTO 0);
BEGIN
------------------------------------
--Period: 1uS
IF( GCLKP1'EVENT AND GCLKP1='1' ) THEN
IF( Count>"1000" ) THEN Count := "0000";
ELSE Count := Count + 1;
END IF;
Period1uS <= Count(3);
END IF;
------------------------------------
--Period: 1mS
IF( Period1uS'EVENT AND Period1uS='1' ) THEN
IF( Count1>"1111100110" ) THEN Count1 := "0000000000";
ELSE Count1 := Count1 + 1;
END IF;
Period1mS <= Count1(9);
END IF;
------------------------------------
--Period: 1S (1111100110: 998)
IF( Period1mS'EVENT AND Period1mS='1' ) THEN
IF( Count2>"1111100110" ) THEN Count2 := "0000000000";
ELSE Count2 := Count2 + 1;
END IF;

ClockScan <= Count2(1);
Period1S <= Count2(9);
END IF;
END PROCESS;

-------------------------------------------------
-- Clock
process(Period1S,count10,count3,stage)
begin
IF( Period1S'EVENT AND Period1S = '1' )THEN
count10<=count10-1;
beep<='0';
if count10="0000" then
count10<="1001";
count3<=count3-1;
if count3="0000" then
stage<=stage+1;
beep<='1';
case stage is
when "00"=>
count10<="0101";
count3<="0010";
light<="11011011";
yellow<='1';
when "01"=>
count10<="0101";
count3<="0000";
light<="11101101";
yellow<='0';
when "10"=>
count10<="0101";
count3<="0010";
light<="11110110";
yellow<='1';
when "11"=>
count10<="0101";
count3<="0000";
light<="11101101";
yellow<='0';
when others=>
count10<="0101";
count3<="0010";
yellow<='1';
stage<="00";
end case;
end if;
end if;
light(1)<=yellow or (not count10(0));
light(4)<=yellow or (not count10(0));
end if;
end process;

-------------------------------------------------
-- MUX
PROCESS( ClockScan, Period1S, Refresh )
BEGIN
IF( ClockScan'EVENT AND ClockScan = '1' )THEN
Refresh <= Refresh + 1;
END IF;
END PROCESS;

-------------------------------------------------
-- MUX
LED <=
count10 when( Refresh=0 ) else
count3 when( Refresh=1 ) else
count10 when( Refresh=2 ) else
count3;

-------------------------------------------------
-- LED Digit Select
DigitSelect <=
"1110" when( Refresh=0 ) else
"1101" when( Refresh=1 ) else
"1011" when( Refresh=2 ) else
"0111";

-------------------------------------------------
--

END LED4_arch;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式