【正文】
vsync_t=vsync_t+1。 end always (negedge hsync)//creat vsync signal if(!rst_n) begin vsync_t=1。 hsync_t=hsync_t+1。 green = 339。 end else begin red = 339。 if(ascii_data_out[(hsync_t216)%8] amp。 end else if(~flag) begin if((data_input == 13) || (char_t_for_screen_roll=99)) begin if(char_t_start_flag=36) begin if(char_t_start=36) begin char_t_start=0。 dis_y=dis_y1。 (data_input=126)) begin if(dis_x=98) begin dis_x=dis_x+1。amp。 assign current_char_y=(vsync_t27)/16。(~flag)),.wraddress(current_char_num),.wrclock(clk),.wren(~data_valid),.q(ram_out))。 reg [7:0] char_t_start_flag。//the max column is 100 wire [5:0] current_char_y。 reg vsync_en。 output hsync。 VGA 模塊 //VGA_Control 1024*76875Hz module vga(clk,rst_n,data_input,flag,red,green,blue,hsync,vsync)。X 88 when x135 = NUM = 01011001。P 80 when x115 = NUM = 01010001。H 72 when x143 = NUM = 01001001。Backspace when x11C = NUM = 01000001。{ when x15b = NUM=x7d 。* when x146 = NUM=x28 。! when x11e = NUM=x40 。s 115 when x02C = NUM = 01110100。k 107 when x04B = NUM = 01101100。c 99 when x023 = NUM = 01100100。, 44 when x049 = NUM = 00101110。 95 when x054 = NUM = 01011011。4 52 when x02E = NUM = 00110101。139。039。 isfo : in std_logic。 end process。 else flag=39。 end if。 end if。 else dataerror=39。and dataing=39。039。 第 14 頁 共 21 頁 ps/2 鍵盤數(shù)據(jù)接收進(jìn)程 process(clk) begin if (clk39。 signal flag1 :std_logic。 architecture behave of keyboard is signal dataerror :std_logic。 use 。如果這個(gè)信號(hào)處理不好會(huì)出現(xiàn)閃頻、顯示不穩(wěn)定 、顯示亂碼等現(xiàn)象,通過不斷地調(diào)試、測試,我們做到理想的效果,也實(shí)現(xiàn)了回車、空格、退格等操作。 第 10 頁 共 21 頁 基本達(dá)到了設(shè)計(jì)要求,能夠?qū)?PS2 鍵盤的字符輸入顯示在 VGA 上,有大小寫轉(zhuǎn)換的功能。039。 end else begin dis_y=dis_y+1。只是這里的基本單位為每行數(shù)據(jù),而行數(shù)據(jù)里面的最基本單位為每個(gè)點(diǎn)。它分為行數(shù)據(jù)時(shí)序和幀數(shù)據(jù)時(shí)序。 end if。) then if (t=8) then if (shiftdata=11110000) then flag=39。 ( 4) 在第十個(gè)時(shí)鐘線下降沿接受奇校驗(yàn)位。 如圖 C0 為 KEYBARD 部分提供時(shí)鐘信號(hào), C1 為TRANSFORM 與 VGA 提供時(shí)鐘信號(hào)。通信的兩端通過 Clock(時(shí)鐘腳)同步,并通過 Data(數(shù)據(jù)腳)交換數(shù)據(jù)。標(biāo)準(zhǔn) PS/2 鍵盤接口協(xié)議簡單,在系統(tǒng)中占用資源少,高可靠性,表達(dá)信息量大。基本達(dá)到了本次設(shè)計(jì)的目的與要求。各模塊之間的關(guān)系如下圖所示: 第 3 頁 共 21 頁 總原理圖 工作原理: 對(duì)鍵盤按鍵進(jìn)行掃描,采集按鍵的掃描碼,通過外部字符轉(zhuǎn)換程序,將掃描碼轉(zhuǎn)化為 ASCII 碼,送入 VGA 驅(qū)動(dòng),進(jìn)行字符的 VGA 顯示。 FPGA 接收 PS/2 鍵盤發(fā)送一個(gè)字節(jié)可按下面的步驟進(jìn)行: 第 5 頁 共 21 頁 ( 1) 時(shí)鐘線電平,如果時(shí)鐘線由高變低,則表示時(shí)鐘線的下降沿到來。這里第 6 頁 共 21 頁 采用接收 PS/2 鍵盤按鍵彈起來斷碼中的通碼,其數(shù)據(jù)處理過程如下: process(clk) 對(duì)接收到的 ps/2 鍵盤數(shù)據(jù)分析處理 begin if (clk39。 end if。對(duì)于普通的 VGA 顯示器,其引出線的共含 5 個(gè)信號(hào): G,R,B(三基色信號(hào)), HS(行同步信號(hào)), VS(場同步 號(hào))。其中 a、 b、 c、 d均為時(shí)間信號(hào),這些信號(hào)根據(jù)需要顯示的分辨率不同而不同。由于采用 1024 768 的顯示模式,選用 65Mhz 的時(shí)鐘頻率。還在此部分進(jìn)行了大小 寫操作。 四、 結(jié)果分析和調(diào)試 雙擊 Quartus II 軟件快捷圖標(biāo)進(jìn)入 Quartus II 集成開發(fā)環(huán)境,新建工程項(xiàng)目文件,并在該項(xiàng)目下新建 VHDL 與 Verilog HDL 源程序文件,輸入程序代碼,建立模塊層次結(jié)構(gòu)圖,然后為該工程項(xiàng)目選擇一個(gè)目標(biāo)器件并對(duì)相應(yīng)的管腳進(jìn)行鎖定,保存后編譯。在此過程中我們也遇到了許多困難 , 首先對(duì) PS2 鍵盤的操作,我們根據(jù)查閱資料逐步對(duì)它有了了解,能夠根據(jù)自己的理解修改老師的程序,在 VGA 顯示時(shí), 最初也只能在頻幕的第一個(gè)位置顯示字符,不能實(shí)現(xiàn)挨個(gè)字符顯示的效果。 S2 為 VGA 復(fù)位按鍵; pll25 鎖相環(huán)分出兩種時(shí)鐘頻率,分別提供給鍵盤( 25MHZ? VGA( 65MHZ), transform 為 VGA 部分的掃描碼轉(zhuǎn) ASCII 碼模塊,其 led 輸 出端口為字符大小寫轉(zhuǎn)換指示燈。 ps/2 鍵盤數(shù)據(jù)輸入 keycode: out std_logic_vector(7 downto 0)。 signal kbclkreg :std_logic。 kbclkfall=kbclkreg and (not kb_clk)。and dataing=39。039。039。039。 t=t+1。) then if (t=8) then if (shiftdata=11110000) then 接收到斷碼的“ F0” ,則表示有鍵彈起,否則表示有按鍵按下 flag=39。039。 use 。 signal Caps: std_logic。 end process。1 49 when x01E = NUM = 00110010。9 57 when x00E = NUM = 01111110。 59 when x052 = NUM = 00011011。退格 8 when x01C = NUM = 01100001。h 104 when x043 = NUM = 01101001。p 112 when x015 = NUM = 01110001。x 120 when x035 = NUM = 01111001。^ when x13d = NU