CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PS2 KEYBOARD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PS2 KEYBOARD
PostPosted: Thu Feb 09, 2006 7:39 pm     Reply with quote

Hy !

I looking to find a sample source to send key to PC PS2 port

I only need to detect keypress on pic port and send A key on PC

Thanks

Alain
RVaughn13



Joined: 09 Feb 2006
Posts: 13
Location: Santa Fe, Texas

View user's profile Send private message Visit poster's website

PS2 Keyboard
PostPosted: Fri Feb 10, 2006 6:18 pm     Reply with quote

Hi,
There are other ways to pass information to your PS2 port (if you only want to detect a button press or switch closure). There are many different types of PS2 keyboard emulators used by the MAME gaming industry. These emulators have screw-lug terminal blocks and are programmable to transmit any character (or series of characters) to your IBM PS2 keyboard port. An example can be found here:
http://www.ultimarc.com/ipac1.html
Hope this helps!
_________________
--Rick
Donlaser



Joined: 17 Sep 2005
Posts: 12
Location: Trenque Lauquen, Argentina

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 10, 2006 8:07 pm     Reply with quote

I use this routines for ps/2 i/o, with a pic16f628 running @4mhz intrc.
Work without problem in more than 2000 units deployed.
You can use this for code as Asm inline o recode in CCS C.

KBD_CLK_I and KBD_DAT_I are inputs pins
KBD_CLK_O and KBD_DAT_O are outputs pins what drives a npn transistors with the colectors conected at de data lines/clock lines and the emiter to GND.

note: Delay is in "cycles" (running at 4mhz).

I hope this was a start point for you.

Hernan.
Argentina.

;---------------------------------------------------------------------------------------------
; ByteOut:
; Sends a byte in w to the host.
; Returns 0xFE if inhibited during transmission.
; Returns 0xFF if host interrupts to send its own data.
; Returns 0x00 if byte sent successfully.
;---------------------------------------------------------------------------------------------
; OUTPUT ONE BYTE: - TIMING IS CRITICAL!!!
;---------------------------------------------------------------------------------------------
SendKey movwf LastSend
ByteOut movwf Temp0
InhibitLoop btfss KBD_CLK_I ;Test for inhibit
goto InhibitLoop
Delay 50
btfss KBD_CLK_I
goto InhibitLoop
btfss KBD_DAT_I ;Check for request-to-send
retlw 0xFF
clrf Parity
movlw 0x08
movwf Counter
movlw 0x00
call BitOut ;Start bit (0)
btfss KBD_CLK_I ;Test for inhibit
goto ByteOutEnd
Delay 4
ByteOutLoop movf Temp0, w
xorwf Parity, f
call BitOut ;Data bits
btfss KBD_CLK_I ;Test for inhibit
goto ByteOutEnd
rrf Temp0, f
decfsz Counter, f
goto ByteOutLoop
Delay 2
comf Parity, w
call BitOut ;Parity bit
btfss KBD_CLK_I ;Test for inhibit
goto ByteOutEnd
Delay 5
movlw 0xFF
call BitOut ;Stop bit (1)
Delay 48
retlw 0x00

ByteOutEnd bcf KBD_DAT_O ; dato a alto (inv)
nop ; x las dudas...
bcf KBD_CLK_O ; clock a alto (inv)
retlw 0xFE

BitOut andlw 0x01 ; saca el bit 0 de w por la salida..
btfss STATUS, Z
bcf KBD_DAT_O ; cero
btfsc STATUS, Z
bsf KBD_DAT_O ; uno
Delay 21
bsf KBD_CLK_O ; clock abajo (uno)
Delay 45
bcf KBD_CLK_O ; clock arriba (cero)
Delay 5
return



;---------------------------------------------------------------------------------------------
; ByteIn:
; Reads a byte from the host.
; Result in "Receive" register.
; Returns 0xFD in w if timeout waiting start bir
; Returns 0xFE in w if host aborts transmission.
; Returns 0xFF in w if framing/Parity error detected.
; Returns 0x00 in w if byte Received successfully.
;---------------------------------------------------------------------------------------------
; READ ONE BYTE: - TIMING IS CRITICAL!!!
;---------------------------------------------------------------------------------------------
ByteIn clrf Contador
ByteInL decfsz Contador, F
goto espsb
retlw 0xFD
espsb btfss KBD_CLK_I ;Wait for start bit, clock alto con dato bajo..... por el tiempo en Contador...
goto ByteInL
btfsc KBD_DAT_I
goto ByteInL

movlw 0x08
movwf Counter
clrf Parity
Delay 28
ByteInLoop call BitIn ;Data bits
btfss KBD_CLK_I ;Test for inhibit
retlw 0xFE
bcf STATUS, C
rrf Receive, f
iorwf Receive, f
xorwf Parity, f
decfsz Counter, f
goto ByteInLoop
Delay 1
call BitIn ;Parity bit
btfss KBD_CLK_I ;Test for inhibit
retlw 0xFE
xorwf Parity, f
Delay 5
ByteInLoop1 Delay 1
call BitIn ;Stop bit
btfss KBD_CLK_I ;Test for inhibit
retlw 0xFE
xorlw 0x00
btfsc STATUS, Z
clrf Parity
btfsc STATUS, Z ;Stop bit = 1?
goto ByteInLoop1 ; No--keep clocking.

;Acknowledge
bsf KBD_DAT_O ; dato como salida
Delay 11
bsf KBD_CLK_O ; clock como salida
Delay 45
bcf KBD_CLK_O ; clock como entrada
Delay 7
bcf KBD_DAT_O ; data como entrada

btfss Parity, 7 ;Parity correct?
retlw 0xFF ; No--return error

Delay 45
retlw 0x00

BitIn Delay 8
bsf KBD_CLK_O ; clock como salida
Delay 45
bcf KBD_CLK_O ; clock como entrada
Delay 21
btfsc KBD_DAT_I
retlw 0x80
retlw 0x00
Guest








PostPosted: Sat Feb 11, 2006 9:08 am     Reply with quote

Thank you very much !!
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Feb 13, 2006 2:16 am     Reply with quote

Just came across this one:
http://www.ccsinfo.com/forum/viewtopic.php?t=25673
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group