Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4439|回復: 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(串聯)輸出,請問我該如果修改程式呢?請大家幫幫忙,給個意見,或者提供任何資料參考...thx
& m( ?% v  V2 o  F% B& s" i( i/ f( R! L! w1 r- E$ n: J
程式如下:
+ p- i) ~1 l- @' t) R, ~-- PS2_Ctrl.vhd
+ b) n" N$ c9 ~1 s2 o7 j- x- Z-- ------------------------------------------------& r6 m* \" v% d$ b  x! |2 d
-- Simplified PS/2 Controller (kbd, mouse...)* s( p  _1 C  i. E0 X( {6 Z7 o: c' Y
-- ------------------------------------------------3 S. @+ l$ s; J1 c, Q) `, D) ?' J/ S
-- Only the Receive function is implemented !+ \5 @0 C+ ?% C1 U8 e6 S4 B
-- (c) ALSE. http://www.alse-fr.com' G2 o& B6 F; O
library IEEE;
0 b+ _0 K- R, R, o0 luse IEEE.STD_LOGIC_1164.all;9 Y4 f& v1 |; Z' O* X) h( C0 k$ o3 y
use IEEE.Numeric_std.all;7 T8 I* S9 K. P
-- --------------------------------------' O: L% b% y' g+ c3 N% z
Entity PS2_Ctrl is
9 q! j6 l! I" n, V-- --------------------------------------% x9 ?) Z: I) G* E& g1 r2 s6 G
generic (FilterSize : positive := 8);9 c2 c) }* m: r6 D/ g
port( Clk : in std_logic; -- System Clock
) O- {6 N  \9 O9 y. n9 KReset : in std_logic; -- System Reset
/ }1 @" S) A/ D3 B9 L' N3 T/ L+ A- u  kPS2_Clk : in std_logic; -- Keyboard Clock Line9 W7 P+ }8 n& u$ `
PS2_Data : in std_logic; -- Keyboard Data Line
( ]" n0 u, Q9 B8 S7 h- A5 H* WDoRead : in std_logic; -- From outside when reading the scan code4 q- |) T+ q$ \% m% B: b$ }1 ^" X
Scan_Err : out std_logic; -- To outside : Parity or Overflow error
9 }/ _3 Q  \* S+ k* ^* xScan_DAV : out std_logic; -- To outside when a scan code has arrived
8 \7 q  c9 h; P  FScan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
6 m# z& [  O; Z7 E5 r' j);
& i; |" g) G. g9 ?2 ]end PS2_Ctrl;+ u9 b# Z& F* b5 a5 [+ U
-- --------------------------------------2 ~, y$ Q1 K) q. ]4 u2 p
Architecture ALSE_RTL of PS2_Ctrl is# [* o+ }: `' c" Y, r% X
-- --------------------------------------
2 b, {; D$ `$ \% K( j-- (c) ALSE. http://www.alse-fr.com: C$ }6 b  X0 ]5 a
-- Author : Bert Cuzeau.
3 E0 \- f0 E1 w9 z1 t  ^: d-- Fully synchronous solution, same Filter on PS2_Clk.
) o# u  p' c  q6 e-- Still as compact as "Plain_wrong"...) \6 r  P4 S9 r# m  _3 D; _  \6 p
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
, n9 z  N' {! V: i+ m-- Note: PS2_Data is resynchronized though this should not be- {/ ?( A1 t; ~* q6 b9 }8 Y" y) [
-- necessary (qualified by Fall_Clk and does not change at that time).
  ?$ b, \/ e- X& A: Q* v-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.
5 _0 N2 ^6 }- F* [9 ]# q9 \' ~4 rsignal PS2_Datr : std_logic;
5 A5 x3 Q! C7 r0 ]# d" U3 f) bsubtype Filter_t is std_logic_vector(FilterSize-1 downto 0);: H: P, l1 t4 j* M) O9 i9 A3 J
signal Filter : Filter_t;
1 o: u/ t; b- o0 [# dsignal Fall_Clk : std_logic;. v9 |  v' Z" F# K( j2 g3 Q
signal Bit_Cnt : unsigned (3 downto 0);
- v; \# G! B, o. r9 osignal Parity : std_logic;
* r0 s" e3 C/ Csignal Scan_DAVi : std_logic;% I9 A+ e8 d3 h0 i, k+ u) W8 B' i
signal S_Reg : std_logic_vector(8 downto 0);
4 R! m+ P7 y0 ?  `) [5 ?1 V) I  Csignal PS2_Clk_f : std_logic;2 Y- b+ g% D0 n: G8 c! J# U
Type State_t is (Idle, Shifting);
7 c0 J/ C. s1 h# Hsignal State : State_t;/ P. s  S; y/ C! h+ |# N6 Q
begin& B) V. d, ~9 ]* p  p
Scan_DAV <= Scan_DAVi;# ]8 K9 ^8 F( H# ~
-- This filters digitally the raw clock signal coming from the keyboard :  Q+ c+ d  l  V. J: m2 G/ H
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high" x* M) u/ e0 }! |
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low
' r# j3 {2 I/ e, |  K+ z-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data( [8 u& M! k6 R: w; y
-- Also in charge of the re-synchronization of PS2_Data' z1 _2 O: W: L8 ]$ q' k
process (Clk,Reset)
0 X6 j; h! X, F' o6 w; q: i* zbegin
; D- f& d7 V: q0 oif Reset='0' then) d! v9 N; s+ L. U- Z
PS2_Datr <= '0';  u0 M* \  i6 F; }% ]; D  q
PS2_Clk_f <= '0';
+ x  A' m/ e/ n8 A; SFilter <= (others=>'0');' {6 _1 s6 q6 l; }! e5 F1 [! t( K
Fall_Clk <= '0';2 d+ D4 t- l0 T; P6 V: v" j) Z! z: I8 t
elsif rising_edge (Clk) then
' c. O' D& I4 ^$ i4 w9 p. YPS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1') _) T9 }5 `0 B* Z2 f4 l; P& ]
Fall_Clk <= '0';
" }$ r  A( p& {* a( {2 @Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
% v4 F6 X' c' `* C' n2 eif Filter = Filter_t'(others=>'1') then
3 Q  T: `/ k' Y% O, mPS2_Clk_f <= '1';
- o2 m8 }" U9 ~elsif Filter = Filter_t'(others=>'0') then1 w' |7 @1 O# N) l! u
PS2_Clk_f <= '0';
% s( m8 |/ D% p1 L7 m% _if PS2_Clk_f = '1' then: d" |2 |/ H+ }& x
Fall_Clk <= '1';
9 M, p# E6 n1 o; f9 Y7 x, `end if;
5 f2 P$ E/ ^  @8 E' z0 nend if;$ T, D" q3 \) J# ~. E& \5 c5 c
end if;
' {7 e, [) p0 u  O( H" ]8 `) `% v4 b9 xend process;
% ]7 R9 G# B3 b$ H9 `% b8 m5 ^-- This simple State Machine reads in the Serial Data( Y& A& W* G' A0 U- n) P! p2 m* @
-- coming from the PS/2 peripheral.' j9 |4 j3 e/ {0 @3 h) [
process(Clk,Reset)
( {( K, T8 K$ A$ w2 J6 X  s2 xbegin7 Q" B7 D3 u* s" y6 Q# j$ D
if Reset='0' then# t/ B2 f  l; u& C
State <= Idle;
, }& R" ^+ ~9 Z' P: d* fBit_Cnt <= (others => '0');
& \) ]$ P+ a) i/ O9 U) nS_Reg <= (others => '0');
% J0 s6 p2 A3 Z' `6 NScan_Code <= (others => '0');
* {) n. t2 N* x* B% XParity <= '0';  X5 t) |- z6 n6 s5 Z: G
Scan_Davi <= '0';
4 e2 r7 y9 C2 I, G7 QScan_Err <= '0';+ s- @/ h2 z  N' l, G5 O9 L
elsif rising_edge (Clk) then# ?4 D( ^' Z4 p
if DoRead='1' then* g* h0 I5 h/ }
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden
3 G, x  _( o; p- @. N. A6 K4 @9 cend if;
! z4 E4 X. p& C- d6 h) Wcase State is* @3 x/ c) O6 R  C
when Idle =>
) |" y; M6 ^. j2 t/ m6 \& ?! i& h! h, qParity <= '0';
, F( |0 a9 a! |5 P' W* N- M9 hBit_Cnt <= (others => '0');8 x9 X  f5 Q" J; e& E
-- note that we dont need to clear the Shift Register
) l$ p$ m: S, k/ U3 w2 A8 i% x: kif Fall_Clk='1' and PS2_Datr='0' then -- Start bit  M* Z* C& s/ Q5 p$ i% |9 Q
Scan_Err <= '0';2 D  [8 D- ~& i0 `' C
State <= Shifting;# }9 U8 |2 {, _- T5 M
end if;/ |/ j, Z4 E2 O/ g
when Shifting =>5 W: O( B! T! E5 F) Q
if Bit_Cnt >= 9 then
. f1 R/ D$ i6 `6 Kif Fall_Clk='1' then -- Stop Bit5 ^+ U( ?& F& H9 E% P# y
-- Error is (wrong Parity) or (Stop='0') or Overflow
' i) K3 {9 q7 W( Y/ |9 WScan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
0 E5 _/ e: U" n" C1 D, _* FScan_Davi <= '1';1 I' e5 z5 w/ [6 |& l
Scan_Code <= S_Reg(7 downto 0);
; i% N) }0 x8 S3 fState <= Idle;
9 k. f- [3 C5 c0 Z1 J# \end if;$ M0 z. l6 l; g" r. y( F
elsif Fall_Clk='1' then
1 g5 j8 t7 z' G& F/ j' d9 R8 W& oBit_Cnt <= Bit_Cnt + 1;
- {) f/ ^- K- ?( BS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right7 a$ F7 L2 b1 N. ?
Parity <= Parity xor PS2_Datr;' f: u5 W/ R1 W* z' W
end if;
- y5 K6 E" s' e1 u' ?# ewhen others => -- never reached3 n# A1 L+ c. n, p" q
State <= Idle;* n8 [& G) q% d5 P. N9 w+ F
end case;
( C8 G4 r4 B% y) Nend if;# L8 A# y# X4 x9 u6 t! v( P4 e1 g- U
end process;
/ `8 J7 h2 b4 Q( j$ D: M7 bend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-20 03:54 AM , Processed in 0.100513 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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