Skip to content

Instantly share code, notes, and snippets.

@PixelWeaver
Created April 30, 2017 08:38
Show Gist options
  • Save PixelWeaver/d34915964428f3aa749933a5553db43f to your computer and use it in GitHub Desktop.
Save PixelWeaver/d34915964428f3aa749933a5553db43f to your computer and use it in GitHub Desktop.
Sauvez Les Morses
library IEEE;
use IEEE.std_logic_1164.all;
entity morse is
port
(
-- Input ports
clk : in std_logic;
message : in std_logic;
ss : in std_logic;
-- Output ports
seg14 : out std_logic_vector (13 downto 0);
lenghtLED : out std_logic
);
end entity morse;
architecture morse_arch of morse is
signal morse : std_logic_vector (3 downto 0);
signal count : integer range 0 to 4 := '0';
signal clk_cnt : integer range 0 to 50 := '0';
begin
-- Relever les différentes entrées Morse
encode : process(clk, message)
begin
while (message = '1')
loop
if (rising_edge(clk)) then
clk_cnt <= clk_cnt + 1;
end if;
-- Informer l'utilisateur de la longueur de sa bite
if (clk_cnt < "25") then
lengthLED <= '0';
else
lengthLED <= '1';
end if;
end loop;
if (falling_edge(message)) then
if (clk_cnt <= "25") then
morse(count) <= '0';
else
morse(count) <= '1';
end if;
count <= count + 1;
end if;
end process encode;
-- Transformer le message en lettre
translate : process(ss,count)
begin
if(rising_edge(ss)) then
if(count=1) then
case morse(0) is
when "0"=> seg14 <= "11000010100001";--E
when "1"=> seg14 <= "10010000001000";--T
end case;
elsif(count=2) then
case morse(1 downto 0) is
when "01" => seg14 <= "11000111100010";--A
when "10" => seg14 <= "01100100100110";--N
when "11" => seg14 <= "01101100100010";--M
when "00" => seg14 <= "00010000001000";--I
end case;
elsif(count=3) then
case morse(2 downto 0) is
when "000" => seg14 <="11000011000011";--S
when "001" => seg14 <="01000100100011";--U
when "010" => seg14 <="11000111100100";--R
when "011" => seg14 <="01000100110110";--W
when "100" => seg14 <="10010100001011";--D
when "101" => seg14 <="01001010100100";--K
when "110" => seg14 <="11000001100011";--G
when "111" => seg14 <="11000100100010";--O
end case;
else if(count=4) then
case morse is
when "0000" => seg14 <="01000111100010";--H
when "0001" => seg14 <="01001000110000";--V
when "0010" => seg14 <="11000010100000";--F
--when "0011" => seg14 <=""
when "0100" => seg14 <="01000000100001";--L
--when "0101" => seg14 <=""
when "0110" => seg14 <="11000111100000";--P
when "0111" => seg14 <="00000100100011";--J
when "1000" => seg14 <="10010101001011";--B
when "1001" => seg14 <="00101000010100";--X
when "1010" => seg14 <="11000000100001";--C
when "1011" => seg14 <="00101000001000";--Y
when "1100" => seg14 <="10001000010001";--Z
when "1101" => seg14 <="11000100100111";--Q
--when "1110" => seg14 <=""
--when "1111" => seg14 <=""
end case;
else
seg14 <= "00000011000000";
end if ;
end if ;
end process translate ;
end architecture morse_arch ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment