Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4486|回復: 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
. Z/ a2 s' K- c* M1 F5 E% m4 S" a& k( H( m9 g
程式如下:
/ \9 j1 s  t! _-- PS2_Ctrl.vhd9 {5 e& d4 S- c
-- ------------------------------------------------& K' z% D; D4 u
-- Simplified PS/2 Controller (kbd, mouse...)4 V# @7 t$ L  m$ S
-- ------------------------------------------------. J$ `" `4 W  a5 ^
-- Only the Receive function is implemented !
8 e& u9 e/ E% Z7 `4 V$ f& g-- (c) ALSE. http://www.alse-fr.com( g5 b8 L- ?; B5 c6 [
library IEEE;- s/ X4 V3 v: \9 V
use IEEE.STD_LOGIC_1164.all;. B# Q4 S9 D' ~$ z) `0 c: o
use IEEE.Numeric_std.all;$ H. A! l  i- H/ u, T% k! F9 j. [1 x
-- --------------------------------------4 S; Z# `1 Z" c; `
Entity PS2_Ctrl is2 b: A0 n1 O' h" D. Q! r2 d) z
-- --------------------------------------
/ w# |3 O  N/ ^8 Qgeneric (FilterSize : positive := 8);
& S# a+ p1 G- x* e5 G" cport( Clk : in std_logic; -- System Clock1 N0 A7 }' g# t
Reset : in std_logic; -- System Reset
2 A6 K2 n9 h$ ]/ x7 DPS2_Clk : in std_logic; -- Keyboard Clock Line- z5 ?7 [/ {- w, X
PS2_Data : in std_logic; -- Keyboard Data Line* F! @' z1 y4 j, N- K- h% x
DoRead : in std_logic; -- From outside when reading the scan code
2 b$ G: l* }7 k- ^9 O$ @' K  kScan_Err : out std_logic; -- To outside : Parity or Overflow error
" s% ~0 W) E) g( r" L8 BScan_DAV : out std_logic; -- To outside when a scan code has arrived- {% _/ @/ s/ W9 y
Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out( B. v- u. j2 \, I) j) Y
);
4 A' r0 D( d( _& X! @end PS2_Ctrl;
3 ]# y6 z! E: `$ O% ^7 p6 ~9 n/ _-- --------------------------------------
1 V! g7 }& ], o1 R/ s$ r. u$ CArchitecture ALSE_RTL of PS2_Ctrl is
* t6 R+ w% c" k4 X; e( ~-- --------------------------------------
8 z( g$ V1 {& Z: Z& a0 a0 T, I- `-- (c) ALSE. http://www.alse-fr.com6 S3 Q1 O5 s* q- t3 a2 n
-- Author : Bert Cuzeau.% a$ f6 o# R9 d! V* t5 ?/ }
-- Fully synchronous solution, same Filter on PS2_Clk.' j$ o4 |" \$ T
-- Still as compact as "Plain_wrong"...
- T3 C5 s( T8 ^5 r1 }-- Possible improvement : add TIMEOUT on PS2_Clk while shifting; J& y8 ^* i9 R& U! V8 ?
-- Note: PS2_Data is resynchronized though this should not be
5 {& x8 i* S- |7 U+ M8 |-- necessary (qualified by Fall_Clk and does not change at that time).
9 c' |* U1 D  x* ?& v8 |-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.
$ ^% n. B, R3 h. G# fsignal PS2_Datr : std_logic;
9 W/ t" e( n/ Qsubtype Filter_t is std_logic_vector(FilterSize-1 downto 0);+ F/ h; y3 D2 Y) Y& s
signal Filter : Filter_t;
; m! k" _, Q: f* ~# o  p8 Isignal Fall_Clk : std_logic;
+ ~- u7 W7 i8 fsignal Bit_Cnt : unsigned (3 downto 0);- g$ T( m: O1 Y0 U- g: P; v
signal Parity : std_logic;* w% i! S$ V8 K+ D1 f9 I! @. k2 t
signal Scan_DAVi : std_logic;+ }3 v9 y( \/ r( C
signal S_Reg : std_logic_vector(8 downto 0);
& q* y& a3 V& @4 B" j8 d0 Lsignal PS2_Clk_f : std_logic;) \) |& I! _: ^) o% E& ?
Type State_t is (Idle, Shifting);# q, |! h5 u6 Z# J9 j. X
signal State : State_t;+ Y! }* e% r) C
begin
9 r2 s! P, s7 J8 i9 GScan_DAV <= Scan_DAVi;
  C% J7 X  u( v; O7 Q! p! b' C-- This filters digitally the raw clock signal coming from the keyboard :3 A2 ^6 E) @5 C  ?6 l! d* a
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
, K+ z4 D. q! v8 J, u8 j% i; H4 }2 e-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low/ k6 w+ [" T7 f
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data5 C% d2 M3 ^" r* v8 R% W* @
-- Also in charge of the re-synchronization of PS2_Data
$ S" K. ]* `. r8 l6 C+ J& Fprocess (Clk,Reset)
  _6 ~; V9 j6 O8 S% Bbegin" @% t  r! h1 q) I: D# S/ X& t
if Reset='0' then6 j3 V/ q# K0 `* b' L) T
PS2_Datr <= '0';
* ^/ I2 s+ g8 H2 x& ^: N, P7 r( W0 Q6 tPS2_Clk_f <= '0';
5 ]6 s- `7 @. M- [5 ~Filter <= (others=>'0');6 U! w/ ~7 K  O5 U. Q$ z$ F* _! M+ w
Fall_Clk <= '0';
* c% |0 ?5 Y9 o$ Celsif rising_edge (Clk) then$ g- f$ l8 Q% B7 s" l
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'- P$ P( _: A2 Y. l3 L$ d; P9 W
Fall_Clk <= '0';
* I* e+ W( j: x. E# X4 hFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);
/ \$ H" t" T2 v; x; I. p( Wif Filter = Filter_t'(others=>'1') then
- V) L3 P" P  Z: u/ A* t4 X7 \' [PS2_Clk_f <= '1';$ D: ~( j; ^% M! c- i# \
elsif Filter = Filter_t'(others=>'0') then
$ L$ [& D9 u" L, C" e) wPS2_Clk_f <= '0';
, f/ H8 ?. s/ @1 j8 N1 iif PS2_Clk_f = '1' then
# ?. u5 x7 f7 c- ~9 A; zFall_Clk <= '1';3 D! k! h& M; ]; }0 {& m
end if;
  K# p" i6 ^; yend if;( x* \' P" k0 g5 ^8 }4 W
end if;: N7 T. q: ]5 N3 {8 a( _/ c
end process;6 w, a1 G+ b! m9 C* k
-- This simple State Machine reads in the Serial Data
2 H1 o4 b+ H& G4 {6 t& g7 l( [-- coming from the PS/2 peripheral.
( k1 d% x0 g( R  sprocess(Clk,Reset)
/ Q& Q0 `4 h9 W9 g: H; y) Rbegin
/ d$ T. L" D6 R% f8 H9 X- c9 M( W: pif Reset='0' then9 z! e  b& `3 d  p/ ?
State <= Idle;
8 i+ |" d0 D& S/ u* y+ bBit_Cnt <= (others => '0');5 I0 v5 v0 |: f0 n! N4 W7 d# C
S_Reg <= (others => '0');
' o( u( e8 b; B% rScan_Code <= (others => '0');
4 {1 b2 Z1 G1 A1 i. U0 k  RParity <= '0';/ m. q' a) |8 o1 A2 N  \
Scan_Davi <= '0';! L- S3 T4 A- G4 @3 S, D  c$ f; [
Scan_Err <= '0';+ v' c' g4 u" B( y4 O1 K  D
elsif rising_edge (Clk) then
; V. P3 P0 H! gif DoRead='1' then
6 w  C. s9 c) j- R/ ^% a4 eScan_Davi <= '0'; -- note: this assgnmnt can be overriden. D1 ?) @$ z- w8 B4 l. ]
end if;
( D* s( }# D7 Z4 [8 p$ S% gcase State is
; b5 f* X/ ^4 z4 J: dwhen Idle =>8 A! z( P' q# Q! \; E+ h
Parity <= '0';
7 }6 ~$ T# x( V1 sBit_Cnt <= (others => '0');
  {7 L6 p, I2 k" M5 y-- note that we dont need to clear the Shift Register
4 {" C# _$ e. l# K) I$ E; g- Mif Fall_Clk='1' and PS2_Datr='0' then -- Start bit
9 x* K1 ?7 y8 s" F* LScan_Err <= '0';6 |& U" l; Z  q6 u8 _
State <= Shifting;1 U4 o; k0 K* S3 ^. W# t! s; U$ `
end if;
# f3 L( F  x9 T" n& I5 e2 F/ }when Shifting =>
; ^% t3 k9 O* n6 Qif Bit_Cnt >= 9 then
0 m# i2 _7 y, qif Fall_Clk='1' then -- Stop Bit
8 ~/ v3 l  q' A8 u+ O-- Error is (wrong Parity) or (Stop='0') or Overflow
* `. }3 g! Y* |* L2 R2 J# IScan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
; X  x2 \: k/ r0 d& U3 uScan_Davi <= '1';
2 c! v$ }9 p4 y, l" v( k0 LScan_Code <= S_Reg(7 downto 0);7 N& x3 r" z! p* g4 a- Y" {. N5 M
State <= Idle;
! [" K* k9 N: n! u0 b" y7 Cend if;+ N+ l+ w7 z; i
elsif Fall_Clk='1' then
% c6 Z: U4 K8 S% w0 V2 T; IBit_Cnt <= Bit_Cnt + 1;
# ?- Y2 s$ `( T* V$ T, nS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right. B) T+ j1 }, u
Parity <= Parity xor PS2_Datr;
) w% B/ `2 R$ O) mend if;
* R' E2 t9 e+ Q% @/ z7 v+ Ywhen others => -- never reached* r. }& y3 C/ d; I7 s4 X
State <= Idle;
# z, ^+ K+ _2 ~  F& Bend case;( b6 C5 E$ j! a& F: z! O
end if;
/ H- O; Z# `4 w7 N8 z, xend process;
$ C# s+ U2 ^( I& e0 c5 Zend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-17 10:53 PM , Processed in 0.119016 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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