Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4431|回復: 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(串聯)輸出,請問我該如果修改程式呢?請大家幫幫忙,給個意見,或者提供任何資料參考...thx5 A" \4 d$ j4 \& V

: Q6 c$ G8 Q$ f, W" U" l, M4 l程式如下:
3 O# Y1 r" \: D  A& p-- PS2_Ctrl.vhd
/ z. B9 i, V% N4 o8 q-- ------------------------------------------------: P! u1 s6 Z) v
-- Simplified PS/2 Controller (kbd, mouse...)
8 {9 S7 q" N. F8 c0 ]' j0 l. {-- ------------------------------------------------
! y2 h  C) ?9 R# q8 I0 D( A-- Only the Receive function is implemented !- h- K  \  y: z: @8 k
-- (c) ALSE. http://www.alse-fr.com
) F$ l+ m% }" I/ X; J3 h, Tlibrary IEEE;; a" n% ~# H! O4 X7 _; R
use IEEE.STD_LOGIC_1164.all;% p3 A) \% J0 D# y5 W4 c6 X/ Z2 W
use IEEE.Numeric_std.all;% F0 C4 c/ L* L; J
-- --------------------------------------
0 f" ^$ ^3 m$ \: F4 ZEntity PS2_Ctrl is7 ?2 u* Y) E% Z1 z
-- --------------------------------------
  Q3 `5 j. ?& L" ]0 Qgeneric (FilterSize : positive := 8);, y& Z' R. o( B1 J. ]0 ]
port( Clk : in std_logic; -- System Clock, E0 A1 z& V$ c' Y
Reset : in std_logic; -- System Reset' l) L- H, `; }$ k5 N
PS2_Clk : in std_logic; -- Keyboard Clock Line
+ g6 S( O1 ]7 S+ f% pPS2_Data : in std_logic; -- Keyboard Data Line) G# P, r$ X4 \
DoRead : in std_logic; -- From outside when reading the scan code
" I& A5 B+ p# ZScan_Err : out std_logic; -- To outside : Parity or Overflow error1 h' u) R! j) ]( \, X; J
Scan_DAV : out std_logic; -- To outside when a scan code has arrived) a2 M# X# [' T; i8 b5 `
Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out1 U- _2 \: n$ C$ _  K+ |  i! E
);
9 z( Q; U8 M9 d; W3 iend PS2_Ctrl;
" _  ]+ y) C) k6 M. z$ X-- --------------------------------------
& p8 q0 P7 D8 q+ H4 RArchitecture ALSE_RTL of PS2_Ctrl is
1 Z* |4 f% U- C! n# ]! u- R-- --------------------------------------
9 z3 Z) W# T9 f; c-- (c) ALSE. http://www.alse-fr.com" Z' U4 @$ F1 z; ]0 E
-- Author : Bert Cuzeau.
  i5 ?3 x  e) O) Y-- Fully synchronous solution, same Filter on PS2_Clk.
2 Y/ `* M  |3 U-- Still as compact as "Plain_wrong"...
6 o1 n' T5 Y! F" o-- Possible improvement : add TIMEOUT on PS2_Clk while shifting; P3 L. L/ T. y' m
-- Note: PS2_Data is resynchronized though this should not be
% H2 X$ k/ [# }/ E-- necessary (qualified by Fall_Clk and does not change at that time)./ b/ {, h1 C) ^3 r
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.: g/ M* h  V6 E# F9 Q
signal PS2_Datr : std_logic;3 ?8 T9 C+ v* u1 o5 I$ k
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);2 `! Q. K* h8 \5 O. w/ O
signal Filter : Filter_t;
* j& H% B  }$ e( M+ Asignal Fall_Clk : std_logic;5 H( F. k2 l+ D& Q  Y+ D- g: z1 N
signal Bit_Cnt : unsigned (3 downto 0);
' I' Z& V- M% N* N2 r  |signal Parity : std_logic;; P8 x- U' V" g
signal Scan_DAVi : std_logic;
# f% I* k0 E# P- T& y% z2 l& Csignal S_Reg : std_logic_vector(8 downto 0);3 Z. w" Y$ s! ]
signal PS2_Clk_f : std_logic;
. R# ~8 ]- T* }0 B1 ?Type State_t is (Idle, Shifting);
/ [$ D0 O; b5 r  \9 U3 V' msignal State : State_t;2 d$ Y$ ?# S( S
begin
! [- A+ n$ `1 C- p& }Scan_DAV <= Scan_DAVi;
- D4 [/ J. Y' h$ M-- This filters digitally the raw clock signal coming from the keyboard :
2 h9 F! O! w. }& y1 O6 Y2 K' |& E5 [-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high- l# a3 ]9 u$ D5 e  G0 C' ~
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low' k1 q$ \) s! U, d! S5 E/ b- `, g
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data
) [; }# j1 _  T-- Also in charge of the re-synchronization of PS2_Data* }) F. `7 T  v4 H' B
process (Clk,Reset)9 C% b$ {2 g$ }# `
begin; q/ V2 d# X8 h" }# ~/ S3 P
if Reset='0' then
- P/ C. Z+ s/ E% e+ s1 w" hPS2_Datr <= '0';. n+ C5 b. p4 T# y4 P5 E
PS2_Clk_f <= '0';
9 a! }9 ^8 z+ ^1 k4 j% `1 W" CFilter <= (others=>'0');
$ A/ B$ c: f' g9 H' l# yFall_Clk <= '0';- b6 T/ c$ s( R4 R" T
elsif rising_edge (Clk) then5 C; @- [% u8 t. h* l; ]. V% i
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'/ e! B% s% g+ v3 {- [! r
Fall_Clk <= '0';
: M( @3 M9 N3 v3 HFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
: i/ y8 y1 o1 Oif Filter = Filter_t'(others=>'1') then- ?' }, e. {' G/ ?1 [
PS2_Clk_f <= '1';
; f' [4 S1 F2 K, p: I* ^* ]elsif Filter = Filter_t'(others=>'0') then8 N4 n1 N! H2 I/ L/ \0 m4 K
PS2_Clk_f <= '0';
( C3 ]4 |7 u2 V1 }# t7 i* ^' Nif PS2_Clk_f = '1' then9 N) [* x  o- ^$ b& k! Y8 g- ~
Fall_Clk <= '1';
% P- F: F( \' G9 j" m" I! {end if;6 X: |/ ]- l2 \4 B6 B8 y
end if;
1 e4 f3 o3 z/ Q( M$ n/ S* P( F7 Tend if;
3 h0 q: |. h0 h% i* fend process;
1 `* a+ [! L8 I- n. f- h6 Q, L-- This simple State Machine reads in the Serial Data
: ]& z6 c6 \2 ^2 _2 k: l-- coming from the PS/2 peripheral.! @( T  w8 k1 v7 `; W& o2 ]/ n, v+ |
process(Clk,Reset)
& W4 q" }8 U" F" I/ L# F7 D# Mbegin, j' x$ g4 ?0 }
if Reset='0' then2 i5 H7 A3 E1 I( R7 Y
State <= Idle;6 p+ `: P+ \! ?. e* A) K
Bit_Cnt <= (others => '0');- ?0 ?0 P3 n& A9 G3 d+ q0 }
S_Reg <= (others => '0');
1 `; v( F6 L5 |% j# ]1 I) HScan_Code <= (others => '0');
9 m+ s( l  E% A* f1 ^5 GParity <= '0';  l# H2 F& ~. v: I" b! ^: E1 i
Scan_Davi <= '0';
/ [. p+ j4 Z  \Scan_Err <= '0';
1 O- I3 e# R7 e! r" welsif rising_edge (Clk) then5 K4 `& }7 A# A. b1 }
if DoRead='1' then
+ S+ i, u" y) Y. C. D& q2 [* @Scan_Davi <= '0'; -- note: this assgnmnt can be overriden
' E2 ]. Y7 }, E$ ~9 h& y9 Xend if;6 }9 o5 J' h6 L5 M' ~( r% y" J" D
case State is
! m) D; ~5 O2 @1 uwhen Idle =>
3 I1 G% s9 v7 j  v9 h# F2 |- }: pParity <= '0';& ^3 x( L. X$ ?- ?- M) B+ V
Bit_Cnt <= (others => '0');9 V1 ?$ Q$ {$ T& @$ T$ a; s
-- note that we dont need to clear the Shift Register9 W1 k$ p1 n% N$ N; f- N( a
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit
: p. @) P4 V$ A. r0 S# xScan_Err <= '0';4 x7 \" l+ s; M6 B3 B
State <= Shifting;/ M( i: F( i- k% [
end if;$ h9 O. x1 Q$ L
when Shifting =>
7 j8 a5 D) g2 W* K% wif Bit_Cnt >= 9 then
0 O8 B& k3 t7 e% \  zif Fall_Clk='1' then -- Stop Bit0 j4 t; a. r& T4 M6 k+ d
-- Error is (wrong Parity) or (Stop='0') or Overflow2 j  J5 |. x  j! ~( @
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;+ b) Z# j% ?, p8 k( L% c* L
Scan_Davi <= '1';2 E/ \& j3 K9 Y2 G$ e& X
Scan_Code <= S_Reg(7 downto 0);
$ K- o5 d) d0 |! [/ b3 n/ _) BState <= Idle;
. \, n! C. B6 k7 H1 z1 P2 Pend if;# f* [0 e9 c7 {# `6 W4 ]$ @3 ^
elsif Fall_Clk='1' then
4 E; \- `, z& C' D4 ~, f8 @Bit_Cnt <= Bit_Cnt + 1;) ?, M$ o/ _) ]1 _( g; B
S_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right$ u" Q  M: r* b0 s! c2 z* R
Parity <= Parity xor PS2_Datr;- \! C" {+ M5 a
end if;
3 T2 g9 U3 Z$ I% K: Iwhen others => -- never reached" v9 ^" F( l3 r" V% o1 S
State <= Idle;
0 T8 X, i  u+ P; }' J" Z  lend case;
% ?0 ^/ g; a9 ~( T% Vend if;/ ^3 d5 p# j8 F( X/ f# C* y
end process;
# W$ w" V% x" T0 C" |end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-16 02:05 AM , Processed in 0.102013 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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