PS/2 Keyboard

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Ralph
Posts: 15
Joined: Tue Apr 01, 2008 3:15 am
Location: Melbourne, Australia

PS/2 Keyboard

Post by Ralph » Thu Sep 23, 2010 10:25 am

Does anyone have any suggestions or code snippets to share that will help be in my quest to read data from an older style PS/2 keyboard? One-way communication is all I need - from keyboard to PIC. (I have no real need to switch on Caps Lock leds etc, although that would be an added bonus) :D

Mikrobasic offers a library for PS/2 keyboard communications, but I don't really want to change to a different comiler at the last minute of development.

Warmest regards,
Ralph

Raistlin
Registered User
Registered User
Posts: 69
Joined: Tue Apr 01, 2008 1:13 pm

Post by Raistlin » Thu Sep 23, 2010 1:11 pm

Its fairly easy as it is a simple synchronous buss

http://www.computer-engineering.org/ps2protocol/

should be all the info you need
If you can read this you are too close

Ralph
Posts: 15
Joined: Tue Apr 01, 2008 3:15 am
Location: Melbourne, Australia

Post by Ralph » Fri Oct 01, 2010 9:54 am

Thanks for that link - I'll take a close look and see how I go...

gramo
Registered User
Registered User
Posts: 200
Joined: Tue Mar 20, 2007 6:55 am
Location: Australia
Contact:

Post by gramo » Fri Oct 01, 2010 10:19 am

I recently made a user module for PS/2 AT Keyboards, perhaps it will do the job for you?

It's software driven with optional interrupt driven timeouts. Here's an example of the modules use:

Code: Select all

Device = 18F2520                            // 18F2520 PIC in use, could be any 18F PIC
Clock = 32                                  // clock speed is 32Mhz (8MIPS)
Config MCLRE = Off                          // disable MCLR
 
Include "InternalOscillator.bas"            // search for "User Module Pack" at www.digital-diy.com
Include "USART.bas"                         // used for displaying content on a uart terminal
Include "swKBD.bas"                         // PS2 Keyboard module. URL http://digital-diy.com/home/swordfish/user-modules/242-ps2-keyboard-module-swkbdbas.html
 
SetBaudrate(br38400)                        // initialise USART for 38400 baud
USART.Write("Power On",13,10)               // send a message to the terminal
 
While True                                  // main program loop
    If swKBD.NewKey Then                    // checks the device for new information
        If KBD.ValidChar Then               // ensure the key is a valid non-white space character
            USART.Write(KBD.KeyChar)        // yes, display it via USART
        ElseIf KBD.KeyCode = KBD_ENTER Then // check if the 'Enter' key was pressed
            USART.Write(13,10)              // yes, send a line feed and carriage return
        EndIf                               //
    EndIf                                   //
 
    High(PORTB.7)                           // toggle PORTB.7 high then low,
    Low(PORTB.7)                            // to measure the time it takes between loops
Wend                                        //   
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.

Australian distributor for the Swordfish Compiler

Ralph
Posts: 15
Joined: Tue Apr 01, 2008 3:15 am
Location: Melbourne, Australia

Perfect - thanks

Post by Ralph » Fri Oct 29, 2010 3:39 am

Superb - thanks Graham, that is just what the doctor ordered!

Post Reply