Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4418|回復: 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
3 F$ `7 ]/ L! C$ D6 F3 ?# c. q+ @% v: e6 \/ w/ k
程式如下:
& U$ J- y/ w, G9 [" d-- PS2_Ctrl.vhd$ F( O; ]9 ^- ^/ @
-- ------------------------------------------------+ Z9 k' ~, J3 o" o% J; K
-- Simplified PS/2 Controller (kbd, mouse...)
! A: y- W7 X' M' x/ D2 h-- ------------------------------------------------
1 X1 F' V, ]) u4 ^-- Only the Receive function is implemented !
8 C; l1 \- n0 u$ I, l( U2 f' K5 N-- (c) ALSE. http://www.alse-fr.com  J' Z6 W$ [8 m& L
library IEEE;0 L* B4 y9 _) ^4 i: o
use IEEE.STD_LOGIC_1164.all;7 m/ ?0 D1 F& C0 s5 h
use IEEE.Numeric_std.all;
0 S/ m7 J. R/ }1 F-- --------------------------------------
  k" ^7 T5 v6 f: p1 KEntity PS2_Ctrl is
; ~$ d# P8 k6 z: i4 P  A-- --------------------------------------0 t8 P2 m. R% y- c  r/ D/ e2 d
generic (FilterSize : positive := 8);
) n0 A1 ^1 }+ l& q$ b- uport( Clk : in std_logic; -- System Clock
0 [2 q) A! Y& Z% PReset : in std_logic; -- System Reset; _6 V8 m  H. L3 J
PS2_Clk : in std_logic; -- Keyboard Clock Line
' V7 r! M6 r; O# Z" L4 H% n# ePS2_Data : in std_logic; -- Keyboard Data Line
/ J3 S0 V3 R! h3 q9 y1 {DoRead : in std_logic; -- From outside when reading the scan code
8 B7 d, f7 n7 rScan_Err : out std_logic; -- To outside : Parity or Overflow error7 X  H* b! Z% M& M
Scan_DAV : out std_logic; -- To outside when a scan code has arrived
) X1 w) b+ G. k/ b* v; {Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
5 N% l0 j; X; A+ q7 Z6 Y);# v+ M# E4 ?" ^% G
end PS2_Ctrl;
2 G/ _/ t! l$ X8 \2 y9 u- H; M-- --------------------------------------7 W) M% F& c8 ]- t1 Z! B
Architecture ALSE_RTL of PS2_Ctrl is
7 ?, C- L, J0 r. H$ E-- --------------------------------------
4 e; g$ }  O0 d. z-- (c) ALSE. http://www.alse-fr.com; z9 Y3 t4 t' o3 K# J* R5 l( p# K
-- Author : Bert Cuzeau.
* }* Z# U7 w1 _( m, }. A+ w-- Fully synchronous solution, same Filter on PS2_Clk.
/ z5 O9 U! u3 t, k5 Z-- Still as compact as "Plain_wrong"...  r8 ?& I& C4 ~  y9 D& F5 |7 J
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
" q$ v. Z: ]  L" @-- Note: PS2_Data is resynchronized though this should not be" W) T6 B* l6 W; k/ E  [
-- necessary (qualified by Fall_Clk and does not change at that time).
* v( c0 e, @) w% ]. @% m-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.) e: d) u: P( ?5 T  X  R
signal PS2_Datr : std_logic;- d8 U- g6 F2 A+ E
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
3 l; z; a8 n- C8 s& t5 r9 Y+ ^4 Wsignal Filter : Filter_t;
" @+ v! N) d% s- Osignal Fall_Clk : std_logic;# e5 e; l, E! a  o
signal Bit_Cnt : unsigned (3 downto 0);; Q8 u4 j: [, V- U
signal Parity : std_logic;( x8 @! L1 e5 c' l# \& h
signal Scan_DAVi : std_logic;% S: d1 Y. i2 H7 W, u) V
signal S_Reg : std_logic_vector(8 downto 0);9 a$ L7 ?" y( y; t
signal PS2_Clk_f : std_logic;
: @+ s# u9 x2 uType State_t is (Idle, Shifting);' r* Q' l6 q9 w
signal State : State_t;
5 d5 c% G: I# N; K/ T# o" ibegin
9 r" `8 b; i3 N4 }# uScan_DAV <= Scan_DAVi;+ b+ T. K- f. u# Z
-- This filters digitally the raw clock signal coming from the keyboard :' H5 {) W2 }. d  h6 b
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high5 Y3 M# h8 k: V$ s* F* d9 s& W5 d
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low
' Z/ ^9 e! n. h2 S$ l0 [* k-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data& G# f  U& Y7 \8 r- }- E5 l. g
-- Also in charge of the re-synchronization of PS2_Data8 P4 s/ C6 A5 k
process (Clk,Reset)
+ F2 E0 h9 ^, |9 [8 B! }& W3 Ibegin
0 C4 m  o) d4 D* }* k) L& Jif Reset='0' then0 S9 Y6 B) G& e7 r
PS2_Datr <= '0';9 {5 t" ^* c; X5 }
PS2_Clk_f <= '0';+ T* T6 a" }4 m
Filter <= (others=>'0');# z( V0 l8 Y; N% s
Fall_Clk <= '0';7 [- [, n1 }% `5 L, z% e: v3 k
elsif rising_edge (Clk) then
5 E  m. q2 j( N& B( m& QPS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'$ {: L# C! I  p7 I! k. M4 ^; _' k
Fall_Clk <= '0';
! H7 \- w# j8 f3 T5 K1 c7 h" {Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);- k9 M5 t) ?" X
if Filter = Filter_t'(others=>'1') then
0 x, Q, \) v1 @. NPS2_Clk_f <= '1';0 V& A& M/ e& O# ~; D4 `  v
elsif Filter = Filter_t'(others=>'0') then5 c( T  c; U) p1 i
PS2_Clk_f <= '0';
6 C8 H% E# Y7 {, ]% n* O) bif PS2_Clk_f = '1' then+ H% I1 A5 E. ^
Fall_Clk <= '1';
; t/ P% Y) o% ^4 J% dend if;  G4 s; S% Q- P
end if;: q# x: H8 z& i( C8 M; g
end if;
# ^0 F1 C( h0 b% q0 E. Uend process;
  _% s# Y  V0 X( a" u! b-- This simple State Machine reads in the Serial Data: b1 a( h! O/ l2 j/ ]( S3 A
-- coming from the PS/2 peripheral.6 O/ E6 {+ j8 I+ \; R3 ~6 R2 x
process(Clk,Reset)8 C' E' K" N: a9 V7 M
begin
. Z$ [% Q8 U! a& o; W* C4 jif Reset='0' then( V- z: X: L" x( _& B
State <= Idle;
8 _, R0 {1 e, b: bBit_Cnt <= (others => '0');
; D0 Z% e& c0 L4 P7 h! T  oS_Reg <= (others => '0');
7 s6 Q9 ?& h* V0 Y* a# ], S6 hScan_Code <= (others => '0');- G7 Y% ~# v8 g
Parity <= '0';2 Z+ A& ^* I( \7 Q6 p% Q
Scan_Davi <= '0';& C9 ~) m% r% q  h- X
Scan_Err <= '0';
, T1 V  i2 m  Z9 |elsif rising_edge (Clk) then
, X2 Y1 A: d, E7 Z% k3 vif DoRead='1' then$ g0 ~0 a) h# D
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden7 L1 M3 s. F, z" F: P
end if;
# c( J5 c1 A4 r. t7 D0 Xcase State is( `" G: e) h# G
when Idle =>
2 k* M6 [# n* V4 `+ S+ E) F1 k! _Parity <= '0';
  {9 ~+ R. h; l+ @Bit_Cnt <= (others => '0');* Q9 i+ V6 b+ |1 Q3 g
-- note that we dont need to clear the Shift Register
. U: ~2 q* o* W) y% yif Fall_Clk='1' and PS2_Datr='0' then -- Start bit
9 d& K1 X9 }, T- i0 v/ M# QScan_Err <= '0';, b& f& C$ e/ ~% O8 g8 l
State <= Shifting;
* f3 |4 b3 F. `1 o% N/ ]end if;
8 a& V" e4 R5 c1 zwhen Shifting =>
' @8 A. q! o4 k# q: M/ l9 m. W7 |if Bit_Cnt >= 9 then
  _+ }/ e: X1 l( y- d% L, p0 q0 uif Fall_Clk='1' then -- Stop Bit
# h: o+ [/ }! J* o1 b. d-- Error is (wrong Parity) or (Stop='0') or Overflow
  U9 x9 R( w& L7 S6 ]- L, gScan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;  z! y( I# O" k7 w4 J2 u1 I0 j
Scan_Davi <= '1';
+ ]: u9 p1 ?  [$ P, H) SScan_Code <= S_Reg(7 downto 0);
0 J7 f$ u- X# k( s4 a2 ZState <= Idle;, i$ X# O$ _" O) b% o( \' H4 b+ b# B) R
end if;6 Z: R6 z! r0 ?+ m/ I: I
elsif Fall_Clk='1' then
: R7 y; H9 o7 _$ z6 a! X8 iBit_Cnt <= Bit_Cnt + 1;
; V5 C  z  O# US_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right$ L$ \. W  i8 f2 e
Parity <= Parity xor PS2_Datr;- D7 N+ z+ h9 q, h! b8 X
end if;
6 n; c6 \& D4 v( Z6 {+ Cwhen others => -- never reached. l0 Z, g, w& u* z/ X! E3 I
State <= Idle;- V. s: G) f7 Y3 Z; I
end case;2 P1 i+ c/ y, W' d% I9 G
end if;% h) x  [1 d! }" Z' n# I' b
end process;9 d4 |, j9 j- ?3 b5 Y
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-4-28 10:43 PM , Processed in 0.104006 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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