PC Keyboard question


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4


    Did you find this post helpful? Yes | No

    Default PIC as a Keyboard replacement

    Sorry for the delay, I have been working on trying different things. I am starting the PC with a regular keyboard and then swaping it with the PIC replacement.

    I have tried a 16F627A and I have moved back to the 16F688

    Below is the code I am testing, I am sending the data twice trying to send it both LSB and MSB first. Sometimes I get a beep from the PC when I change the PauseUS delay and other times I do not.

    ' PIC 16F688
    ' PortC.5 - Data
    ' PortC.4 - Clk
    ' PortA.2 - Switch in, normal low, active high
    ' PortA.4 - 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
    @ device INTRC_OSC_NOCLKOUT
    INCLUDE "modedefs.bas"
    DEFINE SHIFT_PAUSEUS 25
    DEFINE OSC 8 ' 8 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
    WPUA = %00000000

    char var word
    breakcode var word

    clkout var portc.4
    switch1 var portA.2
    ledout1 var portA.4
    dataout var portc.5

    'char = %10101101010 ' 'CR' mode 0
    'breakcode = %11000011110 '/F0H mode 0
    char = %01010110101
    breakcode = %01111000011

    '----- Main Loop --------------------------------
    Start: ' loop start
    low ledout1 ' turn off LED
    if switch1 = 1 then ' check switch, if pushed then LED on and Char our
    pause 50
    if switch1 =1 then
    high ledout1 ' LED on
    shiftout dataout,clkout,4,[char\11]
    shiftout dataout,clkout,4,[breakcode\11]
    shiftout dataout,clkout,4,[char\11]
    PAUSE 1
    shiftout dataout,clkout,5,[char\11]
    shiftout dataout,clkout,5,[breakcode\11]
    shiftout dataout,clkout,5,[char\11]
    endif
    endif
    goto start ' restart loop
    '----- Main Loop --------------------------------

    I have tried the character to send and the breakcode both ways, but they respond the same.

    I see the characters and clock on the scope, all six characters come across but nothing on the PC.

    I am driving the keyboard direct from the chip, no transistors. Do you think the open-collector could be an issue with the driving? Could the Clock and the timing be an issue?

    I would think that something would appear with both combinations of send's but i seem to be going in circles.

    USB would be great but it's not an option, I am not talking to a Windows OS. I have to use the PS/2 port to send data to the terminal.

    Any thoughts would be great, my goal is to send about 24 pre-defined single characters on switches to the port. I have been

    Thanks,
    HH

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


    Did you find this post helpful? Yes | No

    Default

    2 problems that i can see:

    First, looks like ur clock is too fast. PS2 keyboards generate a clock between 10khz-16khz. I'd be changing the shift pause to:

    DEFINE SHIFT_PAUSEUS 40

    Second, The "mode 0" as you call it is the only one with any chance of working, but "%10101101010" corresponds to a scancode of $AD which as far as i can tell is not a valid scancode.

    Try using these:

    char = %10001110000 '$1C = 'a'
    breakcode = %11000011110 '$F0

    shiftout dataout,clkout,4,[char\11]
    shiftout dataout,clkout,4,[breakcode\11]
    shiftout dataout,clkout,4,[char\11]


    Something else you may want to try is this:

    shiftout dataout,clkout,4,[char\11]
    pauseus 100
    shiftout dataout,clkout,4,[breakcode\11]
    pauseus 100
    shiftout dataout,clkout,4,[char\11]
    pauseus 100

    *edit* Check out this page for all the scancodes: http://www.computer-engineering.org/...cancodes2.html

Similar Threads

  1. PC keyboard to ASCII
    By interak in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st October 2009, 17:51
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  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. Question for the PC guru's
    By Bruce in forum Off Topic
    Replies: 24
    Last Post: - 28th January 2008, 21:05
  5. Pic to PC AT keyboard caracters
    By sezgin05 in forum General
    Replies: 5
    Last Post: - 27th March 2007, 10: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