---------------------------------------------------------------------------- -- horloge fonctionnement clock_fpga=50MHz ---------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity emission_RS232 is port( clock_fpga : in std_logic; envoie_enable :in std_logic; TX : out std_logic; data_envoie : in std_logic_vector(7 downto 0)); end entity emission_RS232; architecture Behavioral of emission_RS232 is ------------------------------------------------------------------------ -- SIGNALS ------------------------------------------------------------------------ signal horloge_envoie : std_logic :='0'; signal mot_complet : std_logic_vector(9 downto 0) :="0000000000"; signal compteur: std_logic_vector(3 downto 0):="0000"; signal compteur_baud: integer:=0; signal horloge_enable : std_logic :='0'; signal data_bis : std_logic_vector(7 downto 0) :="00000000"; begin ---------------------------------------------------------------------------- --reoganisation de la data a envoyer; bit poid faible en premier------------ data_bis(0)<= data_envoie(7); data_bis(1)<= data_envoie(6); data_bis(2)<= data_envoie(5); data_bis(3)<= data_envoie(4); data_bis(4)<= data_envoie(3); data_bis(5)<= data_envoie(2); data_bis(6)<= data_envoie(1); data_bis(7)<= data_envoie(0); ---------------------------------------------------------------------------- definition_horloge_enable: process (envoie_enable,compteur) --mise à 1 lorsque l'on veut envoyer le mot-- --repasse à 0 à la fin de l'envoie-- begin if compteur = "0000" then if (envoie_enable'event and envoie_enable='1') then horloge_enable<='1'; end if; else if compteur="1010" then horloge_enable<='0'; end if; end if; end process definition_horloge_enable; --------------------------------------------------------------------------- --envoie mot complet: ajout des bits start et stop+ envoie du mot en serie -- avec registre à decalage---------------------------------------------- mot_entier_envoi: process (horloge_envoie,compteur) begin if (horloge_envoie'event and horloge_envoie='1') then compteur<=compteur+1; mot_complet <= mot_complet(8 downto 0) & '1'; end if; if compteur ="1010" then compteur<="0000"; elsif compteur ="0000" then mot_complet<= '0' & data_bis & '1'; else TX <= mot_complet(9); end if; end process mot_entier_envoi; ----------------------------------------------------------------------------- --horloge permettant le fonctionnement du registre à decalage--------------- --------------------------------------------------------------------------- generation_horloge_envoie: process(clock_fpga) begin if clock_fpga'event and clock_fpga='1' then if horloge_enable ='1' then compteur_baud<=compteur_baud+1; if (compteur_baud =5208 ) then horloge_envoie<='1'; compteur_baud<=0; else horloge_envoie<='0'; end if; else horloge_envoie<='0'; end if; end if; end process generation_horloge_envoie; ----------------------------------------------------------------------------- end behavioral;