主要是用VHDL实现0--9的计数,首先是分频进程,然后是计数0--9直接选择输出段码,程序代码如下:
--时间:2011年6月18日
--文件功能:计数器0-99
--A 1010 B 1011 C 1100 D 1101 E 1110 F 1111
-- 0x3F,/*0*/ 0011 1111
-- 0x06,/*1*/ 0000 0110
-- 0x5B,/*2*/ 0101 1011
-- 0x4F,/*3*/ 0100 1111
-- 0x66,/*4*/ 0110 0110
-- 0x6D,/*5*/ 0110 1101
-- 0x7D,/*6*/ 0111 1101
-- 0x07,/*7*/ 0000 0111
-- 0x7F,/*8*/ 0111 1111
-- 0x6F,/*9*/ 0110 1111
library ieee;
use ieee.std_logic_1164.all;
entity cnt99 is
port(
clk : in std_logic;
outseg : out std_logic_vector(7 downto 0)
);
end cnt99;
architecture one of cnt99 is
signal segclk : std_logic;
begin
process(clk)
variable count0 : integer range 0 to 99999999;
begin
if clk'event and clk='1' then
if count0=99999999 then
count0:=0;
segclk<='1';
else
count0:=count0+1;
segclk<='0';
end if;
end if;
end process;
process(clk)
variable count1 : integer range 0 to 10;
begin
if (segclk'event and segclk='1') then
if count1=10 then
count1:=0;
end if;
case count1 is
when 0=> outseg<="00111111";
when 1=> outseg<="00000110";
when 2=> outseg<="01011011";
when 3=> outseg<="01001111";
when 4=> outseg<="01100110";
when 5=> outseg<="01101101";
when 6=> outseg<="01111101";
when 7=> outseg<="00000111";
when 8=> outseg<="01111111";
when 9=> outseg<="01101111";
when others=> outseg<="11111111";
end case;
count1:=count1+1;
end if;
end process;
end one;
文章评论(0条评论)
登录后参与讨论