Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4484|回復: 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
7 x# I" I- O8 X, N' y, S
$ G- N9 n% X! ]7 N) g( |程式如下:
- {' |2 _( x2 p3 ]: {3 e' h- k-- PS2_Ctrl.vhd
$ r# u) M3 I7 B' A" Y2 A-- ------------------------------------------------
/ i/ o( @  T/ ^; G: H! R-- Simplified PS/2 Controller (kbd, mouse...)
# u* K! N8 y0 _-- ------------------------------------------------
/ z% d2 N2 V/ t8 s/ `; r6 U-- Only the Receive function is implemented !
; X- E9 W1 ^' Z2 X0 v* {! U-- (c) ALSE. http://www.alse-fr.com9 Z3 }! i: z9 p* r2 t
library IEEE;" Q. k" |: C8 _' b
use IEEE.STD_LOGIC_1164.all;# h8 E+ Y, G8 L$ Y* J* \* k
use IEEE.Numeric_std.all;$ p+ [/ g, S& D3 P' e) i
-- --------------------------------------' t; `9 B2 X7 G" ^7 |. x/ Q4 R" d2 k& c
Entity PS2_Ctrl is
2 C- {1 W, m9 Y7 {& M7 y-- --------------------------------------9 o7 R5 a  v8 I
generic (FilterSize : positive := 8);  K4 x" V/ Z: H7 e( w# D5 P; s
port( Clk : in std_logic; -- System Clock& D( o1 w/ a5 v3 u7 x1 Y$ e/ U
Reset : in std_logic; -- System Reset8 c4 A! v+ O3 S, ^
PS2_Clk : in std_logic; -- Keyboard Clock Line4 E8 F, T' _- I5 o' c* x9 V
PS2_Data : in std_logic; -- Keyboard Data Line
! z6 j9 w5 `  L9 U( nDoRead : in std_logic; -- From outside when reading the scan code, Y, g7 V# [5 r
Scan_Err : out std_logic; -- To outside : Parity or Overflow error! h5 F6 o* j% S7 p) O7 w8 C5 b+ _
Scan_DAV : out std_logic; -- To outside when a scan code has arrived
& c7 A) U8 b; Y( Y8 }# W- @Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out% f( W- S5 f1 H( O, Y7 D; w  E
);
- g, Y: D5 b! W- s( j- E6 _4 I, p5 p* eend PS2_Ctrl;2 J; e' @$ j" P% `) j
-- --------------------------------------
8 T7 C! @$ c8 Z$ F0 k- kArchitecture ALSE_RTL of PS2_Ctrl is5 |( \$ D7 a' G( U( N
-- --------------------------------------: w1 h1 l, n5 @/ ^/ x  R" f& d( N2 u% ]
-- (c) ALSE. http://www.alse-fr.com) d9 _8 v% N* d
-- Author : Bert Cuzeau.
, N# @" T1 l8 f0 n, [-- Fully synchronous solution, same Filter on PS2_Clk.
0 \0 P9 f3 v- l5 r0 C-- Still as compact as "Plain_wrong"...
4 N' V7 ~9 f" ]  E-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
5 M0 t0 S4 c4 t# n-- Note: PS2_Data is resynchronized though this should not be2 `  E8 \4 [! Y6 R0 e
-- necessary (qualified by Fall_Clk and does not change at that time).5 D4 C- n4 N" x0 F9 @
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.
! j5 \1 n2 ~+ rsignal PS2_Datr : std_logic;2 f, i! z/ `8 F
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
" E& V  h1 G  Lsignal Filter : Filter_t;
* I' l2 D/ q7 g% D# e( R9 Ssignal Fall_Clk : std_logic;
$ O5 t: b3 `' Gsignal Bit_Cnt : unsigned (3 downto 0);* o: O0 l: z1 J. l
signal Parity : std_logic;0 z' @. M/ \  t) T; }/ m1 e# I
signal Scan_DAVi : std_logic;
" G& M; i7 C2 F, Q$ Q8 p) n: ksignal S_Reg : std_logic_vector(8 downto 0);
8 H0 v* ?, q3 bsignal PS2_Clk_f : std_logic;
, l! h+ x' v' G/ l! q+ mType State_t is (Idle, Shifting);9 O0 c/ \/ @* E* \! |6 p$ C5 y9 _
signal State : State_t;
8 s" W/ E9 ?: L. N9 o# |: wbegin
( p9 w: T# V8 ^. Y0 ~7 sScan_DAV <= Scan_DAVi;
6 \( |* V5 e7 a; x5 i-- This filters digitally the raw clock signal coming from the keyboard :2 _/ @* [6 U1 }
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
. P8 c, q% p1 A; v3 ~1 {-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low
9 p& ?! y$ g2 B6 X/ H$ \-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data
" N: s3 O$ ?1 ~* u! V5 e" u/ Z-- Also in charge of the re-synchronization of PS2_Data4 e2 p- N+ s1 D7 D6 q% \
process (Clk,Reset)% L$ F6 L# ?3 L: h2 r; b1 [& v6 ]) g
begin
4 k, n5 B' p& ]! m" Z5 q/ Gif Reset='0' then
8 B4 {5 g" G" F' X- a& n# v" NPS2_Datr <= '0';3 A. |' h' h5 [2 p. E
PS2_Clk_f <= '0';
7 m& ?/ X9 F0 \5 w+ @6 IFilter <= (others=>'0');. X. |7 |# j& {6 [6 w. S# F
Fall_Clk <= '0';
" Z, K3 t2 ^" }  V' Xelsif rising_edge (Clk) then
4 E- `, d: s( T; h5 s/ c* ^PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'" i. t) Y/ Y; ?% ~
Fall_Clk <= '0';
9 Z5 F7 ^7 X6 K) j+ D3 JFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
# n  m; a, X! w& p# _& d# Hif Filter = Filter_t'(others=>'1') then
$ l5 {; ?  j/ R8 A- hPS2_Clk_f <= '1';
) X# O6 ?2 w9 Helsif Filter = Filter_t'(others=>'0') then
! g; o$ R0 n) [6 e) H3 dPS2_Clk_f <= '0';
3 A8 D- i2 L; Y- m/ \' B2 rif PS2_Clk_f = '1' then
; K7 E  ~! s) u8 yFall_Clk <= '1';) f0 d. ~. I" h4 n$ Z1 L# B2 o
end if;3 y! c! H7 B! g( t
end if;
& Y3 P7 ?8 B% y  s1 Tend if;" R) x" f" @. h% s8 a
end process;1 Q6 |5 \# M; j0 w, W
-- This simple State Machine reads in the Serial Data! S% y5 y( H5 X7 P* h1 |
-- coming from the PS/2 peripheral.2 ^# I2 O/ Q7 j
process(Clk,Reset)
1 W2 m; J' \- s; Wbegin
7 s* c3 f3 Y9 C, |* nif Reset='0' then
- R* H' y% k. q5 NState <= Idle;
) x. A8 d  ~) E5 sBit_Cnt <= (others => '0');
5 R6 N8 R# q) Y9 ^* SS_Reg <= (others => '0');' K# `$ C/ `+ l
Scan_Code <= (others => '0');
# _. l# Z. E/ j" y$ q9 KParity <= '0';& _# x* }5 I/ _, m7 |
Scan_Davi <= '0';! u; ^& _: r8 F: Y" C
Scan_Err <= '0';
) e, q; `0 p. d, w3 @% Felsif rising_edge (Clk) then
! y4 S2 f0 ?3 y. o. z* eif DoRead='1' then  G/ ]) o0 k  ^! \
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden( A# l( ^- y6 k7 h' C
end if;
! {, b5 \- A. b; ccase State is
/ F% _5 y! ^- E; Q* B1 H1 T- Gwhen Idle =>: i# F. i  z2 ]8 e( i) r
Parity <= '0';
. H+ k' K; l5 K/ K; OBit_Cnt <= (others => '0');$ A3 j% a6 V9 d/ x4 p% E
-- note that we dont need to clear the Shift Register" r$ D1 }* q; t  k( l, v4 L
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit% B0 K, _2 m. z0 y% @7 W
Scan_Err <= '0';
( h* R8 R$ A3 ~8 x4 lState <= Shifting;" Q# J* s+ o# ^3 \8 N  z/ [* G
end if;
% e. A& u7 U, |8 w& ~$ x4 qwhen Shifting =>
& U1 c! {1 N% l# xif Bit_Cnt >= 9 then
  \+ f8 A% R" Cif Fall_Clk='1' then -- Stop Bit
* ~3 o; ~' r0 L8 W4 T) X-- Error is (wrong Parity) or (Stop='0') or Overflow
) l. p& }7 Y7 ]1 hScan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;& [/ j" @! ~, d" p& I/ Y4 S) p
Scan_Davi <= '1';
) Y* y0 Q6 m3 R4 u' {2 aScan_Code <= S_Reg(7 downto 0);* q+ O& i8 u; L/ r4 l  y5 b% a8 F1 H
State <= Idle;
& v1 p/ B6 m$ }1 ?1 B0 Bend if;( W' A9 w+ A% e1 J' O
elsif Fall_Clk='1' then7 S$ d6 e/ g5 j3 r- m$ h; Z
Bit_Cnt <= Bit_Cnt + 1;7 E/ C  F2 o' Y' n# ]
S_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
* ~* f6 F1 d7 P3 L3 A  I) pParity <= Parity xor PS2_Datr;
+ v4 n9 S; Q, w% C6 e- Dend if;
5 o8 m! m4 ]8 {: r  h% [' y8 a6 {when others => -- never reached
4 A% N5 T4 @1 D5 G5 |% I1 c3 MState <= Idle;" g6 w5 Z( H% e; N
end case;' S- E4 J  _7 @, P4 k: [
end if;
9 [+ p/ H2 B( E9 Send process;5 t* D1 z+ V5 ]1 \9 M/ m
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-16 10:18 PM , Processed in 0.145018 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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