⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse_pos.v

📁 本实验利用PS/2接口实现了与鼠标通信
💻 V
字号:
//-----------------------------------------------------------------------------
//
// Author: John Clayton
// Date  : April 30, 2001
// Update: April 30, 2001 Copied this file from "lcd_3.v" for use as top level
// Update: May    3, 2001 Included instantiations of VHDL code, to test mixed
//                        language support of the XILINX foundation 3.1 tools.
// Update: June   1, 2001 Brigham Young's 200th birthday!
//                        Started project "build_4" using ps2 interface and
//                        the rs232 interface code.
// Update: June   5, 2001 Finished debugging the keyboard ps2 interface.
//                        Removed debug outputs from keyboard interface.
// Update: June   7, 2001 Added the new ps2_mouse_interface module. ("build_5")
//
// Description
//-----------------------------------------------------------------------------
// This targets an XC2S200 board which was created for educational purposes.
//-----------------------------------------------------------------------------


`resetall
`timescale 1ns/100ps

module mouse_pos(
  clk,
  rst_n,
  ps2_clk,
  ps2_data,
  mouse_left,
  mouse_right,
  mouse_ack,
  x_increment,
  y_increment,
  x_pos,
  y_pos
  );
  
// I/O declarations
input  clk;      // 50 MHz
input  rst_n;
inout  ps2_clk;
inout  ps2_data;
output mouse_left;
output mouse_right;
output mouse_ack;
output [8:0] x_increment;
output [8:0] y_increment;

output reg [9:0] x_pos;
output reg [9:0] y_pos;


//--------------------------------------------------------------------------
// Instantiations
//--------------------------------------------------------------------------


ps2_mouse_interface #(20000, // Watchdog timer at 400usec
                      15,    // Bits for the watchdog timer
                      186,   // Debounce timer value
                      8      // Bits for the debounce timer
                      )
  mouse1_block (             // instance name
  .clk(clk),
  .reset((!rst_n)||(mouse_ack)),
  .ps2_clk(ps2_clk),
  .ps2_data(ps2_data),
  .left_button(mouse_left),
  .right_button(mouse_right),
  .x_increment(x_increment),
  .y_increment(y_increment),
  .data_ready(mouse1_data_ready),   // rx_read_o
  .read(mouse1_data_ready),         // rx_read_ack_i
  .error_no_ack(mouse_ack)
  );
  
always @(posedge clk)
  if (!rst_n) 
    begin
      x_pos <= 10'd80;
      y_pos <= 10'd80;
    end
  else if (mouse1_data_ready)
    begin
      x_pos <= x_pos + {{2{x_increment[8]}},x_increment[7:0]};
      y_pos <= y_pos - {{2{y_increment[8]}},y_increment[7:0]};
    end
  
endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -