Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4423|回復: 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
) w( q' s8 J4 A" w: R  E) n& L' K# }# |: R
程式如下:- ~3 O% q! X/ j; S
-- PS2_Ctrl.vhd( G* F( ^8 Y% ]5 K5 F3 _2 W" e
-- ------------------------------------------------3 |2 m' m8 v- H  G/ r: [% n
-- Simplified PS/2 Controller (kbd, mouse...). @# E2 @+ a' z9 U6 N1 x7 B  g( ^
-- ------------------------------------------------
$ v% W5 `8 M- P6 T; R+ V-- Only the Receive function is implemented !$ q4 y  W  R1 `* i+ I
-- (c) ALSE. http://www.alse-fr.com6 j6 J, m/ l- p& Z
library IEEE;
+ H  d( b- D4 r) {: guse IEEE.STD_LOGIC_1164.all;1 h+ j5 W0 }/ |
use IEEE.Numeric_std.all;
. y; ?& h( Y8 K; l7 P, q3 l) j-- --------------------------------------
+ R8 f& n( e" I: ~& F) _Entity PS2_Ctrl is
3 m2 U  J- o1 ^4 g) l' z9 g-- --------------------------------------
9 p* O6 _/ I9 R% \generic (FilterSize : positive := 8);
" s6 d+ F& y9 Gport( Clk : in std_logic; -- System Clock5 Z$ g$ [" f+ Z% {, p
Reset : in std_logic; -- System Reset6 f  U1 j/ |5 E; D7 S6 H4 D( w
PS2_Clk : in std_logic; -- Keyboard Clock Line  ?- {# z# S; f; J1 v3 G- `9 T' M9 w
PS2_Data : in std_logic; -- Keyboard Data Line
4 N+ }) @( t' X9 zDoRead : in std_logic; -- From outside when reading the scan code3 R5 B) {# _0 V! E# t0 k: I
Scan_Err : out std_logic; -- To outside : Parity or Overflow error1 L& T8 c% p. y; U
Scan_DAV : out std_logic; -- To outside when a scan code has arrived! o0 Q: F3 U: M
Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
: B+ D+ F5 _" z. \);
6 i* a+ L$ K/ x! z2 x& Yend PS2_Ctrl;! L! C- l7 g3 V$ _6 g4 N! `+ N/ G* t
-- --------------------------------------
4 Y. |  |$ m8 Z5 R, W3 bArchitecture ALSE_RTL of PS2_Ctrl is
1 p4 I; n3 K' W+ v5 G7 x! a-- --------------------------------------
  f6 g$ h/ x% b& B* z7 c' h-- (c) ALSE. http://www.alse-fr.com
, B6 j; x$ N% y-- Author : Bert Cuzeau., |7 R' J. ~' T* S& R) U2 W
-- Fully synchronous solution, same Filter on PS2_Clk.
( Y/ f" S, X* m  ^-- Still as compact as "Plain_wrong"...
( N  J5 O  k: B, y2 }-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
; Q0 g7 ^6 G) S& K; F1 C) v-- Note: PS2_Data is resynchronized though this should not be$ L" k/ p$ n4 r
-- necessary (qualified by Fall_Clk and does not change at that time).8 J( |) m" C' D' N# p
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.9 M' P, I9 Q9 V. `( [& M" v/ J
signal PS2_Datr : std_logic;- m5 S8 [6 |! H" S9 V0 {
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
, t! S- S% Q; w9 n0 _" csignal Filter : Filter_t;
0 ~: a" b1 z4 [: Isignal Fall_Clk : std_logic;; m: X0 R7 d" r* N
signal Bit_Cnt : unsigned (3 downto 0);( K: c+ s" x+ F# I
signal Parity : std_logic;
! L/ x( O8 q( F. D, x& Ysignal Scan_DAVi : std_logic;3 I2 J- H9 k, o8 a( E- @" y
signal S_Reg : std_logic_vector(8 downto 0);5 |. ~# ~. H2 T( B. d' m$ L/ E
signal PS2_Clk_f : std_logic;
8 q$ e$ S2 ~# J- o- E  |Type State_t is (Idle, Shifting);
2 Q2 g9 ~! ^3 Gsignal State : State_t;
, K3 X# J' ^8 ]0 Obegin
  C  U2 N) R; P0 [" e9 mScan_DAV <= Scan_DAVi;
4 t" z/ ]! N9 e1 m- p0 w7 ^-- This filters digitally the raw clock signal coming from the keyboard :
( K/ O+ k4 i5 w-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high2 i, u& `5 u: E. f
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low( z9 p! _1 J0 P7 v# v+ J' A0 K) t
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data
$ }# n6 X! O. ^9 N-- Also in charge of the re-synchronization of PS2_Data
( ^; n9 }: K( w9 j" R9 O& e6 Kprocess (Clk,Reset)
! {; }1 Q5 S/ p0 Kbegin
6 G9 V  P9 ?6 i* R* Z! d0 p/ Lif Reset='0' then
+ P, f/ U! d, |PS2_Datr <= '0';  e: r; {! _% J# O, f# ]% [) s
PS2_Clk_f <= '0';9 B2 T2 O  o; ~  B$ m% H0 E* Y3 T% q
Filter <= (others=>'0');" l: {& r" I# p$ g: R: i' X: o
Fall_Clk <= '0';' k) ]# n) L: f" k  A! y
elsif rising_edge (Clk) then" z7 L0 r; e. U/ Q! S% J% V
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'
' f1 j) F/ J2 Y. OFall_Clk <= '0';
& n+ N8 y% V! p/ m9 cFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
+ C3 [) s1 }8 r. Q* b; _if Filter = Filter_t'(others=>'1') then  u: Z4 G2 p" F  F7 a$ C
PS2_Clk_f <= '1';
, j$ ^" v0 Q9 D/ M3 R8 velsif Filter = Filter_t'(others=>'0') then! m% P  w, i; k8 H3 G
PS2_Clk_f <= '0';
0 u/ F3 t( B  w, L- I; Q6 ?if PS2_Clk_f = '1' then
* o$ S3 n& s2 G: t# U1 m  aFall_Clk <= '1';
; R5 y6 R" i! a1 zend if;
4 H5 Q7 D; J5 G8 W5 tend if;, S: b( h& O) z9 ~1 n! ^1 i, f
end if;
0 S1 S, K- Q" g" g, q% h- N2 @0 cend process;1 k! x/ B1 u& Z: {8 Z  {  t
-- This simple State Machine reads in the Serial Data7 R2 H/ s- K1 n( R2 L$ S
-- coming from the PS/2 peripheral.+ p/ _& x; z- C" |
process(Clk,Reset), _3 ^, F( s, Q) [) M8 ^6 H' {2 y* r
begin. [+ b% P; p) h' E8 z
if Reset='0' then
# p, q& U: s* m( ?+ N3 ?" z/ NState <= Idle;7 m: X$ s& D. b" i2 V& s" A
Bit_Cnt <= (others => '0');
/ [" T! C+ I+ }# B2 _( tS_Reg <= (others => '0');
0 o8 n" e- S+ x% BScan_Code <= (others => '0');( Z" X$ _0 T- M8 a9 B, e- v
Parity <= '0';
7 o. M  X$ d9 `( Y% ]Scan_Davi <= '0';
2 Y, o6 [2 G+ x& @Scan_Err <= '0';
# R: m4 H; u  ^& a$ Y6 relsif rising_edge (Clk) then
5 d6 E( x7 R% m* j3 q$ Lif DoRead='1' then0 H2 l8 ?; p9 T9 m8 @
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden( V5 b9 _1 k1 J+ V4 F
end if;; z  x4 m/ r0 Q& ]7 Z2 ~6 O
case State is( P5 E* e1 E) b  d3 ~5 N
when Idle =>( U5 \. L/ t* b/ K+ B( w
Parity <= '0';
, X* u  V5 R$ N3 FBit_Cnt <= (others => '0');, l  E) x( V: `& C% B
-- note that we dont need to clear the Shift Register% f  Y+ @! A) S( [+ M# k" \
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit- ?5 O+ U+ f. z( X& \' m
Scan_Err <= '0';
+ v$ P2 b2 ]* B8 nState <= Shifting;6 g! W* a% w6 X6 P  q; E7 p9 S$ u
end if;, x7 W* [3 q1 A- S, E
when Shifting =>4 p' i6 L/ D2 Q1 b. d* X( \
if Bit_Cnt >= 9 then
2 j% u! u& J$ q& @& Hif Fall_Clk='1' then -- Stop Bit
9 B6 Z% f/ \* j7 E4 o* b-- Error is (wrong Parity) or (Stop='0') or Overflow3 h! O( U8 y$ ~9 n
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
* ~  Y! E7 p# g) aScan_Davi <= '1';% n: b# h' t8 A' n/ w, r
Scan_Code <= S_Reg(7 downto 0);
4 c" n  Q& a, ~0 a: J, X4 v9 KState <= Idle;7 }! V) f4 Z9 E4 U
end if;
7 t" k& a! t& i, B5 g: l3 @! E# Ielsif Fall_Clk='1' then
# H  K, _: _' n, @4 O5 fBit_Cnt <= Bit_Cnt + 1;
; l* L5 l4 ^/ u! y# hS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right, ^; G$ Q+ S; W: O7 e5 U
Parity <= Parity xor PS2_Datr;" _- X8 g# C+ q* w$ |; V3 x8 v" y$ S
end if;. A$ I" Y; H& }$ N+ d
when others => -- never reached* A" t" T& A% L+ d- D& ^  @8 G
State <= Idle;
4 v5 \- a0 u0 B+ ^' q# z* dend case;0 S4 K9 f6 P; R
end if;& F0 w, u7 A9 D" a# c; S- Q
end process;
- D3 c' Y( O0 k; L( U- dend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-3 08:49 PM , Processed in 0.100006 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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