------------------------------------------------- -- BLOC PER A LA COMUNICACIÓ SERIE RS232 -- -- -- -- REALITZAT PER LLUIS MAGI -- ------------------------------------------------- ------------------------------------------------------------------------------ -- EL SENYAL clk_serie HA DE SER IGUAL A LA VELOCITAT DE COMUNICACIÓ -- -- UN POLS POSITIU AL SENYAL enviar PROVOCA L'INICI DE LA TRANSMISSIÓ -- -- EL SENYAL data_rebuda REALITZA UN POLS POSITIU QUAN S'HA REBUT UNA DADA -- ------------------------------------------------------------------------------ LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; ENTITY cserie2 IS PORT( clk12 : in std_logic; -- clock de 12 MHz data_serie_in : in std_logic; -- dades serie d'entrada data_in : in std_logic_vector(7 downto 0); -- dades per extreure pel port serie enviar : in std_logic; -- pols per començar a enviar data_serie_out : out std_logic; -- dades serie de sortida data_out : out std_logic_vector(7 downto 0); -- dades rebudes del port serie dada_rebuda : out std_logic; -- pols que indica dada rebuda dada_enviada : out std_logic -- pols per indicar que la dada ha estat enviada ); -- 12 MHz 8MHz constant M_PERIODE : integer := 625; --625 417 constant PERIODE : integer := 1250; --1250 834 constant TEMPS : integer := 900; END cserie2; ARCHITECTURE arq_cserie OF cserie2 IS signal estat : integer range 0 to 11; signal estat_out : integer range 0 to 11; signal dades : std_logic_vector(7 downto 0); signal dada_in : std_logic_vector(7 downto 0); signal activar_out : std_logic; signal activar_in : std_logic; signal inici : std_logic; signal fi : std_logic; signal fi_env : std_logic; signal conta : integer range 0 to TEMPS+10; signal contador : integer range 0 to PERIODE; signal contadore : integer range 0 to PERIODE; signal clk : std_logic; signal clke : std_logic; BEGIN process(clk12) -- detecció del bit d'start begin if rising_edge(clk12) then if data_serie_in='0' and estat=0 then inici<='1'; elsif fi='1' then inici<='0'; end if; end if; end process; process(clk12) -- generació del clock de comunicació sincronitzat begin if rising_edge(clk12) then if inici='1' then if contador< M_PERIODE then contador<=contador+1; clk<='0'; elsif contador fi <= '0'; if data_serie_in='0' and activar_in='0' then estat <= 1; activar_in<='1'; else estat <= 0; end if; when 1 => fi <= '0'; dades(0)<=data_serie_in; estat<=2; when 2 => fi <= '0'; dades(1)<=data_serie_in; estat<=3; when 3 => fi <= '0'; dades(2)<=data_serie_in; estat<=4; when 4 => fi <= '0'; dades(3)<=data_serie_in; estat<=5; when 5 => fi <= '0'; dades(4)<=data_serie_in; estat<=6; when 6 => fi <= '0'; dades(5)<=data_serie_in; estat<=7; when 7 => fi <= '0'; dades(6)<=data_serie_in; estat<=8; when 8 => fi <= '0'; dades(7)<=data_serie_in; estat<=9; when 9 => fi <= '0'; estat<=10; when 10 => estat<=0; activar_in<='0'; fi<='1'; when others => null; end case; end if; end process; process(clk12) begin if rising_edge(clk12) then if estat=9 then data_out<=dades; elsif estat=10 then dada_rebuda<='1'; else dada_rebuda<='0'; end if; end if; end process; process(clk12) -- generació del clock de comunicació no sincronitzat begin if rising_edge(clk12) then if contadore< M_PERIODE then contadore<=contadore+1; clke<='0'; elsif contadore data_serie_out<='0'; -- bit START estat_out <= 1; when 1 => data_serie_out<=dada_in(0); estat_out<=2; when 2 => data_serie_out<=dada_in(1); estat_out<=3; when 3 => data_serie_out<=dada_in(2); estat_out<=4; when 4 => data_serie_out<=dada_in(3); estat_out<=5; when 5 => data_serie_out<=dada_in(4); estat_out<=6; when 6 => data_serie_out<=dada_in(5); estat_out<=7; when 7 => data_serie_out<=dada_in(6); estat_out<=8; when 8 => data_serie_out<=dada_in(7); estat_out<=9; when 9 => estat_out <= 10; data_serie_out<= '1'; -- bit STOP when 10 => estat_out <= 11; when others => estat_out <= 0; end case; else data_serie_out<='1'; estat_out <= 0; end if; end if; end process; process(clk12) -- pols de la dada enviada begin if rising_edge(clk12) then if fi_env='1' then if conta