Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4424|回復: 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
& ~. g4 T7 ~# ^' m: o5 X
; U7 S# i4 H8 o程式如下:( {! u; \8 \0 b$ }- h
-- PS2_Ctrl.vhd
. X7 ]& ~; k$ ~-- ------------------------------------------------9 n% u8 n' o% D0 x2 O
-- Simplified PS/2 Controller (kbd, mouse...)& ?3 z7 k3 ?  z9 o6 p
-- ------------------------------------------------
  P, z8 K7 I# O/ D8 S-- Only the Receive function is implemented !
7 H& c- p$ h% u( L+ y, X-- (c) ALSE. http://www.alse-fr.com6 _' b/ d# j- E( m
library IEEE;$ q! O8 V& M6 o. r* B# O9 g
use IEEE.STD_LOGIC_1164.all;0 g, b6 w4 J3 c. x
use IEEE.Numeric_std.all;
8 A6 C# g/ c9 X5 I' Q$ Z% [-- --------------------------------------0 x; {; f$ Z- X: o0 g- p3 a1 b
Entity PS2_Ctrl is+ o* ?3 G, A3 Y' `, g: R
-- --------------------------------------6 Y1 U, E8 J' U) C( v
generic (FilterSize : positive := 8);
( }  f6 _9 q& J) |7 _+ a$ a8 d! x+ Aport( Clk : in std_logic; -- System Clock
! ~/ O3 b8 f7 O1 u$ v. D! wReset : in std_logic; -- System Reset
5 t* z& f# G5 T1 p$ F2 @8 b% Z" EPS2_Clk : in std_logic; -- Keyboard Clock Line8 m) Y1 r0 z: T* h7 V4 l' r
PS2_Data : in std_logic; -- Keyboard Data Line
0 f7 h/ P0 ~; A* c, c9 j* T+ VDoRead : in std_logic; -- From outside when reading the scan code* k' M6 M; m( e6 |5 {( ]' y
Scan_Err : out std_logic; -- To outside : Parity or Overflow error7 g5 C6 q4 z  u! W
Scan_DAV : out std_logic; -- To outside when a scan code has arrived% L3 }# q3 D7 A8 ?5 u# ~
Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out1 y0 Z3 [3 p) ~  J
);
. q# i2 k$ L+ \% S. |' k! Nend PS2_Ctrl;$ Z3 \  ^& h" d0 n: A
-- --------------------------------------
# s2 E, v! Y8 a8 F8 s- jArchitecture ALSE_RTL of PS2_Ctrl is
8 D1 |% K8 y5 T-- --------------------------------------: X3 C0 ?# S& G
-- (c) ALSE. http://www.alse-fr.com/ w' n8 p) `6 F8 u4 t: A5 E& O& c* |
-- Author : Bert Cuzeau.
  T( j+ b4 x, T1 y-- Fully synchronous solution, same Filter on PS2_Clk.; x7 m& D* I6 w. Z: M+ h2 }6 F$ f( d
-- Still as compact as "Plain_wrong"...
8 G7 B1 W; W7 ^. Z1 w8 |1 Q-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
+ Q5 l5 f2 p$ F-- Note: PS2_Data is resynchronized though this should not be
! H4 B7 E6 `. \, j* y-- necessary (qualified by Fall_Clk and does not change at that time).
$ W4 h: F9 Y# ~4 `+ V9 s4 l8 X-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation." y; a5 w8 N2 X! s  T
signal PS2_Datr : std_logic;- Q9 @. f: n  X* I' I, r
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
1 z, l: s1 J# v0 X6 ]# a/ ]; vsignal Filter : Filter_t;
# L' d: b- g" x( j4 ]- B8 ?4 S. Dsignal Fall_Clk : std_logic;
- F5 Q! V, ^# D4 |; `6 ]! bsignal Bit_Cnt : unsigned (3 downto 0);6 v9 {7 J# x( i; D
signal Parity : std_logic;" ]! Y& ^3 U) A! ^$ E* L
signal Scan_DAVi : std_logic;
4 w; J4 S6 e1 x2 v. R# d+ T* n% Ysignal S_Reg : std_logic_vector(8 downto 0);1 _: T% B  `5 g6 t9 i7 F
signal PS2_Clk_f : std_logic;2 ]/ m8 s5 y- N# X, [/ e& q7 T
Type State_t is (Idle, Shifting);8 n9 B/ }4 u( e6 e$ h- W5 j
signal State : State_t;! j' E- z5 o  i# O4 Q
begin2 u+ Q! k: k) `+ m) m% {
Scan_DAV <= Scan_DAVi;
1 [* o7 p7 A0 b4 l9 ^2 {9 |9 [" J-- This filters digitally the raw clock signal coming from the keyboard :  H: i) L- I0 ^8 k9 ^5 ?
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
9 c4 q  h. Q1 B-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low8 g/ ~0 y5 h/ y0 C
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data+ \! A2 y1 M( Z4 H$ z
-- Also in charge of the re-synchronization of PS2_Data
: ~$ n2 [$ m. S- t) Yprocess (Clk,Reset)! U& y$ |* p& q$ m9 M
begin
# o, a* Q( h  j: rif Reset='0' then' g% Z/ M& J2 A8 l) _$ u
PS2_Datr <= '0';1 _1 L2 C5 Z2 X7 D: Z0 r
PS2_Clk_f <= '0';
5 E2 x3 C* V' e0 l3 UFilter <= (others=>'0');
$ r' b, R  v7 YFall_Clk <= '0';
& \/ H8 s) l/ N9 G1 _elsif rising_edge (Clk) then
' v8 {3 ^4 `. W" |5 Q! O, u$ jPS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'
+ `& F3 ~# q1 g2 P4 fFall_Clk <= '0';
* k# L' B9 d( e  f: U7 lFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
" n+ o0 A7 a2 m+ B2 [0 Jif Filter = Filter_t'(others=>'1') then4 b7 I5 ^# q6 K3 Z9 a) z  e
PS2_Clk_f <= '1';2 g) q9 `# U, t- s
elsif Filter = Filter_t'(others=>'0') then2 m3 L/ @3 b1 \* g# L( B1 s
PS2_Clk_f <= '0';8 e: f! ?7 J4 S" m
if PS2_Clk_f = '1' then
, n6 j3 f6 ~/ @9 N5 m7 vFall_Clk <= '1';+ T( _4 A9 W8 ^' k+ B5 G
end if;
. n/ l$ d. V# E- }9 hend if;/ X! d# F" e9 E+ z2 w4 T" D
end if;. M* b6 `) _9 ^# d$ b' v% _
end process;: \8 m! b# t. o0 L+ e( Y: Z
-- This simple State Machine reads in the Serial Data' c9 H& @0 `1 t" P  g
-- coming from the PS/2 peripheral.- w# k" E; [: F2 Q9 d
process(Clk,Reset)
2 j( n) N5 W/ a, g) `; ^8 ?begin
3 Y6 ~" i6 u. |if Reset='0' then
; ?' t$ x$ c0 n5 b+ c# c% gState <= Idle;
! ~, O+ o$ P, e$ G  Z7 v/ {* GBit_Cnt <= (others => '0');
, U; s. `9 n8 v( t; _S_Reg <= (others => '0');9 J' ~6 _5 E3 Q- k5 D" I" \7 \2 j
Scan_Code <= (others => '0');
3 `0 V" ]" W2 A9 N5 E+ |$ \0 @Parity <= '0';
9 ~* t9 O( |& a. \5 DScan_Davi <= '0';
2 s, `" Z6 i8 L1 q+ H7 A' LScan_Err <= '0';
- l' W$ g6 p5 w. b* melsif rising_edge (Clk) then
& _/ N) n& m' a8 ]4 y: Z4 kif DoRead='1' then( G7 d: d* f& E. W' Q3 H$ p
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden
5 z$ @( R3 \; q( x* @8 aend if;
, M" D5 F- m0 j1 J& _case State is7 p; N  S* C4 \. a$ y1 Z
when Idle =>
% Z, ?6 V% f- ?5 d" A: k# hParity <= '0';
: p1 e$ A6 r% R( M( FBit_Cnt <= (others => '0');6 s4 G8 n; j/ f7 c9 ^3 C) `6 n
-- note that we dont need to clear the Shift Register2 N, f% n, L. {6 h) s! c- X+ @
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit" ^/ n1 i  R- `2 f. `+ U2 D* w2 E
Scan_Err <= '0';
( ?" D! [" }8 S4 z, QState <= Shifting;) q& v# B8 \0 Z6 s
end if;- Q" s) y  U1 X% i  s8 C
when Shifting =>* W: p8 f6 @9 Z  E7 U
if Bit_Cnt >= 9 then
# G" A) {: A! Y. d* pif Fall_Clk='1' then -- Stop Bit- l7 }  i1 _9 t$ B
-- Error is (wrong Parity) or (Stop='0') or Overflow1 Y+ Q1 k7 E' N8 d5 J+ O# p: K. y8 t
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;( S$ a1 z# h3 B" d+ A1 n
Scan_Davi <= '1';
) c( V  g; k7 D0 X1 e$ mScan_Code <= S_Reg(7 downto 0);
( h% Q* f4 m" h! H( E6 y3 c* TState <= Idle;7 s3 s. `/ e* `) e! j5 F
end if;5 }/ M/ |% S3 c* x* O
elsif Fall_Clk='1' then
8 R  V  X# b, [7 }: }Bit_Cnt <= Bit_Cnt + 1;' b! ?1 h. [3 r  P% F2 Y& S* x
S_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
: q7 z9 L6 K3 h1 Q: P0 R1 v/ fParity <= Parity xor PS2_Datr;
. C! e" A  b1 k8 nend if;
  K- ~2 a7 O. M: z% `' a+ qwhen others => -- never reached3 |) C7 g5 g3 C7 Q% B
State <= Idle;- j! q4 B7 o0 F+ B5 H! z( P7 @
end case;
4 J& n) w+ X: Q9 I. j7 Aend if;
; n& m- i* O! W# y' lend process;& o  Y$ w, I. K  W, p
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-4 04:48 AM , Processed in 0.096005 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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