PS/2 keyboard emulation


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10

    Default PS/2 keyboard emulation

    Hi all,

    I'm having a look into a project that takes input from a circuit (push buttons) and sends it through to a PS/2 cable that can be plugged into the keyboard port of a PC. I'm trying to get the push buttons in the circuit to send the data of certain keys from the keyboard. For example, when I press one push button it sends a lower case "a" to the computer, and when I press the other push button it sends a space.

    Has anyone had a play around with this before? I've been having a fiddle with using a PIC for it without much luck...

    Any help would be great.

  2. #2
    Join Date
    Jul 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    Has anyone had a play around with this before?
    I did ! (-Played-) several yrs ago....
    look at this i dont remember but it's part off a bigger program... any way I hope you can find it useful...
    Code:
     'ps2 emu-sw betomax
     DEFINE SHIFT_PAUSEUS 15
     char        var Word  'character
     datpin      var porta.0   'Keyboard Data ' 10k pull up
     clkpin      var porta.1   'Keyboard Clock ' 10k pull up
     col         VAR   BYTE     ' Keypad column
     row         VAR   BYTE     ' Keypad row
     key         VAR   BYTE     ' Key value
     delayer con 100    'delay btw chars
     CMCON = 7
     trisa =0
     datpin = 1
     clkpin = 1
     OPTION_REG.7 =    0        ' Enable PORTB pull-ups
     h var word : h = %11001100110
     o var word : o = %11010001000 
     l var word : l = %11010010110
     a var word : a = %10000111000
     b var word : b = %10001100100
     c var word : c = %11001000010
     d var word : d = %10001000110
     uno var word  : uno =  %10000101100
     dos var word : dos =  %11000111100
     tres var word : tres =  %10001001100 
     cuatro var word : cuatro =  %10001001010
     extcode var word : extcode = %10111000000 'e0
     berak var word : berak  =%11111100000 'f0
     intro var word : intro = %11010110100 '5a
    
    Start:
    
     GOSUB Getkey ' from switch / keypad
    
     Select CASE Key ' wich key ??
      case 1
       char = uno : GOSUB sendchar : pause 500
      case 2
       char = dos :GOSUB sendchar : pause 500
      case 3
       char = tres :GOSUB sendchar: pause 500
      case 4
       char = cuatro: GOSUB sendchar: pause 500
      case 5
       char = a : GOSUB sendchar: pause 500
      case 6
       char = b: GOSUB sendchar: pause 500
      case 7
       char = c : GOSUB sendchar: pause 500
      case 8
       char = d :  GOSUB sendchar: pause 500
      case 9
       char =h:GOSUB sendchar: pause 500
         case 10
       char =o:GOSUB sendchar: pause 500
      case 11
       char = l:GOSUB sendchar: pause 500
     END SELECT
      pause 500
      goto start
    
    'actually make ps2 tx !
    
    sendchar:
      shiftout datpin,clkpin,0,[char\11] : pauseus 50
      shiftout datpin,clkpin,0,[berak\11] : pauseus 50
      shiftout datpin,clkpin,0,[char\11]: pauseus 50
      return

  3. #3
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    This looks neat! I'll have a crack at it!

    I was wondering though, do you have more of the keyboard codes? The application I plan on using will make use of 21 keys in the end...

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Did you try searching the forum? Found this.
    http://www.picbasic.co.uk/forum/showthread.php?t=2736
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    Yeah, I had seen that, but it is dealing with the exact opposite of what I'm trying to do. I'm not trying to interface a keyboard to a PIC.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    Yeah, I had seen that, but it is dealing with the exact opposite of what I'm trying to do. I'm not trying to interface a keyboard to a PIC.
    Hmmm. Did you read the whole thing? Guess not.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    When scanning a forum for similar topics, no-one reads each thread in it's entirety.

    I'll have a look now you've drawn my attention to it. Thanks for the link.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    When scanning a forum for similar topics, no-one reads each thread in it's entirety.
    I knew I was doing something wrong
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    When scanning a forum for similar topics, no-one reads each thread in it's entirety.
    Nobody's ever always or never. I usually do.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  2. 16f877 and ps/2 keyboard error???
    By boraciner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th July 2009, 08:14
  3. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  4. pic as ps/2 keyboard
    By mischl in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 15th May 2007, 16:53
  5. PS/2 mouse and keyboard
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2006, 16:29

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts