library ieee;
use ieee.std_logic_1164.all;
entity scan_led_10000_multifuction is
port(
clk : in std_logic;--50MHz输入端,提供系统时钟。
reset: in std_logic_vector(4 downto 0);--复位信号输入,从低到高依次复位个位,十位,百位,千位和全部复位。
pause:in std_logic;--暂停信号输入,低电平有效。
rsr:in std_logic;--置位信号,低电平有效。
SG : out std_logic_vector(7 downto 0);--段控制信号输出,abcdefgh低电平有效(小数点h不显示,时钟保持高电平),单个数码管字符显示
BT : out std_logic_vector(3 downto 0); --位控制信号输出,低电平有效,四个数码管的片选
LED: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));--计数流水灯输出,低电平有效,全灭代表进位信号(初始0除外)。
end scan_led_10000_multifuction;
architecture behave of scan_led_10000_multifuction is
signal scan : integer range 0 to 3;--扫描数码管个数
signal cnt_50MHz : integer range 0 to 49999999;--输入时钟计数
signal cnt_1kHz : integer range 0 to 50000;--1kHz时钟计数
signal clk1kHz : integer range 0 to 1;--数码管扫描时钟
signal clk1Hz : integer range 0 to 1;--1s计数时钟
signal ledag1,ledag2,ledag3,ledag4 : std_logic_vector(7 downto 0);--四个数码管的动态字符显示
signal cnt_One,cnt_Ten,cnt_Hundred,cnt_thousand:integer range 0 to 9 :=0;--数码管计数的个位、十位、百位、千位,范围0-9,初始值均为0。
begin
--1s计数时钟模块
Module_1Hz : process(clk)
begin
if(clk'event and clk='1')then
if(cnt_50MHz=49999999)then
cnt_50MHz<=0;
else
cnt_50MHz<=cnt_50MHz+1;
end if;
if(cnt_50MHz<=24999999)then
clk1Hz<=1;
else
clk1Hz<=0;
end if;
end if;
end process module_1Hz;
--1kHz时钟扫描模块
Module_1kHz : process(clk1khz)
begin
if (clk'event and clk='1') then
if (cnt_1kHz=50000) then
cnt_1kHz<=0;
else
cnt_1kHz<=cnt_1kHz+1;
end if;
if(cnt_1kHz<=25000) then
clk1kHz<=1;
else
clk1kHz<=0;
end if;
end if;
--扫描模块
if(clk1kHz'event and clk1kHz=1)then
if(scan=3)then
scan<=0;
else
scan<=scan+1;
end if;
end if;
end process Module_1kHz;
--1s计数模块,四个数码管累加显示数字,范围0000-9999
Module_cnt : process(clk1Hz)
begin
if rsr='1' then--置位信号,低电平有效。
if pause='1' then
if reset="11111" then
if(clk1Hz'event and clk1Hz=1) then
if(cnt_One=9)then
if(cnt_Ten=9)then
if(cnt_Hundred=9)then
if(cnt_thousand=9)then--计数溢出,全部清零。
cnt_thousand<=0;
cnt_Hundred<=0;
cnt_Ten<=0;
cnt_One<=0;
else
cnt_thousand<=cnt_thousand+1;--千位加1,清零个十百位。
cnt_Hundred<=0;
cnt_Ten<=0;
cnt_One<=0;
end if;
else
cnt_Hundred<=cnt_Hundred+1;--百位加1,清零个十位。
cnt_Ten<=0;
cnt_One<=0;
end if;
else
cnt_Ten<=cnt_Ten+1;--十位加1,个位清0。
cnt_One<=0;
end if;
else
cnt_One<=cnt_One+1;--个位一直相加。
end if;
end if;
elsif reset="11110" then--复位个位
cnt_One<=0;
elsif reset="11101" then--复位十位
cnt_ten<=0;
elsif reset="11011" then--复位百位
cnt_hundred<=0;
elsif reset="10111" then--复位千位
cnt_thousand<=0;
elsif reset="01111" then--复位全部
cnt_One<=0;
CNT_Ten<=0;
CNT_Hundred<=0;
CNT_thousand<=0;
end if;
end if;
else--置位信号有效,个十百千均置成9
cnt_One<=9;
CNT_Ten<=9;
CNT_Hundred<=9;
CNT_thousand<=9;
end if;
end process Module_cnt;
--译码电路1,数码管1动态字符查表
Module_Decoding_1 : process(cnt_One)
begin
case cnt_One is
when 0 => ledag1 <= "11111100";led<="11111111";--数字0,灯全灭,代表进位。
when 1 => ledag1 <= "01100000";led<="01111111";--数字1,点亮第一个灯。
when 2 => ledag1 <= "11011010";led<="10111111";--数字2,点亮第二个灯。
when 3 => ledag1 <= "11110010";led<="11011111";--数字3,点亮第三个灯。
when 4 => ledag1 <= "01100110";led<="11101111";--数字4,点亮第四个灯。
when 5 => ledag1 <= "10110110";led<="11110111";--数字5,点亮第五个灯。
when 6 => ledag1 <= "10111110";led<="11111011";--数字6,点亮第六个灯。
when 7 => ledag1 <= "11100100";led<="11111101";--数字7,点亮第七个灯。
when 8 => ledag1 <= "11111110";led<="11111110";--数字8,点亮第八个灯。
when 9 => ledag1 <= "11110110";led<="11111101";--数字9,点亮第七个灯。实现计数流水灯效果。
when others => Null;
end case;
end process Module_Decoding_1;
--译码电路2,数码管2动态字符查表
Module_Decoding_2 : process(cnt_Ten)
begin
case cnt_Ten is
when 0 => ledag2 <= "11111100";--数字0
when 1 => ledag2 <= "01100000";--数字1
when 2 => ledag2 <= "11011010";--数字2
when 3 => ledag2 <= "11110010";--数字3
when 4 => ledag2 <= "01100110";--数字4
when 5 => ledag2 <= "10110110";--数字5
when 6 => ledag2 <= "10111110";--数字6
when 7 => ledag2 <= "11100100";--数字7
when 8 => ledag2 <= "11111110";--数字8
when 9 => ledag2 <= "11110110";--数字9
when others => Null;
end case;
end process Module_Decoding_2;
--译码电路3,数码管3动态字符查表
Module_Decoding_3 : process(cnt_Hundred)
begin
case cnt_Hundred is
when 0 => ledag3 <= "11111100";--数字0
when 1 => ledag3 <= "01100000";--数字1
when 2 => ledag3 <= "11011010";--数字2
when 3 => ledag3 <= "11110010";--数字3
when 4 => ledag3 <= "01100110";--数字4
when 5 => ledag3 <= "10110110";--数字5
when 6 => ledag3 <= "10111110";--数字6
when 7 => ledag3 <= "11100100";--数字7
when 8 => ledag3 <= "11111110";--数字8
when 9 => ledag3 <= "11110110";--数字9
when others => Null;
end case;
end process Module_Decoding_3;
--译码电路4,数码管4动态字符查表
Module_Decoding_4 : process(cnt_thousand)
begin
case cnt_thousand is
when 0 => ledag4 <= "11111100";--数字0
when 1 => ledag4 <= "01100000";--数字1
when 2 => ledag4 <= "11011010";--数字2
when 3 => ledag4 <= "11110010";--数字3
when 4 => ledag4 <= "01100110";--数字4
when 5 => ledag4 <= "10110110";--数字5
when 6 => ledag4 <= "10111110";--数字6
when 7 => ledag4 <= "11100100";--数字7
when 8 => ledag4 <= "11111110";--数字8
when 9 => ledag4 <= "11110110";--数字9
when others => Null;
end case;
end process Module_Decoding_4;
--刷新显示模块
Module_SG : process(scan)
begin
case scan is
when 0 => SG <= ledag1;BT <= "1110";--数码管1,个位。
when 1 => SG <= ledag2;BT <= "1101";--数码管2,十位。
when 2 => SG <= ledag3;BT <= "1011";--数码管3,百位。
when 3 => SG <= ledag4;BT <= "0111";--数码管4,千位。
when others => Null;
end case;
end process Module_SG;
--暂停模块
process
begin
--wait until(pause='1');--定义一个无敏感表的进程,使用WAIT语句,直到pause='1',结束挂起。
WAIT UNTIL PAUSE'EVENT AND PAUSE='1';--pause处于上升沿才结束挂起。
end process;
end behave;
实验设备
以及管脚分配。