pic as ps/2 keyboard


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default Found it!

    Here's a code snippet to transmit PS/2 data:

    In this case, dataout is an array of bytes I may want to send to the computer.

    Odd parity is NOT the value of all bits XOR'ed together.

    Good luck!

    John


    * * *
    for x = 0 to 7
    if dataout[x] <> 0 then
    sendthis = dataout[x]
    parity = not(sendthis.0 ^^ sendthis.1 ^^ sendthis.2 ^^ sendthis.3 ^^ sendthis.4 ^^ sendthis.5 ^^ sendthis.6 ^^ sendthis.7)
    sendthis = sendthis << 1 'move over to insert start bit
    sendthis.0 = 0 'start bit
    sendthis.9 = parity
    sendthis.10 = 1 'stop bit
    shiftout kbddata,kbdclk,4,[sendthis\11]
    dataout[x] = 0
    endif
    next x

  2. #2
    Join Date
    Jan 2005
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    hello john

    thanks for your support.

    i work with a similar code. so i have some additional questions :

    - which osc speed do you use? - i have a 16f876 with 4M
    - have you defined a shift_pauseus? - i try it . around 40us seems best
    - how long do you wait until you send the release code (F0) after the button press comand? - i don't wait
    - how looks your hardware setup? - 2 transistors at portc with pull up works at best. nod good because i get different chars... when i only take pullups instead the transisitors, after connect the keyboard it wouldn't be initialized.
    - what are you doing at the booting from the pc?

    best regards

  3. #3
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    - which osc speed do you use? - i have a 16f876 with 4M

    '628 @ 20 MHz

    - have you defined a shift_pauseus? - i try it . around 40us seems best

    I used 50 uS

    - how long do you wait until you send the release code (F0) after the button press comand? - i don't wait

    In my particular application, I sent a 'make' code at keydown and a 'break' code at keyup. So the waiting time was up to the buttonpusher.

    - how looks your hardware setup? - 2 transistors at portc with pull up works at best. nod good because i get different chars... when i only take pullups instead the transisitors, after connect the keyboard it wouldn't be initialized.

    Just a pair of 4K7 pullup resistors on clock and data. The pins on my pic are set to be inputs (high impedence) unless I'm transmitting.

    - what are you doing at the booting from the pc?

    My project doesn't so far parse all of the boot communication which takes place, because it's only used after Windows has totally started.

    I'd started to send copies of the incoming data out to a terminal program so I could see what was being said, but didn't spend much time there due to other projects.

    However, one of the documents mentioned earlier in this thread has a fairly detailed description of the commands and responses that will be flying around on a properly configured system.

    Sorry I can't help much more.

    John

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


    Did you find this post helpful? Yes | No

    Default Anyone, please ?

    I'm trying to simulate (emulate) a ps/2 keyboard from a pic to laptop's ps/2 port. The PIC (12F509) needs to send a few keystrokes to the laptop.

    Using a part of JEC's code i got it working, but the output (e.g. what i see on my notepad on my laptop screen does not look like the characters i should be seeing, when i look at various scan code tables.

    What am i doing wrong ?

    Here's the code :

    Code:
    INCLUDE "modedefs.bas"
    DEFINE SHIFT_PAUSEUS 50
    
    '==== Andere test ! ============================================================
    parity      var word
    sendthis    vaR word
    kbddata     var GPIO.0
    kbdclk      var GPIO.1   
    
    start:
    high kbddata
    high kbdclk           
     
    pause 500
    
    sendthis = %11010110 'sending this results in a "y" on screen
    gosub calsub
    
    sendthis = %11110000 'This should be 0xF0 the "release code"
    gosub calsub
    sendthis = %11010110 'For release code
    gosub calsub
    goto start          
    
    
    calsub
    
    parity = not(sendthis.0 ^^ sendthis.1 ^^ sendthis.2 ^^ sendthis.3 ^^ sendthis.4 ^^ sendthis.5 ^^ sendthis.6 ^^ sendthis.7)
        
    sendthis = sendthis << 1 'move over to insert start bit
    
    sendthis.0 = 1 'start bit 'In JEC's code this was a 0, but that did'nt work
                     
    sendthis.9 = parity
    
    sendthis.10 = 0 'stop bit 'In JEC's code this was a 1, but that did'nt work
    
    shiftout kbddata,kbdclk,4,[sendthis\11]
    
    return
    
    goto start

    The "y" i got when i was experimenting, other thing i saw was :

    11000111 = 3
    11000110 = DEL
    00010010 = o
    11010110 = y
    00110010 = F4
    11011110 = NUM-LOCK
    11110110 = PAGE-UP

    What is wrong ???

    Best Regards, UB

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    INCLUDE "modedefs.bas"
    DEFINE SHIFT_PAUSEUS 50
    parity var word:sendthis var word:kbddata var GPIO.0:kbdclk var GPIO.1
    start:
    high kbddata:high kbdclk:pause 500:sendthis=$d6:gosub calsub:sendthis=$f0
    gosub calsub:sendthis=$d6:gosub calsub:goto start          
    
    calsub:    <---ADD COLON HERE
    
    parity=not(sendthis.0^^sendthis.1^^sendthis.2^^sendthis.3^^sendthis.4^^sendthis.5^^sendthis.6^^sendthis.7)
    sendthis=sendthis<<1:sendthis.0=1:sendthis.9=parity:sendthis.10=0:shiftout kbddata,kbdclk,4,[sendthis\11]:return
    goto start

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what happen if your change NOT by ~ ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    what happen if your change NOT by ~ ?
    Agh! Missed that one! And it was right below my comment!

Similar Threads

  1. PS/2 keyboard emulation
    By CumQuaT in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th September 2009, 04:32
  2. I've made keyboard with pic, but i have a problem.
    By XErTuX in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th November 2008, 00:40
  3. Pic to PC AT keyboard caracters
    By sezgin05 in forum General
    Replies: 5
    Last Post: - 27th March 2007, 10:45
  4. PS/2 mouse and keyboard
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2006, 16:29
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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