Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4417|回復: 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
% R: l5 R! |& N% E: E
0 y+ E& E% Z/ y5 Y- E) \( i程式如下:, D+ k! Q& ~* Y' V1 v
-- PS2_Ctrl.vhd& V2 I: j! u+ S& S6 j
-- ------------------------------------------------
7 p- ?- N! ?! L* ^1 w  b9 A" D4 k  E-- Simplified PS/2 Controller (kbd, mouse...)
) W! |  o( l5 D3 k3 ?  a-- ------------------------------------------------5 ~* Y' f4 `8 v. a
-- Only the Receive function is implemented !
" K. l0 O! M( ^6 ?. T$ O) P-- (c) ALSE. http://www.alse-fr.com3 W; d4 P  H- S' ~
library IEEE;
6 ]! g$ ?6 z8 {. x  |/ }+ _9 Tuse IEEE.STD_LOGIC_1164.all;
, v- g1 B# |6 w$ cuse IEEE.Numeric_std.all;) ]" B8 s9 ^4 B1 M; s6 M5 f; Q# n" k
-- --------------------------------------% @; e/ T/ [9 ^& b' R1 b. i
Entity PS2_Ctrl is
5 S# g# n! [8 Q1 W( E! A6 l-- --------------------------------------/ n6 M1 O# L4 O: q. `9 J( [' \+ ~
generic (FilterSize : positive := 8);
9 b. g- J2 q: r* kport( Clk : in std_logic; -- System Clock
+ F) I- }1 ?2 H; Q' K( w$ `2 M# VReset : in std_logic; -- System Reset
) h0 g2 F8 y! \" ]& xPS2_Clk : in std_logic; -- Keyboard Clock Line
5 A' X* O& A: I6 Y/ K. a: ]PS2_Data : in std_logic; -- Keyboard Data Line3 M; w* Z/ f6 ~1 h
DoRead : in std_logic; -- From outside when reading the scan code$ n' C% U4 o0 J+ y- E& I& Z6 [
Scan_Err : out std_logic; -- To outside : Parity or Overflow error9 t- Y. |) g9 G5 y
Scan_DAV : out std_logic; -- To outside when a scan code has arrived
' C( E5 Y% S# ?# Z1 eScan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
) F. A" j. F6 m3 Z, Y( M! }+ N; {);; m9 B% m" I* n0 J8 g3 N" O: g
end PS2_Ctrl;  v) {1 x( {! x+ D/ K4 G
-- --------------------------------------
8 G5 r3 U+ \2 V8 n/ ]2 T3 W3 x# hArchitecture ALSE_RTL of PS2_Ctrl is
% e& ~% C, V$ _) M5 m, ~# |-- --------------------------------------
' _7 ~- t- X: \- |-- (c) ALSE. http://www.alse-fr.com2 j, c( i' Q) V+ ~
-- Author : Bert Cuzeau.
$ p  W0 W6 \8 d' U' Z-- Fully synchronous solution, same Filter on PS2_Clk.3 ^" {4 I: z! D% ^, K! I0 K2 U* J
-- Still as compact as "Plain_wrong"...7 u% Z* D$ \0 `  e2 w( r8 b& b
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting. S. _+ R2 R- ?4 ?+ i6 r, s7 W
-- Note: PS2_Data is resynchronized though this should not be! M% Y) H  e8 V3 u0 Q
-- necessary (qualified by Fall_Clk and does not change at that time)., @4 M, m0 o2 Q; L% O
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.8 H( g6 f6 J+ v2 G) T+ Q8 K
signal PS2_Datr : std_logic;5 Z$ Z1 ^6 L( d) S
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);' b9 L8 o# T0 d1 B. f
signal Filter : Filter_t;% G9 x4 ]1 P% W& }  I
signal Fall_Clk : std_logic;
/ H# y& Z. u1 J4 f3 M% P4 a# ?signal Bit_Cnt : unsigned (3 downto 0);
5 }) t( `: `# E5 \signal Parity : std_logic;7 W, A% ]- Z( A
signal Scan_DAVi : std_logic;
1 q* D& ~1 u" E" g" Fsignal S_Reg : std_logic_vector(8 downto 0);
$ \9 X/ C8 R+ ]; d" E& fsignal PS2_Clk_f : std_logic;
% a- l) S" ]" r/ w& mType State_t is (Idle, Shifting);
' }, R, {. P9 _3 ~0 u! W: u3 E3 hsignal State : State_t;4 Z! B* o( ~7 P/ ~( K: i
begin
4 u/ d: k( n! ?: E! Z0 p1 P5 `$ XScan_DAV <= Scan_DAVi;
9 I$ ^+ ]  \; S- F& L) c-- This filters digitally the raw clock signal coming from the keyboard :4 _& H! V# R' E
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high& o0 X. ]1 Q# [
-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low- A" I! d  I2 S4 d' X: O" g
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data9 H( U; \0 S9 p, C& n! i
-- Also in charge of the re-synchronization of PS2_Data
, i! ]6 O# @) N4 Z$ dprocess (Clk,Reset)
' ]8 V1 H/ h. _, I6 F  g+ o$ B& {begin
0 ?2 M) k) M! P* W7 Dif Reset='0' then
* `) R  k+ {  k1 g7 O0 d# [PS2_Datr <= '0';
6 C3 d1 o6 v0 `PS2_Clk_f <= '0';% N" A& {" J: F  {
Filter <= (others=>'0');# _) l2 d- V' c2 P; h
Fall_Clk <= '0';4 k2 E/ h7 d: d( F- m/ f
elsif rising_edge (Clk) then
  A6 C( f& c" R! V" D" X0 @PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'
( S% h1 }, N  o. E; zFall_Clk <= '0';/ q( C, d- G5 j; ?
Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
# b+ e# B- l5 x. Mif Filter = Filter_t'(others=>'1') then
% ?1 u% J9 u+ [5 p1 m4 l* I- lPS2_Clk_f <= '1';5 s( o3 K7 d2 ]$ p+ N0 {6 y2 X# m
elsif Filter = Filter_t'(others=>'0') then; j+ c) H% n6 }* L1 B8 D4 Z
PS2_Clk_f <= '0';
- x! J3 t* R1 \( a, z2 iif PS2_Clk_f = '1' then, p* e7 K7 W, s  n; x
Fall_Clk <= '1';
3 d/ I% T7 U5 d6 Jend if;1 e7 r0 Z- L- ^2 j
end if;
$ A& q/ S* ]7 H# O* V1 ]; W, kend if;
, o1 d; e2 y, i  ^end process;2 B) D, b8 K6 Y8 z1 w
-- This simple State Machine reads in the Serial Data
: Z( r7 D: ?9 L% P-- coming from the PS/2 peripheral.9 ^3 U0 R# @! w8 X0 d  z% c& ?
process(Clk,Reset)
0 `4 C; I' \  k5 n9 Fbegin8 y8 U" u2 f* c" p/ Y6 Y# Q
if Reset='0' then, |9 Q; t2 f3 y/ `
State <= Idle;
! q2 J2 w9 D* a( O! VBit_Cnt <= (others => '0');
6 A( p8 x8 h* {6 xS_Reg <= (others => '0');2 O' ?# _& W# C
Scan_Code <= (others => '0');
* q! e  o5 B/ G  q. H. hParity <= '0';. i- Z1 W  m4 J  F' |" {& W# n
Scan_Davi <= '0';
$ p* V& ?& D5 \+ u2 BScan_Err <= '0';0 B! A: c  z, Z" R! w  L) }$ p
elsif rising_edge (Clk) then6 d6 ~0 C( y: f# O; J9 K1 A* h/ |* o! G
if DoRead='1' then; g4 g8 Y9 f( x6 b, X
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden5 q2 a0 V( P9 Q$ f9 c- e" H8 s: S/ l; {
end if;' }% w. ]" b- S' s+ s7 U
case State is& M  P" z2 u7 y/ a2 K
when Idle =>( @. ]9 H# M" |
Parity <= '0';* I" d+ }, g5 y% X, z
Bit_Cnt <= (others => '0');. ^5 _  N: Y9 O
-- note that we dont need to clear the Shift Register
4 }' K$ s) I" s6 W; Cif Fall_Clk='1' and PS2_Datr='0' then -- Start bit. n) E% }' k9 h+ C' w+ P! l
Scan_Err <= '0';- Z  s. k: i5 b
State <= Shifting;. w2 \' U8 J8 R: M* O5 n
end if;! Q0 }& Z+ p8 N* Z- i. H
when Shifting =>
9 m0 U, r6 f" rif Bit_Cnt >= 9 then9 v% N! e5 _, b+ n: h+ o
if Fall_Clk='1' then -- Stop Bit" ]0 X% k- C  i
-- Error is (wrong Parity) or (Stop='0') or Overflow/ u5 B! {/ a7 }. |4 _# U; v, \
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
; j3 k! P; M$ _Scan_Davi <= '1';
  e0 q) O2 |& s8 MScan_Code <= S_Reg(7 downto 0);
5 U6 P6 A6 e* SState <= Idle;
$ D: k; S. I# j% b5 Bend if;) H' G; p! j0 E' ?
elsif Fall_Clk='1' then
- s" {' V: o  [% A8 kBit_Cnt <= Bit_Cnt + 1;& h  L  T% Z/ T' p. C, W) C
S_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
0 I/ Z& r' J$ wParity <= Parity xor PS2_Datr;" F9 J* a" G" ^! H
end if;# ]7 E8 v0 _" W' y& c
when others => -- never reached
+ q6 S% k5 ]) VState <= Idle;
4 b+ A/ k$ i) v3 Iend case;
; O% a2 |# p; f# l3 a8 h- cend if;
8 h: t3 B2 X3 |* Q/ j& k5 ~; zend process;$ H* J  b2 A" W* J) S/ E
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-4-28 03:00 AM , Processed in 0.106006 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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