Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4428|回復: 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
1 j% V$ R  Q8 R9 _# B+ j& c4 s, I& x
( }& T* u0 v  q4 Q1 Y/ i$ W0 s. l程式如下:
& L' V- @# y6 `, t- K% ~-- PS2_Ctrl.vhd- e/ W+ g) ?; o/ g2 ^8 f
-- ------------------------------------------------# u+ o0 q) v" x: L5 x& u- _( j
-- Simplified PS/2 Controller (kbd, mouse...)
4 E- K. @6 F2 i6 m1 ^6 O0 h-- ------------------------------------------------; L$ h( W) ~) Y$ q/ O8 P% R
-- Only the Receive function is implemented !
4 d- D. r" @( S* R% R7 C1 R- f-- (c) ALSE. http://www.alse-fr.com
' X* M& y" J, E+ y( y+ i6 ?library IEEE;, P9 }$ X3 h+ d& e
use IEEE.STD_LOGIC_1164.all;, V; P1 }0 d6 k3 q8 l
use IEEE.Numeric_std.all;- B8 }* j9 W1 w3 L1 T
-- --------------------------------------
* e; z* Q4 J! [! H# JEntity PS2_Ctrl is
( {0 ^1 A. W+ z5 [-- --------------------------------------
; |$ \& K$ D- mgeneric (FilterSize : positive := 8);7 ~- q- n+ F+ R4 M; n$ G0 R' i
port( Clk : in std_logic; -- System Clock
# N" D5 x3 z* ~+ c! uReset : in std_logic; -- System Reset: b$ S2 s& `! j$ b2 |' u( H
PS2_Clk : in std_logic; -- Keyboard Clock Line; z$ ?, _4 N; K2 w% S& x
PS2_Data : in std_logic; -- Keyboard Data Line
' H5 Q8 h/ H! k  |. [0 qDoRead : in std_logic; -- From outside when reading the scan code  o& }' g9 x% w' o; {$ u
Scan_Err : out std_logic; -- To outside : Parity or Overflow error
4 Y3 f8 {/ y7 T5 C( I  `& iScan_DAV : out std_logic; -- To outside when a scan code has arrived
4 F5 ?( \; N: Q5 y: A: zScan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out% y6 ?6 e' k+ q  P- ~1 {
);
1 t( r7 d; E, ^+ T! aend PS2_Ctrl;
+ P: y4 u/ X( Z) h( C$ y-- --------------------------------------! B( C( T- V) c) y% c
Architecture ALSE_RTL of PS2_Ctrl is# y( b6 n; K8 k# x! s
-- --------------------------------------
* Z# u& Y* @% D0 _- U: G-- (c) ALSE. http://www.alse-fr.com* |5 y7 i8 M; G5 F; f3 G& E/ |
-- Author : Bert Cuzeau.
" `7 ~* |1 @4 Y5 m  i. u4 o! _-- Fully synchronous solution, same Filter on PS2_Clk., o) I* y- w) h3 Y. j: C
-- Still as compact as "Plain_wrong"...7 i. h: ^* a0 ^7 q
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
- K- y8 u: E* d- n4 y, W' o-- Note: PS2_Data is resynchronized though this should not be
3 w; \! L. i0 m' r5 i-- necessary (qualified by Fall_Clk and does not change at that time).% \) J8 V% \& x, D( u+ c
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.
" s/ Y( F4 }9 L% Ssignal PS2_Datr : std_logic;
/ B8 C* X9 c+ Q  @7 k1 L9 isubtype Filter_t is std_logic_vector(FilterSize-1 downto 0);7 J/ }3 ^6 ^$ ]+ r7 U7 A; B
signal Filter : Filter_t;
0 S$ \9 o: B! X, T# a9 ^signal Fall_Clk : std_logic;2 N: K2 g* n6 o/ v+ `$ [( i( C6 j
signal Bit_Cnt : unsigned (3 downto 0);# ]) @0 c/ H" r& }- d( L# f9 M
signal Parity : std_logic;$ e7 B1 z% C0 s# m4 b; X& u
signal Scan_DAVi : std_logic;
$ t3 C8 P( {6 Tsignal S_Reg : std_logic_vector(8 downto 0);* C" |' ]3 P; g( y* ^
signal PS2_Clk_f : std_logic;
) l/ t) e' G; V+ p* G0 Q1 jType State_t is (Idle, Shifting);
2 F  x% U0 d4 J7 [' V/ ~- wsignal State : State_t;9 }& G  z0 l3 M
begin
: s2 P% l* j3 |Scan_DAV <= Scan_DAVi;- C6 _8 i! I; E( N9 ]: m  q: _. m
-- This filters digitally the raw clock signal coming from the keyboard :
- B2 w0 k. Q- Z+ Y6 J7 M-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
& Z2 n0 S( }9 Y3 ]-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low" [, z- m- w& }
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data
8 n+ ?. E( j+ a, x9 P-- Also in charge of the re-synchronization of PS2_Data
7 V- U5 v, Z2 y4 C4 ~7 Gprocess (Clk,Reset)
9 \. p# e+ Z& \9 j& dbegin# H4 H7 }9 Y! _6 a" i/ \
if Reset='0' then
. a4 z6 M+ @" i" \: t) ]5 |PS2_Datr <= '0';$ q8 L$ P6 u: Y9 n7 Q$ O
PS2_Clk_f <= '0';8 B- R3 u6 n- r) M$ O7 o  u+ }
Filter <= (others=>'0');
' h6 w9 w) Y5 R2 F$ lFall_Clk <= '0';
( f5 U/ _! {4 m0 i( A9 Lelsif rising_edge (Clk) then* ^; b% U" I# R3 @0 ~! ]) {
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'7 a1 \- E7 F5 i$ L9 s7 W, n
Fall_Clk <= '0';; O' [7 B/ y# ^6 A6 ~% ]2 k
Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);- C3 K+ a! Z9 S8 D
if Filter = Filter_t'(others=>'1') then) ]2 `5 G6 `" \* q" |: C3 G% C
PS2_Clk_f <= '1';
) k( Q. o  ^7 w: zelsif Filter = Filter_t'(others=>'0') then
1 q2 ^3 d4 o* yPS2_Clk_f <= '0';
* P! C- u) Z' e2 _: T) v; Uif PS2_Clk_f = '1' then3 G) q' H! B# O6 r$ q
Fall_Clk <= '1';
( G" H8 i) g  t6 y" Q8 Fend if;7 Q: V/ y5 X4 V7 b# P& S. z
end if;
; Y# }* g4 Z3 C1 u, h1 d9 w4 eend if;
$ C, L0 l0 q. G. x9 d6 v7 i7 n! S- zend process;
, T" _. g* E2 R0 j; e7 J9 `-- This simple State Machine reads in the Serial Data: |; E3 A0 J4 g3 i: A
-- coming from the PS/2 peripheral.' F" {4 b) _9 j# B
process(Clk,Reset): M, G# P9 l/ l& q7 J% O* x- e
begin% M! A0 Q2 Z7 L4 ~. {7 X; g
if Reset='0' then
6 D( O+ K2 T: D2 _7 [" oState <= Idle;
. I3 p- F7 `2 gBit_Cnt <= (others => '0');" |% W4 V2 v. X4 k; p
S_Reg <= (others => '0');
; l3 W# i+ @, M& dScan_Code <= (others => '0');
! E+ |* W/ f, H( BParity <= '0';
% R; k4 p% _6 f& OScan_Davi <= '0';
) v# n/ J1 E0 x2 j+ o& p6 `6 SScan_Err <= '0';, }" u, `& w4 A7 k. ]4 s1 a$ e  r2 d8 S
elsif rising_edge (Clk) then
2 I" r, z" \4 {8 ]) h1 |8 uif DoRead='1' then
8 j5 M0 q- V  R4 L, @: K+ f% KScan_Davi <= '0'; -- note: this assgnmnt can be overriden
2 D6 H6 o) M) [, y+ q1 m+ m" H! wend if;2 P5 S3 P. p% t; H4 u# ~0 Z+ ~) n
case State is
  e# m! y) [: uwhen Idle =>) d. M7 n9 I( [; }( n
Parity <= '0';
' h7 h7 e& D8 _% f1 ?$ vBit_Cnt <= (others => '0');
4 Y9 X# P+ n* q! u-- note that we dont need to clear the Shift Register5 P/ \" F3 \( s9 e) U6 e
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit
$ F6 J  H9 y9 m6 @  B: tScan_Err <= '0';) ^4 y0 T6 ~0 \( N7 s
State <= Shifting;/ g9 g- J* ?/ M/ E, b+ a1 |- |7 x
end if;* Q- g$ s9 D5 C
when Shifting =>
; {/ }% U/ v- f4 tif Bit_Cnt >= 9 then6 {1 w8 G  o4 A; B% m( D! s$ H
if Fall_Clk='1' then -- Stop Bit5 j$ l9 o2 s, R/ x
-- Error is (wrong Parity) or (Stop='0') or Overflow( e5 W5 H1 |5 n7 e8 p
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;' C. Z4 c) ~+ t) @$ A
Scan_Davi <= '1';
: i- z+ e' W9 N  h* v- {; ^- ?Scan_Code <= S_Reg(7 downto 0);6 R! r1 x% r5 Y" H/ d7 p3 [
State <= Idle;
/ o5 d  Z0 j( {+ L/ Send if;8 u+ W& `4 {" P  I* k; t4 m
elsif Fall_Clk='1' then5 ?, ^( H  B5 V  \7 B( n
Bit_Cnt <= Bit_Cnt + 1;
% l  c8 r: O: G! g9 H4 X( TS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
0 r$ a: c4 w) hParity <= Parity xor PS2_Datr;0 V6 _4 F# ~# s
end if;
. T+ N. ~2 s0 l  C# _* h+ Gwhen others => -- never reached
$ z% h' d5 O- y/ Z9 s; tState <= Idle;& |( l8 y7 D- n$ b3 U  ?* E
end case;1 r: B# @+ {+ C4 n
end if;1 \' c, @  V( f
end process;! d$ I  p( M. z2 S2 m- ?/ P' e8 {
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂1 踩 分享分享
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-7 01:04 PM , Processed in 0.098006 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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