Project:
Interface a mouse with FPGA:
Design Obstacles and Reservations:
VHDL Code:
library IEEE;use IEEE.std_logic_1164.all;entity mouse is port (mouse_clk : in std_logic_vector; reset : in std_logic_vector; --reset all to zero; status : in std_logic_vector; --status active/idle mouse_data : in std_logic_vector (1 downto 0);--left or right is clicked speed : in std_logic_vector (3 downto 0); displayed_number: out std_logic_vector(6 downto 0);--7 segments anode : out std_logic_vector (3 downto 0);)--4 digitsend mouse;architecture mouse_arc of mouse is dig : std_logic_vector (1 downto 0);--led activation mouse_bits : std_logic_vector (5 downto 0);--number of bits received signal displayed_number: std_logic_vector(15 downto 0); signal led_bcd : std_logic_vector(4 downto 0); //32 bit signal received from the mouse if(rising_edge(mouse_clk)||rising_edge(reset)) then if(reset==1) // resetting the mouse bits and displayed number mouse_bits <= 0; else if(mouse_bits<=31) //if the bits received from mouse is smaller than 31 bit mouse_bits <= mouse_bits+1; else mouse_bits <= 0; end//Displayed number increment/decrement when the right or left button of the mouse is clicked if(falling_edge(mouse_clk)||rising_edge(reset)) then if(reset==1) displayed_number <=0; else begin if(status ==1) then//mouse is active if(mouse_data == "01") then//right button is pressed displayed_number <= displayed_number + 1; end else if(mouse_data == "10"&&displayed_number>0) then//left button is pressed displayed_number <= displayed_number -1; end else if(mouse_data =="11" || mouse_data =="00") then//inactive or both buttons displayed_number <= displayed_number; end end end//converting the displayed_number to numeric number to be displayed on the 4-digit displayer begin case(dig) 2'b00: begin anode = 4'b0111; led_bcd = displayed_number/1000; end 2'b01: begin anode = 4'b1011 led_bcd = displayed_number%1000/100; end 2'b10: begin anode = 4'b1101 led_bcd = displayed_number%1000%100/10; end 2'b11: begin anode = 4'b1110 led_bcd = displayed_number%1000%100%10; end endcase end begin case(led_bcd) 4'b0000: displayed_number = 7'b0000001; --"0" 4'b0001: displayed_number = 7'b1001111; --"1" 4'b0010: displayed_number = 7'b0010010; --"2" 4'b0011: displayed_number = 7'b0000110; --"3" 4'b0100: displayed_number = 7'b1001100; --"4" 4'b0101: displayed_number = 7'b0100100; --"5" 4'b0110: displayed_number = 7'b0100000; --"6" 4'b0111: displayed_number = 7'b0001111; --"7" 4'b1000: displayed_number = 7'b0000000; --"8" 4'b1001: displayed_number = 7'b0001000; --"9" default: displayed_number = 7'b1111111; endcase endend Pin Constraint File:
##Switchesset_property -dict { PACKAGE_PIN J15 IOSTANDARD LVCMOS33 } [get_ports { mouse_clk }]; IO_L24N_T3_RS0_15 Sch=mouse_clkset_property -dict { PACKAGE_PIN L16 IOSTANDARD LVCMOS33 } [get_ports { mouse_data }]; IO_L3N_T0_DQS_EMCCLK_14 Sch=mouse_dataset_property -dict { PACKAGE_PIN M13 IOSTANDARD LVCMOS33 } [get_ports { reset }]; IO_L6N_T0_D08_VREF_14 Sch=resetset_property -dict { PACKAGE_PIN R15 IOSTANDARD LVCMOS33 } [get_ports { status }]; IO_L13N_T2_MRCC_14 Sch=status## LEDsset_property -dict { PACKAGE_PIN H17 IOSTANDARD LVCMOS33 } [get_ports { LED[0] }]; IO_L18P_T2_A24_15 Sch=led[0]set_property -dict { PACKAGE_PIN K15 IOSTANDARD LVCMOS33 } [get_ports { LED[1] }]; IO_L24P_T3_RS1_15 Sch=led[1]set_property -dict { PACKAGE_PIN J13 IOSTANDARD LVCMOS33 } [get_ports { LED[2] }]; IO_L17N_T2_A25_15 Sch=led[2]set_property -dict { PACKAGE_PIN N14 IOSTANDARD LVCMOS33 } [get_ports { LED[3] }]; IO_L8P_T1_D11_14 Sch=led[3]set_property -dict { PACKAGE_PIN R18 IOSTANDARD LVCMOS33 } [get_ports { LED[4] }]; IO_L7P_T1_D09_14 Sch=led[4]set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports { LED[5] }]; IO_L18N_T2_A11_D27_14 Sch=led[5]set_property -dict { PACKAGE_PIN U17 IOSTANDARD LVCMOS33 } [get_ports { LED[6] }]; IO_L17P_T2_A14_D30_14 Sch=led[6]set_property -dict { PACKAGE_PIN H15 IOSTANDARD LVCMOS33 } [get_ports { DP }]; #IO_L19N_T3_A21_VREF_15 Sch=dp#set_property -dict { PACKAGE_PIN J17 IOSTANDARD LVCMOS33 } [get_ports { anode[0] }]; #IO_L23P_T3_FOE_B_15 Sch=anode[0]#set_property -dict { PACKAGE_PIN J18 IOSTANDARD LVCMOS33 } [get_ports { anode[1] }]; #IO_L23N_T3_FWE_B_15 Sch=an[1]#set_property -dict { PACKAGE_PIN T9 IOSTANDARD LVCMOS33 } [get_ports { anode[2] }]; #IO_L24P_T3_A01_D17_14 Sch=an[2]#set_property -dict { PACKAGE_PIN J14 IOSTANDARD LVCMOS33 } [get_ports { anode[3] }]; Conclusion: