library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
ENTITY yyh IS
PORT (reset : in std_logic;
clk : IN std_logic;
speaker : OUT std_logic );
END yyh;
ARCHITECTURE one OF yyh IS
signal clk_6Mhz,clk_4hz,clk10k : std_logic;
SIGNAL divider : std_logic_vector(13 DOWNTO 0);
SIGNAL origin : std_logic_vector(13 DOWNTO 0);
SIGNAL counter : std_logic_vector(7 DOWNTO 0);
SIGNAL carry : std_logic;
SIGNAL speaker_xhdl1 : std_logic;
SIGNAL yindiao : std_logic_vector(8 DOWNTO 0);
BEGIN
speaker <= speaker_xhdl1 when reset='1' else '0';
carry <='1' when divider="11111111111111" else '0' ;
process(clk)
variable cnt1: integer range 0 to 8;
variable cnt2: integer range 0 to 5000;
begin
if clk'event and clk='1' then
if cnt1=8 then
cnt1:=0;
else
cnt1:=cnt1+1;
end if;
if cnt1<4 then
clk_6mhz<='1';
else
clk_6mhz<='0';
end if;
if cnt2=5000 then
cnt2:=0;
else
cnt2:=cnt2+1;
end if;
if cnt2<2500 then
clk10k<='1';
else
clk10k<='0';
end if;
end if;
end process;
process(clk10k)
variable cnt1: integer range 0 to 2500;
begin
if clk10k'event and clk10k='1' then
if cnt1=2500 then
cnt1:=0;
else
cnt1:=cnt1+1;
end if;
if cnt1<1250 then
clk_4hz<='1';
else
clk_4hz<='0';
end if;
end if;
end process;
PROCESS
BEGIN
WAIT UNTIL (clk_6MHz'EVENT AND clk_6MHz = '1');
IF (carry = '1') THEN
divider <= origin;
ELSE
divider <= divider + 1;
END IF;
END PROCESS;
PROCESS
BEGIN
WAIT UNTIL (carry'EVENT AND carry = '1');
speaker_xhdl1 <= NOT speaker_xhdl1;
END PROCESS;
PROCESS
BEGIN
WAIT UNTIL (clk_4Hz'EVENT AND clk_4Hz = '1');
CASE yindiao IS
WHEN "000000001"=>
origin <= "01001100110100"; --d1
WHEN "000000010" =>
origin <= "01100000010111"; --d2
WHEN "000000011" =>
origin <= "01110001110001"; --d3
WHEN "000000100" =>
origin <= "01111001110000"; --d4
WHEN "000000101" =>
origin <= "10001000011010"; --d5
WHEN "000000110" =>
origin <= "10010101011101"; --d6
WHEN "000000111" =>
origin <= "10100001000101"; --d7
WHEN "000001000" =>
origin <= "10100110011010"; --z1
WHEN "000010000"=>
origin <= "10110000001011"; --z2
WHEN "000011000" =>
origin <= "10111000111000"; --z3
WHEN "000100000" =>
origin <= "10111100111000"; --z4
WHEN "000101000" =>
origin <= "11000100001100"; --z5
WHEN "000110000" =>
origin <= "11001010010011"; --z6
WHEN "000111000" =>
origin <= "11010000100010"; --z7
WHEN "001000000" =>
origin <= "11010011001100"; --g1
WHEN "010000000" =>
origin <= "11011000000101"; --g2
WHEN "011000000" =>
origin <= "11011100011100"; --g3
WHEN "100000000" =>
origin <= "11011110011011"; --g4
WHEN "101000000" =>
origin <= "11100010000110"; --g5
WHEN "110000000" =>
origin <= "11100101010110"; --g6
WHEN "111000000" =>
origin <= "11101000010001"; --g7
WHEN "000000000" =>
origin <= "11111111111111"; --blank
WHEN OTHERS =>
NULL;
END CASE;
END PROCESS;
PROCESS
BEGIN
WAIT UNTIL (clk_4Hz'EVENT AND clk_4Hz = '1');
IF (counter = "00111111") THEN
counter <= "00000000";
ELSE
counter <= counter + "00000001";
END IF;
CASE counter IS
WHEN "00000000" =>
yindiao <= "000011000";
WHEN "00000001" =>
yindiao <= "000011000";
WHEN "00000010" =>
yindiao <= "000101000";
WHEN "00000011" =>
yindiao <= "000110000";
WHEN "00000100" =>
yindiao <= "000011000";
WHEN "00000101" =>
yindiao <= "000011000";
WHEN "00000110" =>
yindiao <= "000001000";
WHEN "00000111" =>
yindiao <= "000010000";
WHEN "00001000" =>
yindiao <= "000001000";
WHEN "00001001" =>
yindiao <="000010000";
WHEN "00001010" =>
yindiao <= "000101000";
WHEN "00001011" =>
yindiao <= "000011000";
WHEN "00001100" =>
yindiao <= "000011000";
WHEN "00001101" =>
yindiao <= "000010000";
WHEN "00001110" =>
yindiao<= "000010000";
WHEN "00001111" =>
yindiao<= "000010000";
WHEN "00010000" =>
yindiao <= "000010000";
WHEN "00010001" =>
yindiao<= "000011000";
WHEN "00010010" =>
yindiao <= "000010000";
WHEN "00010011" =>
yindiao <= "000000110";
WHEN "00010100" =>
yindiao <= "000000101";
WHEN "00010101" =>
yindiao <= "000001000";
WHEN "00010110" =>
yindiao <= "000001000";
WHEN "00010111" =>
yindiao <= "000010000";
WHEN "00011000" =>
yindiao<= "000011000";
WHEN "00011001" =>
yindiao <= "000010000";
WHEN "00011010" =>
yindiao<= "000011000";
WHEN "00011011" =>
yindiao<= "000011000";
WHEN "00011100" =>
yindiao <= "000010000";
WHEN "00011101" =>
yindiao <= "000010000";
WHEN "00011110" =>
yindiao <= "000011000";
WHEN "00011111" =>
yindiao <= "000011000";
WHEN "00100000" =>
yindiao <= "000101000";
WHEN "00100001" =>
yindiao <= "000110000";
WHEN "00100010" =>
yindiao <= "000011000";
WHEN "00100011" =>
yindiao <= "000011000";
WHEN "00100100" =>
yindiao <= "000001000";
WHEN "00100101" =>
yindiao <= "000010000";
WHEN "00100110" =>
yindiao <= "000001000";
WHEN "00100111" =>
yindiao <="000010000";
WHEN "00101000" =>
yindiao <= "000101000";
WHEN "00101001" =>
yindiao <= "000011000";
WHEN "00101010" =>
yindiao <= "000011000";
WHEN "00101011" =>
yindiao <= "000010000";
WHEN "00101100" =>
yindiao<= "000010000";
WHEN "00101101" =>
yindiao<= "000010000";
WHEN "0010111