Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4434|回復: 0
打印 上一主題 下一主題

[問題求助] VHDL PS/2 Keyboard 程式問題..thx

  [複製鏈接]
跳轉到指定樓層
1#
發表於 2008-1-23 17:29:22 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
目前需要使用MAXII 1270 做PS/2 Keyboard控制,在網路上找到了用VHDL寫PS/2介面,經過測試後正常,但輸出是8個Pin輸出(並聯),但我希望輸出為1個Pin(串聯)輸出,請問我該如果修改程式呢?請大家幫幫忙,給個意見,或者提供任何資料參考...thx0 F2 M1 q% W/ k. z( S

5 D: c+ C% x; ^/ m) ?9 W; x程式如下:
7 t! l$ C2 F1 f0 S-- PS2_Ctrl.vhd
1 v$ |- |( h# [9 ^0 j-- ------------------------------------------------: a1 Z9 Z5 d9 D! O: N, p$ d
-- Simplified PS/2 Controller (kbd, mouse...)
: x# B- t9 R% U-- ------------------------------------------------
' l5 m$ j, f" r3 o) x-- Only the Receive function is implemented !% R0 ~( W9 V- z# M# C: ?# ~) O: v5 ?
-- (c) ALSE. http://www.alse-fr.com; q- ?% @  l' o* y
library IEEE;, B4 q: D' }, d8 U) T8 o
use IEEE.STD_LOGIC_1164.all;
3 E% t( Z' r2 muse IEEE.Numeric_std.all;
  R; k9 A# G7 L; I* q, Y) ?-- --------------------------------------: I+ `/ [$ h6 u- A
Entity PS2_Ctrl is7 `) Y. H: N3 L/ \% @3 u
-- --------------------------------------
& Q7 X* [6 a9 I% T# Ngeneric (FilterSize : positive := 8);2 l4 ]5 ^  s9 D  A$ |( r
port( Clk : in std_logic; -- System Clock# u  u! G2 W$ {! r1 A5 g
Reset : in std_logic; -- System Reset( E. \+ f0 {. L, W& ]) n1 i
PS2_Clk : in std_logic; -- Keyboard Clock Line( `% \& D* c6 O3 X$ E7 j& O% Z
PS2_Data : in std_logic; -- Keyboard Data Line
: V3 ~4 C3 D( v) fDoRead : in std_logic; -- From outside when reading the scan code7 S. X- y* V' _' ^7 e+ |4 z
Scan_Err : out std_logic; -- To outside : Parity or Overflow error  p' d( [4 k3 U6 R% ~5 ]& A; T
Scan_DAV : out std_logic; -- To outside when a scan code has arrived
- t* F: {) T8 B) \Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
! k, L: P9 i; \+ q4 o# W7 m6 h);
! E" _; F$ t: b* P" e8 Gend PS2_Ctrl;
: A9 h4 @& S7 @% j0 ^; G# E-- --------------------------------------, {, D/ h2 m6 T
Architecture ALSE_RTL of PS2_Ctrl is. D9 z9 V4 n  m) P2 T$ s% [
-- --------------------------------------
& A) M* g% g4 z) W) R-- (c) ALSE. http://www.alse-fr.com
2 \0 i% h8 H4 I4 y3 o+ c, W2 P-- Author : Bert Cuzeau.: z/ @- G; O  V1 V
-- Fully synchronous solution, same Filter on PS2_Clk.
4 @$ b. N5 B$ L-- Still as compact as "Plain_wrong"...$ T  }, r9 b1 V9 M
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting+ o/ F9 E' r3 Y! _6 i: l
-- Note: PS2_Data is resynchronized though this should not be' F' ?" C- T. E% J% w: C" @
-- necessary (qualified by Fall_Clk and does not change at that time).
6 t5 n, w6 \6 r, ~' N0 r% I-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.; \. w/ \. u9 I- R7 r& C7 x
signal PS2_Datr : std_logic;/ ?4 W- d* D1 Z( s& s- F" K
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
5 i' l7 S. B8 @) c, C+ X' A* usignal Filter : Filter_t;, w6 Q- a& n. z* Q6 x1 a
signal Fall_Clk : std_logic;- ?+ e' d8 N4 Q! z) ~% ~( v2 z$ ?
signal Bit_Cnt : unsigned (3 downto 0);( U) v" M$ B5 J1 t
signal Parity : std_logic;9 w: y1 F; w/ d  H
signal Scan_DAVi : std_logic;
" z5 I5 O- a4 f, Hsignal S_Reg : std_logic_vector(8 downto 0);! T- U& F9 z4 U7 X
signal PS2_Clk_f : std_logic;
' M5 a% q- A) x  {Type State_t is (Idle, Shifting);
6 X2 V/ e, H' @' `) ^% Rsignal State : State_t;
6 e# o' V2 j& v2 e0 U& d4 jbegin
4 j  P5 w6 F& _% G) M( w( _% P5 WScan_DAV <= Scan_DAVi;; A- F- n* n, j
-- This filters digitally the raw clock signal coming from the keyboard :* a( N, J) m: j" ~5 I/ s
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high9 n* G0 m1 L- |* |
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low% O! m* @2 k. i  q3 X& ^
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data
: J1 \# G5 w$ ^1 I-- Also in charge of the re-synchronization of PS2_Data3 c# O2 h: F' w- A! i) ?+ \$ _
process (Clk,Reset)
. S" v2 U/ r, lbegin
4 ?8 r# J0 ~7 Q( \$ Iif Reset='0' then
( n: s3 y6 r! e' GPS2_Datr <= '0';
0 {4 t1 m6 b* \3 U( [PS2_Clk_f <= '0';
1 B0 E# Q0 J0 o+ p8 i* T8 lFilter <= (others=>'0');" N7 ~, e9 ^3 V6 x, ~- }
Fall_Clk <= '0';1 \. w; x0 Z- V. ~: p5 J% Y+ _
elsif rising_edge (Clk) then/ B! D% ~5 r/ ^! |
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'% l$ {0 V! \/ x
Fall_Clk <= '0';
) Y! V9 l  w- S% c- p' S8 SFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
; i4 q2 d4 s: ^, F5 z  _if Filter = Filter_t'(others=>'1') then! K  r$ j9 D2 Y
PS2_Clk_f <= '1';+ Z" N, _6 D5 }1 o9 I
elsif Filter = Filter_t'(others=>'0') then0 \2 D! C3 {" f
PS2_Clk_f <= '0';7 J: b4 o0 c& m4 l7 W+ @
if PS2_Clk_f = '1' then
4 B/ \! n7 x$ t# {/ T$ q+ d, DFall_Clk <= '1';
& q; e4 ~# T/ t' \' }end if;
0 F2 c' R( o' _, v$ R: q1 M# send if;7 D  ^4 {2 k/ s
end if;1 F  @6 ~: w5 ?  Z) l$ R) s
end process;
  ]' s, g8 B3 t( A-- This simple State Machine reads in the Serial Data
) y4 \6 k/ f1 H4 P5 S& J-- coming from the PS/2 peripheral.
! N! [# d; r/ Q, f  j( I2 D4 _process(Clk,Reset)
1 H# D& f* a) `% q5 m) }, @, \6 U3 jbegin
2 S6 s& y# h; }% r7 ?  c6 U9 x! pif Reset='0' then
! p: v7 x1 ~1 w, a- ?6 x! _State <= Idle;" r% D4 u' U% ^. {
Bit_Cnt <= (others => '0');+ v) L  G, C0 q
S_Reg <= (others => '0');
: |  @" o9 V7 ?; Z# KScan_Code <= (others => '0');+ E- t6 v, B# \, E
Parity <= '0';
. @! {0 V5 m& _! ^Scan_Davi <= '0';
+ L5 v/ V0 n4 y! S& R. OScan_Err <= '0';1 N# x  E' J# k8 O9 i, n6 {0 o: f
elsif rising_edge (Clk) then
0 U8 J) \+ S, [! F# yif DoRead='1' then2 N: X" }7 z/ X' a* |
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden
: y8 ?- S2 u, M- A/ `end if;
) T4 g; f3 v: r8 Y+ T- kcase State is1 w+ I% v2 X- z. z. f
when Idle =>
& B8 B' |8 G4 {+ v. r0 W0 h7 E; BParity <= '0';$ n$ d8 y0 h5 c
Bit_Cnt <= (others => '0');
, ~4 r4 g6 W! O- r( ]-- note that we dont need to clear the Shift Register
2 N$ z0 g* z+ i+ u( b# A. f0 Zif Fall_Clk='1' and PS2_Datr='0' then -- Start bit
2 J( E& h" g  Y( V$ f0 X+ I; jScan_Err <= '0';
8 w0 u6 `3 _: Q4 G$ e4 `& XState <= Shifting;
; a6 U8 {; K6 T% R' o  g% o! Fend if;  n7 j. o: ?! [. J: G% }; i
when Shifting =>! P& n1 K) c3 h; t! H1 L8 S
if Bit_Cnt >= 9 then
& l$ Z) L* l  A4 c4 ~# zif Fall_Clk='1' then -- Stop Bit
9 D8 B  a# [6 c* ?- s( H- S-- Error is (wrong Parity) or (Stop='0') or Overflow; h4 |. P! B9 h% j
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
1 E& B( c* R  ~. h: fScan_Davi <= '1';, H. Y) ^) p' n" o# x
Scan_Code <= S_Reg(7 downto 0);
9 g- g7 K) ^( f$ y9 z* S" jState <= Idle;# f3 D3 S7 S. d$ R% f
end if;
2 |' p' a1 d1 e+ A) Eelsif Fall_Clk='1' then
2 u8 o3 v3 q" e+ C! d+ x4 m# FBit_Cnt <= Bit_Cnt + 1;
1 s5 n) Z+ k: c+ PS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
- t, H2 S) g0 K5 QParity <= Parity xor PS2_Datr;2 K1 a8 M: c9 l; g' g: ?
end if;
; V( d9 Y# c# F6 M7 Jwhen others => -- never reached
* T+ D7 N0 Z: @7 u, q! b! kState <= Idle;
% d) C0 O# l( X8 I' Z* E/ dend case;
1 ?; d4 o- o! h3 S& K4 Uend if;* S$ u3 _( u% U1 N9 y1 E
end process;
/ R+ Q4 R; E* ~  q) a5 s# d' B* Nend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

首頁|手機版|Chip123 科技應用創新平台 |新契機國際商機整合股份有限公司

GMT+8, 2024-5-18 09:37 AM , Processed in 0.114014 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表