PC Keyboard question


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Hi Hatchedhand,

    I did this (PIC -> PC PS2) a while ago to simulate keystrokes. I used a simple 12F509
    and it worked ....

    See thread : http://www.picbasic.co.uk/forum/showthread.php?t=1611

    Best Regards,

    UB

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Your other option is to use USB.

    It is quite trivial to set up a PIC keyboard with USB PIC chip. When you plug it in, your OS detects it as a generic USB keyboard. Include the USB keyboard definitions file and its a matter of 1 or 2 lines of code to send keystrokes. Much easier than PS2.
    Last edited by Kamikaze47; - 11th September 2007 at 09:26.

  3. #3


    Did you find this post helpful? Yes | No

    Default Sample PIC to PS/2 Port

    Attached is a program I have tried. I see data going out of the data pin and the clock on the scope. But I do not get anything on the dos screen (DOS 6.22).

    I strobe the switch looking for a High, and then set and LED on when I get it, for some reason I do not see any data on the screen.

    I have tried all of the modes for the shiftout command but nothing seems to work.

    I am using pins +5 and Ground on the PCB connector, and then 1 and 5 on the connector. I have even jumpered 1-2 and 5-6 thinking I am looking at the wrong end of the cable. but nothig works.

    Any help would be appreciated.



    USB would be great, but I need PS/2.
    Thanks,
    HH





    ' PIC 16F688
    ' PortC.5 - Data
    ' PortC.4 - Clk
    ' PortA.2 - Switch in, normal low, active high
    ' PortA.0 - LED Out, high if switch pressed

    ' Circuit description
    ' 10K pull up on PortC.5 - Data
    ' 10K pull up on PortC.4 - Clk
    ' 10K pull up on /MCLR
    ' 10K pulling down on switch input, PortA.2

    'Goal of program, to send a chracter to the PC keyboard port when switch is pressed

    INCLUDE "modedefs.bas"
    DEFINE OSC 4 ' 4 Mhz

    TRISA = %00000100 ' Set PORTA.2 to input, all others are output
    TRISC = %00000000 ' set PORTC to outputs
    CMCON0 = 7 ' turn off comparitors
    ANSEL = %00000000 ' set all as digital ports, analog off
    char var word
    breakcode var word

    char = %11100011110 '/a
    breakcode = %11111000000 '/F0H
    '----- Main Loop --------------------------------
    Start: ' loop start
    low porta.0 ' turn off LED
    if PORTA.2 = 1 then ' check switch, if pushed then LED on and Char our
    high porta.0 ' LED on
    call sendchar ' send characters
    endif
    goto start ' restart loop


    sendchar:
    char = %11100011110 '/a
    shiftout portc.5,portc.4,4,[(char)\11] ' LSB first, Clk High
    shiftout portc.5,portc.4,4,[(breakcode)\11]
    shiftout portc.5,portc.4,4,[(char)\11]

    char=%11010010100 '/CR
    shiftout portc.5,portc.4,1,[(char)\11] ' MSB first, Clk low
    shiftout portc.5,portc.4,1,[(breakcode)\11]
    shiftout portc.5,portc.4,1,[(char)\11]

    char=%11011001110 '/b
    shiftout portc.5,portc.4,1,[char\11] ' MSB first, Clk low
    shiftout portc.5,portc.4,1,[breakcode\11]
    shiftout portc.5,portc.4,1,[char\11]

    char=%11100101110 '/t
    shiftout portc.5,portc.4,5,[(char)\11] ' MSB first, Clk high
    shiftout portc.5,portc.4,5,[(breakcode)\11]
    shiftout portc.5,portc.4,5,[(char)\11]

    char=%10100101100 '/r
    shiftout portc.5,portc.4,0,[(char)\11] ' LSB first, Clk low
    shiftout portc.5,portc.4,0,[(breakcode)\11]
    shiftout portc.5,portc.4,0,[(char)\11]


    char=%10011101110 '/d
    shiftout portc.5,portc.4,1,[char\11] ' MSB first, Clk low
    shiftout portc.5,portc.4,1,[breakcode\11]
    shiftout portc.5,portc.4,1,[char\11]

    pause 100
    return
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    I think your problem is that a normal keyboard will initialize with the PC at boot up. This involves the PC sending different commands to the keyboard, and the keyboard responding to them.

    You might want to try plugging in a standard keyboard, boot the PC, and while its still on, unplug the keyboard and plug in your pic and see if it works then.

    Heres an example of the 2 way communication that happens as the keyboard inits:

    Code:
        Keyboard: AA  Self-test passed                ;Keyboard controller init
        Host:     ED  Set/Reset Status Indicators 
        Keyboard: FA  Acknowledge
        Host:     00  Turn off all LEDs
        Keyboard: FA  Acknowledge
        Host:     F2  Read ID
        Keyboard: FA  Acknowledge
        Keyboard: AB  First byte of ID
        Host:     ED  Set/Reset Status Indicators     ;BIOS init
        Keyboard: FA  Acknowledge
        Host:     02  Turn on Num Lock LED
        Keyboard: FA  Acknowledge
        Host:     F3  Set Typematic Rate/Delay        ;Windows init
        Keyboard: FA  Acknowledge
        Host:     20  500 ms / 30.0 reports/sec
        Keyboard: FA  Acknowledge
        Host:     F4  Enable
        Keyboard: FA  Acknowledge
        Host:     F3  Set Typematic Rate/delay
        Keyboard: FA  Acknowledge
        Host:     00  250 ms / 30.0 reports/sec
        Keyboard: FA  Acknowledge
    The above is copied from: http://www.computer-engineering.org/ps2keyboard/

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Also, the PS2 keyboard protocol expects data in the order shown below and the data is valid when the clock is low.

    First Bit Sent -> Last Bit Sent
    Start(0), Data0, Data2, Data3, Data4, Data5, Data6, Data7, Parity, Stop(1)

    To press A you need to send $1C and then to release you need to send $F0, $1C

    Which means the code for A is "0 00011100 0 1", but if you store that into a word variable it will be stored as 0000000001110001 which wont help us much becuase the first bit we want to send is bit10. So if you store the code for A in reverse like this:

    char = %10001110000 '/a

    you can then send the LSB first and you will get the correct bits in the correct order. It then follows that:

    breakcode = %11000011110 '/F0

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Not meaning to flood this thread, but just spotted something else:
    "call sendchar" should be "gosub sendchar" as call is only for routines written in assembly.

  7. #7
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    You can use a built-in feature of Windows if the PC has an unused serial port.
    This feature lets you send any kind of keystroke to the PC via serial port.

    * * *

    Use an Alternative Input Device Instead of a Keyboard or Mouse

    SerialKeys is accessibility feature designed for people who have difficulty
    using the computer's standard keyboard or mouse. SerialKeys provides support
    so that alternative input devices, such as single switch or puff and sip
    devices can be plugged into the computer's serial port.

    https://www.microsoft.com/windowsxp/...erialkeys.mspx

    How to Set Up and Use SerialKeys in Windows:
    http://support.microsoft.com/?kbid=260517

    Best regards,

    Luciano

Similar Threads

  1. PC keyboard to ASCII
    By interak in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st October 2009, 18:51
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  3. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 01:04
  4. Question for the PC guru's
    By Bruce in forum Off Topic
    Replies: 24
    Last Post: - 28th January 2008, 22:05
  5. Pic to PC AT keyboard caracters
    By sezgin05 in forum General
    Replies: 5
    Last Post: - 27th March 2007, 11:45

Members who have read this thread : 0

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