`include "ps2_kbd.v" `include "cstringdisp.v" `include "font_rom.v" /////////////////////////////////////////////////////////////////////////////// module ps2_kbd_sample (beep, audio_reset_b, ac97_sdata_out, ac97_sdata_in, ac97_synch, ac97_bit_clock, vga_out_red, vga_out_green, vga_out_blue, vga_out_sync_b, vga_out_blank_b, vga_out_pixel_clock, vga_out_hsync, vga_out_vsync, tv_out_ycrcb, tv_out_reset_b, tv_out_clock, tv_out_i2c_clock, tv_out_i2c_data, tv_out_pal_ntsc, tv_out_hsync_b, tv_out_vsync_b, tv_out_blank_b, tv_out_subcar_reset, tv_in_ycrcb, tv_in_data_valid, tv_in_line_clock1, tv_in_line_clock2, tv_in_aef, tv_in_hff, tv_in_aff, tv_in_i2c_clock, tv_in_i2c_data, tv_in_fifo_read, tv_in_fifo_clock, tv_in_iso, tv_in_reset_b, tv_in_clock, ram0_data, ram0_address, ram0_adv_ld, ram0_clk, ram0_cen_b, ram0_ce_b, ram0_oe_b, ram0_we_b, ram0_bwe_b, ram1_data, ram1_address, ram1_adv_ld, ram1_clk, ram1_cen_b, ram1_ce_b, ram1_oe_b, ram1_we_b, ram1_bwe_b, clock_feedback_out, clock_feedback_in, flash_data, flash_address, flash_ce_b, flash_oe_b, flash_we_b, flash_reset_b, flash_sts, flash_byte_b, rs232_txd, rs232_rxd, rs232_rts, rs232_cts, mouse_clock, mouse_data, keyboard_clock, keyboard_data, clock_27mhz, clock1, clock2, disp_blank, disp_data_out, disp_clock, disp_rs, disp_ce_b, disp_reset_b, disp_data_in, button0, button1, button2, button3, button_enter, button_right, button_left, button_down, button_up, switch, led, user1, user2, user3, user4, daughtercard, systemace_data, systemace_address, systemace_ce_b, systemace_we_b, systemace_oe_b, systemace_irq, systemace_mpbrdy, analyzer1_data, analyzer1_clock, analyzer2_data, analyzer2_clock, analyzer3_data, analyzer3_clock, analyzer4_data, analyzer4_clock); output beep, audio_reset_b, ac97_synch, ac97_sdata_out; input ac97_bit_clock, ac97_sdata_in; output [7:0] vga_out_red, vga_out_green, vga_out_blue; output vga_out_sync_b, vga_out_blank_b, vga_out_pixel_clock, vga_out_hsync, vga_out_vsync; output [9:0] tv_out_ycrcb; output tv_out_reset_b, tv_out_clock, tv_out_i2c_clock, tv_out_i2c_data, tv_out_pal_ntsc, tv_out_hsync_b, tv_out_vsync_b, tv_out_blank_b, tv_out_subcar_reset; input [19:0] tv_in_ycrcb; input tv_in_data_valid, tv_in_line_clock1, tv_in_line_clock2, tv_in_aef, tv_in_hff, tv_in_aff; output tv_in_i2c_clock, tv_in_fifo_read, tv_in_fifo_clock, tv_in_iso, tv_in_reset_b, tv_in_clock; inout tv_in_i2c_data; inout [35:0] ram0_data; output [18:0] ram0_address; output ram0_adv_ld, ram0_clk, ram0_cen_b, ram0_ce_b, ram0_oe_b, ram0_we_b; output [3:0] ram0_bwe_b; inout [35:0] ram1_data; output [18:0] ram1_address; output ram1_adv_ld, ram1_clk, ram1_cen_b, ram1_ce_b, ram1_oe_b, ram1_we_b; output [3:0] ram1_bwe_b; input clock_feedback_in; output clock_feedback_out; inout [15:0] flash_data; output [23:0] flash_address; output flash_ce_b, flash_oe_b, flash_we_b, flash_reset_b, flash_byte_b; input flash_sts; output rs232_txd, rs232_rts; input rs232_rxd, rs232_cts; input mouse_clock, mouse_data, keyboard_clock, keyboard_data; input clock_27mhz, clock1, clock2; output disp_blank, disp_clock, disp_rs, disp_ce_b, disp_reset_b; input disp_data_in; output disp_data_out; input button0, button1, button2, button3, button_enter, button_right, button_left, button_down, button_up; input [7:0] switch; output [7:0] led; inout [31:0] user1, user2, user3, user4; inout [43:0] daughtercard; inout [15:0] systemace_data; output [6:0] systemace_address; output systemace_ce_b, systemace_we_b, systemace_oe_b; input systemace_irq, systemace_mpbrdy; output [15:0] analyzer1_data, analyzer2_data, analyzer3_data, analyzer4_data; output analyzer1_clock, analyzer2_clock, analyzer3_clock, analyzer4_clock; //////////////////////////////////////////////////////////////////////////// // // I/O Assignments // //////////////////////////////////////////////////////////////////////////// // Audio Input and Output assign beep= 1'b0; assign audio_reset_b = 1'b0; assign ac97_synch = 1'b0; assign ac97_sdata_out = 1'b0; // ac97_sdata_in is an input // Video Output assign tv_out_ycrcb = 10'h0; assign tv_out_reset_b = 1'b0; assign tv_out_clock = 1'b0; assign tv_out_i2c_clock = 1'b0; assign tv_out_i2c_data = 1'b0; assign tv_out_pal_ntsc = 1'b0; assign tv_out_hsync_b = 1'b1; assign tv_out_vsync_b = 1'b1; assign tv_out_blank_b = 1'b1; assign tv_out_subcar_reset = 1'b0; // Video Input assign tv_in_i2c_clock = 1'b0; assign tv_in_fifo_read = 1'b0; assign tv_in_fifo_clock = 1'b0; assign tv_in_iso = 1'b0; assign tv_in_reset_b = 1'b0; assign tv_in_clock = 1'b0; assign tv_in_i2c_data = 1'bZ; // tv_in_ycrcb, tv_in_data_valid, tv_in_line_clock1, tv_in_line_clock2, // tv_in_aef, tv_in_hff, and tv_in_aff are inputs // SRAMs assign ram0_data = 36'hZ; assign ram0_address = 19'h0; assign ram0_adv_ld = 1'b0; assign ram0_clk = 1'b0; assign ram0_cen_b = 1'b1; assign ram0_ce_b = 1'b1; assign ram0_oe_b = 1'b1; assign ram0_we_b = 1'b1; assign ram0_bwe_b = 4'hF; assign ram1_data = 36'hZ; assign ram1_address = 19'h0; assign ram1_adv_ld = 1'b0; assign ram1_clk = 1'b0; assign ram1_cen_b = 1'b1; assign ram1_ce_b = 1'b1; assign ram1_oe_b = 1'b1; assign ram1_we_b = 1'b1; assign ram1_bwe_b = 4'hF; assign clock_feedback_out = 1'b0; // clock_feedback_in is an input // Flash ROM assign flash_data = 16'hZ; assign flash_address = 24'h0; assign flash_ce_b = 1'b1; assign flash_oe_b = 1'b1; assign flash_we_b = 1'b1; assign flash_reset_b = 1'b0; assign flash_byte_b = 1'b1; // flash_sts is an input // RS-232 Interface assign rs232_txd = 1'b1; assign rs232_rts = 1'b1; // rs232_rxd and rs232_cts are inputs // PS/2 Ports // mouse_clock, mouse_data, keyboard_clock, and keyboard_data are inputs // LED Displays assign disp_blank = 1'b1; assign disp_clock = 1'b0; assign disp_rs = 1'b0; assign disp_ce_b = 1'b1; assign disp_reset_b = 1'b0; assign disp_data_out = 1'b0; // disp_data_in is an input // Buttons, Switches, and Individual LEDs //assign led = 8'hFF; // button0, button1, button2, button3, button_enter, button_right, // button_left, button_down, button_up, and switches are inputs // User I/Os assign user1 = 32'hZ; assign user2 = 32'hZ; assign user3 = 32'hZ; assign user4 = 32'hZ; // Daughtercard Connectors assign daughtercard = 44'hZ; // SystemACE Microprocessor Port assign systemace_data = 16'hZ; assign systemace_address = 7'h0; assign systemace_ce_b = 1'b1; assign systemace_we_b = 1'b1; assign systemace_oe_b = 1'b1; // systemace_irq and systemace_mpbrdy are inputs // Logic Analyzer assign analyzer1_data = 16'h0; assign analyzer1_clock = 1'b1; assign analyzer2_data = 16'h0; assign analyzer2_clock = 1'b1; assign analyzer3_data = 16'h0; assign analyzer3_clock = 1'b1; assign analyzer4_data = 16'h0; assign analyzer4_clock = 1'b1; //////////////////////////////////////////////////////////////////////////// // use FPGA's digital clock manager to produce a // 65MHz clock (actually 64.8MHz) wire clock_65mhz_unbuf,clock_65mhz; DCM vclk1(.CLKIN(clock_27mhz),.CLKFX(clock_65mhz_unbuf)); // synthesis attribute CLKFX_DIVIDE of vclk1 is 10 // synthesis attribute CLKFX_MULTIPLY of vclk1 is 24 // synthesis attribute CLK_FEEDBACK of vclk1 is NONE // synthesis attribute CLKIN_PERIOD of vclk1 is 37 BUFG vclk2(.O(clock_65mhz),.I(clock_65mhz_unbuf)); // power-on reset generation wire power_on_reset; // remain high for first 16 clocks SRL16 reset_sr (.D(1'b0), .CLK(clock_65mhz), .Q(power_on_reset), .A0(1'b1), .A1(1'b1), .A2(1'b1), .A3(1'b1)); defparam reset_sr.INIT = 16'hFFFF; // ENTER button is user reset wire reset,user_reset; debounce db5(power_on_reset, clock_65mhz, ~button_enter, user_reset); assign reset = user_reset | power_on_reset; // generate basic XVGA video signals wire [10:0] hcount; wire [9:0] vcount; wire hsync,vsync,blank; xvga xvga1(clock_65mhz,hcount,vcount,hsync,vsync,blank); // character display module: sample string in middle of screen reg [16*8-1:0] cstring; wire [2:0] cdpixel; char_string_display cd(clock_65mhz,hcount,vcount, cdpixel,cstring,11'd100,10'd384); defparam cd.NCHAR = 16; defparam cd.NCHAR_BITS = 4; // keyboard input wire [7:0] ascii; wire char_rdy; ps2_ascii_input kbd(clock_65mhz, reset, keyboard_clock, keyboard_data, ascii, char_rdy); reg [3:0] count = 15; reg [7:0] last_ascii; always @(posedge clock_65mhz) begin count <= reset ? 15 : (char_rdy ? count-1 : count); last_ascii <= char_rdy ? ascii : last_ascii; end // assign cstring = {8{last_ascii}}; always @(posedge clock_65mhz) begin cstring[7:0] <= (count==0) ? last_ascii : cstring[7:0]; cstring[7+'o10:'o10] <= (count==1) ? last_ascii: cstring[7+'o10:'o10]; cstring[7+'o20:'o20] <= (count==2) ? last_ascii: cstring[7+'o20:'o20]; cstring[7+'o30:'o30] <= (count==3) ? last_ascii: cstring[7+'o30:'o30]; cstring[7+'o40:'o40] <= (count==4) ? last_ascii: cstring[7+'o40:'o40]; cstring[7+'o50:'o50] <= (count==5) ? last_ascii: cstring[7+'o50:'o50]; cstring[7+'o60:'o60] <= (count==6) ? last_ascii: cstring[7+'o60:'o60]; cstring[7+'o70:'o70] <= (count==7) ? last_ascii: cstring[7+'o70:'o70]; cstring[7+'o100:'o100] <= (count==8) ? last_ascii: cstring[7+'o100:'o100]; cstring[7+'o110:'o110] <= (count==9) ? last_ascii: cstring[7+'o110:'o110]; cstring[7+'o120:'o120] <= (count==10) ? last_ascii: cstring[7+'o120:'o120]; cstring[7+'o130:'o130] <= (count==11) ? last_ascii: cstring[7+'o130:'o130]; cstring[7+'o140:'o140] <= (count==12) ? last_ascii: cstring[7+'o140:'o140]; cstring[7+'o150:'o150] <= (count==13) ? last_ascii: cstring[7+'o150:'o150]; cstring[7+'o160:'o160] <= (count==14) ? last_ascii: cstring[7+'o160:'o160]; cstring[7+'o170:'o170] <= (count==15) ? last_ascii: cstring[7+'o170:'o170]; end assign led = {reset,4'b0,count}; // switch[0] selects which video generator to use: // 00: text // 01: 1 pixel outline of active video area (adjust screen controls) // 10: color bars reg [2:0] rgb; reg b,hs,vs; always @(posedge clock_65mhz) begin hs <= hsync; vs <= vsync; b <= blank; if (switch[1:0] == 2'b01) begin // 1 pixel outline of visible area (white) rgb <= (hcount==0 | hcount==1023 | vcount==0 | vcount==767) ? 7 : 0; end else if (switch[1:0] == 2'b10) begin // color bars rgb <= hcount[8:6]; end else begin // default: text rgb <= cdpixel; end end // VGA Output. In order to meet the setup and hold times of the // AD7125, we send it ~clock_65mhz. assign vga_out_red = {8{rgb[2]}}; assign vga_out_green = {8{rgb[1]}}; assign vga_out_blue = {8{rgb[0]}}; assign vga_out_sync_b = 1'b1; // not used assign vga_out_blank_b = ~b; assign vga_out_pixel_clock = ~clock_65mhz; assign vga_out_hsync = hs; assign vga_out_vsync = vs; endmodule //////////////////////////////////////////////////////////////////////////////// // // xvga: Generate XVGA display signals (1024 x 768 @ 60Hz) // //////////////////////////////////////////////////////////////////////////////// module xvga(vclock,hcount,vcount,hsync,vsync,blank); input vclock; output [10:0] hcount; output [9:0] vcount; output vsync; output hsync; output blank; reg hsync,vsync,hblank,vblank,blank; reg [10:0] hcount; // pixel number on current line reg [9:0] vcount; // line number // horizontal: 1344 pixels total // display 1024 pixels per line wire hsyncon,hsyncoff,hreset,hblankon; assign hblankon = (hcount == 1023); assign hsyncon = (hcount == 1047); assign hsyncoff = (hcount == 1183); assign hreset = (hcount == 1343); // vertical: 806 lines total // display 768 lines wire vsyncon,vsyncoff,vreset,vblankon; assign vblankon = hreset & (vcount == 767); assign vsyncon = hreset & (vcount == 776); assign vsyncoff = hreset & (vcount == 782); assign vreset = hreset & (vcount == 805); // sync and blanking wire next_hblank,next_vblank; assign next_hblank = hreset ? 0 : hblankon ? 1 : hblank; assign next_vblank = vreset ? 0 : vblankon ? 1 : vblank; always @(posedge vclock) begin hcount <= hreset ? 0 : hcount + 1; hblank <= next_hblank; hsync <= hsyncon ? 0 : hsyncoff ? 1 : hsync; // active low vcount <= hreset ? (vreset ? 0 : vcount + 1) : vcount; vblank <= next_vblank; vsync <= vsyncon ? 0 : vsyncoff ? 1 : vsync; // active low blank <= next_vblank | (next_hblank & ~hreset); end endmodule /////////////////////////////////////////////////////////////////////////////// // // Pushbutton Debounce Module (video version) // /////////////////////////////////////////////////////////////////////////////// module debounce (reset, clock_65mhz, noisy, clean); input reset, clock_65mhz, noisy; output clean; reg [19:0] count; reg new, clean; always @(posedge clock_65mhz) if (reset) begin new <= noisy; clean <= noisy; count <= 0; end else if (noisy != new) begin new <= noisy; count <= 0; end else if (count == 650000) clean <= new; else count <= count+1; endmodule