Вы находитесь на странице: 1из 8

Instituto Politcnico Nacional

UPIIZ

Ing. Mecatrnica

Dispositivos Lgicos Programables

Reporte de Practica #6

Jaime de Jess Vzquez Arvilla.

09/03/2015
1. Objetivo

El objetivo de la siguiente prctica es comprender el funcionamiento del


puerto PS/2, para teclado usando la tarjeta de desarrollo Basys2.

2. Desarrollo
a) Estudiar el protocolo de comunicacin con el puerto PS2. En concreto
estudiar su implementacin para un teclado PS2.
b) Conectar un teclado PS2 a la basys 2.
c) Realizar un programa en el que al pulsar una tecla nos proporcione su
Scancode (que aparecen en la siguiente figura) por el display de 7
segmentos.
Un teclado o ratn del tipo AT-PS/2 utiliza parta comunicarse un
protocolo bidireccional serie sncrono de 11 bits. Usa dos lneas a
colector abierto con resistencias de pullup TTL +5V (por defecto a uno)
1. CLK para transmitir el reloj de sincronizacin. El reloj siempre debe ser
generado por el dispositivo con una frecuencia entre 10 y 16,7KHz
(aunque puede ser forzado a 0 por el sistema.
2. DATA para transmitir los datos serie. Los datos pueden ser generados
por el dispositivo o por el sistema, y su formato es: 1bit de star(0), 8
bits de datos (primero el lsb), 1 bit deparidad impar, 1 bit de stop(1).
La lnea de datos, como se ha comentado anteriormente, se mantiene a
1 cuando est inactivo, es decir, no hay transmisin.
El bit de paridad impar estar a 1 cuando haya un nmero par de unos
en los 8 bits de datos, de manera que los ocho bits de datos ms el de
paridad deber ser siempre un nmero impar de unos, de esta manera
se pueden detectar algunos errores.
El teclado comienza una transmisin realizando el siguiente protocolo:
1. Comprobar que la lnea de datos y el reloj est a 1
2. Coloca en la lnea de datos el bit start (0), de esta manera se indica
que se va a comenzar.
3. A los 5-25us el teclado pone la lnea del reloj a 0
4. A continuacin coloca los bits de datos, de paridad y de fin, indicando
con el flanco de bajada del reloj cuando se deben leer.

5. Para enviar una nueva trama, despus del bit de fin de la trama
anterior, se inicia el protocolo de nuevo.

Imagen 1.0: Transmisin de datos.

Imagen 1.1: Pines de conexion.

A continuacin se muestra su archivo ucf:

NET "clk" LOC = "T9" ; #Main clock 50 MHz

NET "reset" LOC ="L14";


NET "clk_t" LOC = "M16" ;
NET "dat_t" LOC = "M15" ;
NET "clk_t" CLOCK_DEDICATED_ROUTE = FALSE;
NET
NET
NET
NET
NET
NET
NET

"led<6>"
"led<5>"
"led<4>"
"led<3>"
"led<2>"
"led<1>"
"led<0>"

LOC
LOC
LOC
LOC
LOC
LOC
LOC

=
=
=
=
=
=
=

"L14";
"H12";
"N14";
"N11";
"P12";
"L13";
"M12";

NET
NET
NET
NET

"an<0>"
"an<1>"
"an<2>"
"an<3>"

LOC
LOC
LOC
LOC

=
=
=
=

"F12";
"J12";
"M13";
"K14";

Esta implementacin se hizo instanciando componentes que fue


un divisor de frecuencia, una lectura de datos de teclado, y un
decodificador a continuacin se muestran:

Lectura de datos del teclado:


library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all;
entity lectura is
Port ( kbclk : in STD_LOGIC;--relog del teclado
reset : in STD_LOGIC;--reset
kbdat : in STD_LOGIC;--dato del teclado
dato : out STD_LOGIC_VECTOR (7 downto 0));--dato de salida
end lectura;
architecture Behavioral of lectura is
signal bit_inicio: std_logic;--condicion de captura
signal cont0: std_logic_vector(3 downto 0);--contador 1
signal dato0: std_logic_vector(10 downto 0);--guarda el dato temporalmente
signal z: STD_LOGIC_VECTOR(3 downto 0);--contador 2
begin
--Contador
process (kbclk)
begin
if reset='1' then
cont0 <= (others => '0');

elsif kbclk='0' and kbclk'event then


cont0<=cont0+1;
if cont0 = 13 then
cont0 <= (others => '0');
end if;
end if;
end process;
--empezar deteccion------------------------------------process (kbclk,reset,cont0)
begin
if reset='1' then
dato0 <="00000000000";
bit_inicio <= '0';
elsif kbclk'event and kbclk='0' and cont0 > 0 then
bit_inicio <= '1';
end if;
end process;
--capturando datos--------------------------------------process (kbclk,cont0,bit_inicio)
begin
if reset ='1' then
dato0 <="00000000000";
z <= (others => '0');
elsif kbclk'event and kbclk = '0' and cont0 > 1 and bit_inicio = '1' then
z<=z+1;
if z = 8 then
z<=(others => '0');
end if;
end if;
end process;
process (z,kbdat)
begin
if z = 0 then
dato0 <="00000000000";
elsif z = 1 then
dato0(10) <=kbdat;
elsif z = 2 then
dato0(9) <=kbdat;
elsif z = 3 then
dato0(8) <=kbdat;
elsif z = 4 then
dato0(7) <=kbdat;
elsif z = 5 then
dato0(6) <=kbdat;
elsif z = 6 then
dato0(5) <=kbdat;
elsif z = 7 then
dato0(4) <=kbdat;
elsif z = 8 then
dato0(3) <=kbdat;
end if;
end process;
dato<=dato0(10 downto 3);
end Behavioral;

Decodificador:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity decod_7 is
Port ( key_e : in STD_LOGIC_VECTOR (3 downto 0);
segmentos_s : out STD_LOGIC_VECTOR (6 downto 0));
end decod_7;
architecture Behavioral of decod_7 is
signal nibble0 : std_logic_vector (3 downto 0);
begin
nibble0 <= key_e(3 downto 0);
with nibble0 select
segmentos_s <= "1000000" when "0000", --0
"1111001" when "0001", --1
"0100100" when "0010", --2
"0110000" when "0011", --3
"0011001" when "0100", --4
"0010010" when "0101", --5
"0000011" when "0110", --6
"1111000" when "0111", --7
"0000000" when "1000", --8
"0011000" when "1001", --9
"0001000" when "1010", --A
"0000011" when "1011", --b
"0100111" when "1100", --C
"0100001" when "1101", --d
"0000110" when "1110", --E
"0111111" when others; -- display RAYA CENTRAL
end Behavioral;

Divisor de frecuencia:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity CLK_CONT is
port (CLK : in STD_LOGIC; -- Reloj de entrada a la FPGA
CLK_CONTROL : out STD_LOGIC);
end CLK_CONT;
architecture CLK_CONT of CLK_CONT is
signal contador : STD_LOGIC_VECTOR (31 downto 0);
signal flag : STD_LOGIC;
begin
PROC_CONT : process (CLK)
begin
if CLK'event and CLK='1' then
contador<=contador + '1';
if contador=50000 then
flag<=not flag;
contador<=(others=>'0');
end if;
end if;
end process;
CLK_CONTROL <=flag;
end CLK_CONT;

Programa principal:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pro_a is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
clk_t : in STD_LOGIC;
dat_t : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0));
end pro_a;
architecture Behavioral of pro_a is
----------------------------------------------component CLK_CONT is
port (CLK : in STD_LOGIC;
CLK_CONTROL : out STD_LOGIC);
end component;
----------------------------------------------component decod_7 is
Port ( key_e : in STD_LOGIC_VECTOR (3 downto 0);
segmentos_s : out STD_LOGIC_VECTOR (6 downto 0));
end component;
--------------------------------------------------------------------------------------------component lectura is
Port ( kbclk : in STD_LOGIC;--relog del teclado
reset : in STD_LOGIC;--reset
kbdat : in STD_LOGIC;--dato del teclado
dato : out STD_LOGIC_VECTOR (7 downto 0));
end component;
----------------------------------------------signal CLK_CONTROLO: STD_LOGIC;
signal SAL0: STD_LOGIC_VECTOR (7 downto 0);
signal LED1: STD_LOGIC_VECTOR (6 downto 0);
signal LED0: STD_LOGIC_VECTOR (6 downto 0);
signal C : STD_LOGIC_VECTOR(1 downto 0);
----------------------------------------------begin
U01 : CLK_CONT
port map (
CLK => CLK_T,
CLK_CONTROL=> CLK_CONTROLO --RELOG PARA EL CONTROL
);
U02 : lectura
port map (
kbclk => clk_t,
reset => reset,
kbdat => dat_t,
dato => SAL0
);
U04 : decod_7
port map (
key_e => SAL0(7 downto 4),
segmentos_s=> LED1
);
U05 : decod_7
port map (

--SALIDA1

key_e => SAL0(3 downto 0),


segmentos_s=> LED0
);

--SALIDA0

process(CLK_CONTROLO,C,LED0,LED1)
begin
if CLK_CONTROLO'event and CLK_CONTROLO='1' then
C <= C + 1;
end if;
case C is
when "00" =>
an <= "1110";
led <= LED0;
when "01" =>
an <= "1101";
led <= LED1;
when "10" =>
an <= "1011";
led <= "0000001";
when "11" =>
an <= "0111";
led <= "0000001";
when others => an <= "1111";
led <= "0000000";
end case;
end process;
end Behavioral;

3. Conclusiones
En esta prctica se comprendi el funcionamiento del puerto
ps2, de la tarjeta de desarrollo basys2, usando el teclado. El
protocolo de comunicacin mencionado anteriormente.

Вам также может понравиться