📄
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity occur is
port (
line: in STD_LOGIC_VECTOR (3 downto 0);
row: buffer STD_LOGIC_VECTOR (3 downto 0);
bcdout: out std_logic_vector ( 6 downto 0);
dec3to8: out std_logic_vector ( 7 downto 0);
clk: in STD_LOGIC;
r: in STD_LOGIC
);
end occur;
architecture occur_arch of occur is
signal dd:STD_LOGIC_VECTOR (1 downto 0);
signal dd1:STD_LOGIC_VECTOR (1 downto 0);
signal dcout3:STD_LOGIC_VECTOR (2 downto 0);
signal bcd:STD_LOGIC_VECTOR (3 downto 0);
signal line1:STD_LOGIC_VECTOR (1 downto 0);
signal cc:STD_LOGIC_VECTOR (3 downto 0);
signal cd1:STD_LOGIC_VECTOR (7 downto 0);
signal cd2:STD_LOGIC_VECTOR (7 downto 0);
signal cd3:STD_LOGIC_VECTOR (7 downto 0);
signal cd4:STD_LOGIC_VECTOR (7 downto 0);
signal cd:STD_LOGIC_VECTOR (7 downto 0);
signal keydown:std_logic;
signal cout1:STD_LOGIC_VECTOR (3 downto 0);
signal cout2:STD_LOGIC_VECTOR (3 downto 0);
signal cout3:STD_LOGIC_VECTOR (3 downto 0);
signal cout4:STD_LOGIC_VECTOR (3 downto 0);
signal cout5:STD_LOGIC_VECTOR (3 downto 0);
begin
count: process (r, clk )
begin
if ( r='1' ) then dd<="00";
elsif( clk'event and clk = '1') then
dd <= dd + '1';
end if ;
end process count ;
with dd select
row<="0111"when"00",
"1011"when"01",
"1101"when"10",
"1110"when"11",
"ZZZZ"when others ;
with row select
dd1<= "00"when"0111",
"01"when"1011",
"10"when"1101",
"11"when"1110",
"ZZ"when others ;
keydown<= line(0) and line(1) and line(2) and line(3) ;
with line select
line1<="00"when"0111",
"01"when"1011",
"10"when"1101",
"11"when"1110",
"ZZ"when others ;
process ( keydown,clk,r )
begin
if ( r='1' ) then cc<="0000";
elsif( clk'event and clk = '1') then
if (keydown = '0') then
cc <= dd1&line1 ;
end if;
end if;
end process ;
process (cc)
variable tmp: STD_LOGIC_VECTOR (7 downto 0);
begin
tmp:="00000000";
if (cc(3)='1') then
tmp:=tmp+cc;
end if;
tmp:=tmp(6 downto 0) & '0';
if (cc(2)='1') then
tmp:=tmp+cc;
end if;
tmp:=tmp(6 downto 0) & '0';
if (cc(1)='1') then
tmp:=tmp+cc;
end if;
tmp:=tmp(6 downto 0) & '0';
if (cc(0)='1') then
tmp:=tmp+cc;
end if;
cd<=tmp;
end process;
--------------------- 4 bin => 2 BCD ------------------
process (cc)
begin
if (cc>9) then
cout1<="0001";
cout2<=cc+6;
else
cout1<="1111";
cout2<=cc;
end if;
end process;
--------------------- 8 bin => 3 BCD ------------------
process (cd)
begin
if (cd=0) then
cout3<="1111";
cout4<="1111";
cout5<="0000";
elsif (cd=1) then
cout3<="1111";
cout4<="1111";
cout5<="0001";
elsif (cd=4) then
cout3<="1111";
cout4<="1111";
cout5<="0100";
elsif (cd=9) then
cout3<="1111";
cout4<="1111";
cout5<="1001";
elsif (cd=16) then
cout3<="1111";
cout4<="0001";
cout5<="0110";
elsif (cd=25) then
cout3<="1111";
cout4<="0010";
cout5<="0101";
elsif (cd=36) then
cout3<="1111";
cout4<="0011";
cout5<="0110";
elsif (cd=49) then
cout3<="1111";
cout4<="0100";
cout5<="1001";
elsif (cd=64) then
cout3<="1111";
cout4<="0110";
cout5<="0100";
elsif (cd=81) then
cout3<="1111";
cout4<="1000";
cout5<="0001";
elsif (cd=100) then
cout3<="0001";
cout4<="0000";
cout5<="0000";
elsif (cd=121) then
cout3<="0001";
cout4<="0010";
cout5<="0001";
elsif (cd=144) then
cout3<="0001";
cout4<="0100";
cout5<="0100";
elsif (cd=169) then
cout3<="0001";
cout4<="0110";
cout5<="1001";
elsif (cd=196) then
cout3<="0001";
cout4<="1001";
cout5<="0110";
elsif (cd=225) then
cout3<="0010";
cout4<="0010";
cout5<="0101";
else
cout3<="1111";
cout4<="1111";
cout5<="1111";
end if;
end process;
count1: process (r, clk )
begin
if ( r='1' ) then dcout3<="000";
elsif( clk'event and clk = '1') then
dcout3 <= dcout3 + '1';
end if ;
end process count1 ;
with dcout3 select
bcd<=cout1 when"000",
cout2 when"001",
cout3 when"101",
cout4 when"110",
cout5 when"111",
"1111"when others ;
with bcd select
bcdout<="1111110"when "0000",
"0110000"when "0001",
"1101101"when "0010",
"1111001"when "0011",
"0110011"when "0100",
"1011011"when "0101",
"1011111"when "0110",
"1110000"when "0111",
"1111111"when "1000",
"1111011"when "1001",
"0000000"when others ;
with dcout3 select
dec3to8<="10000000" when "000",
"01000000" when "001",
"00100000" when "010",
"00010000" when "011",
"00001000" when "100",
"00000100" when "101",
"00000010" when "110",
"00000001" when "111",
"00000000" when others;
end occur_arch;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -