AT/PS2 Keybord - PIC Interface?


Closed Thread
Results 1 to 40 of 74

Hybrid View

  1. #1
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Reading A Ps/2 Keyboard.

    I JUST FOUND THIS SITE VERY USEFUL (PDS CODE) AND THE CODE WORKED WITH ME. i COULD DECODE THE PS/2 KEYBOARD ATTACHED TO THE PIC ON THE LCD.

    SORRY FOR PUTTING UP A PDS CODE. CAN ANYONE CONVERT IT FOR PBP. IT HAS A LOT OF ASM, WONDER WHY ?

    http://users.picbasic.org/Howto/PC_k...c_keyboard.htm

    REGARDS

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    I JUST FOUND THIS SITE VERY USEFUL (PDS CODE) AND THE CODE WORKED WITH ME. i COULD DECODE THE PS/2 KEYBOARD ATTACHED TO THE PIC ON THE LCD. SORRY FOR PUTTING UP A PDS CODE. CAN ANYONE CONVERT IT FOR PBP. IT HAS A LOT OF ASM, WONDER WHY ? http://users.picbasic.org/Howto/PC_k...c_keyboard.htm
    REGARDS
    Why don't you try converting it over. Then if/when it doesn't work, we'll help you figure out why it doesn't work.

  3. #3
    Join Date
    Nov 2007
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Hi guys,

    I was wondering if someone can help me out here on a simple task.
    I've been learning a lot by reading about sending data to a keyboard's PS/2 port, but I am unable to send a simple letter and have it show up in notepad.exe on the host computer.

    I know the following: data sent must have Start Bit = 0, Scancode (LSB First), Odd Parity, Stop Bit = 1.

    Now, I don't care about keyboard initialization, because I will be booting up the PC with a normal keyboard attached, then swapping out the keyboard with my device.

    All I want to do is send the letter 'q' ($15).

    I am doing so by sending q (0+$51+0+1), then the release code (0+$0F+1+1), then q again (0+$51+0+1).

    However, I am not getting anything on the host side of things.

    Here is my code:




    Code:
    ; PS2SendCode          
    ;               
    ;                                     PIC16F648A                 
    ;                         _________________  _______________          
    ;                       1|RA2/AN2/VREF               RA1/AN1|18
    ;                       2|RA3/AN3/CMP1               RA0/AN0|17 
    ;                       3|RA4/TOCKI/CMP2      RA7/OSC1/CLKIN|16     
    ;              VPP ---> 4|RA5/MCLR/VPP       RA6/OSC2/CLKOUT|15                            
    ;                   Gnd 5|Vss                            Vdd|14 +5                            
    ;                       6|RB0/INT              RB7/T1OSI/PGD|13 <--- PGD            
    ;                       7|RB1/RX/DT      RB6/T1OSO/T1CKI/PGC|12 <--- PGC                    
    ;                       8|RB2/TX/CK                      RB5|11 <--> PS2DATA
    ;      PUSH BUTTON ---> 9|RB3/CCP1                   RB4/PGM|10 <--- PS2CLK _|¯|_|¯|_|¯|_|¯|_ 
    ;                         ----------------------------------           
    ;                       
    ;===============================================================================
    ;                             Keyboard to Host Protocol
    ;             ___    _   _   _   _   _   _   _   _   _   _   _   _   ___
    ;       CLOCK    |__| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_|
    ;
    ;       DATA       |  S | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | P | E |
    ;
    ;          S = start bit = 0    P = odd parity   E = stop bit = 1
    ;                      data valid on falling edge of clock
    ;===============================================================================
    
    
    @                 errorlevel  -223,-207,-306               ; Suppress useless messages
    @                 LIST   P=PIC16F648A
    @                 __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_OFF & _LVP_OFF
    
    ;Using 4MHz oscillator
    define          OSC 4
    ;DEFINE SHIFT_PAUSEUS 43
    
                    PortB = 0            'Clear Port B
                    INTCON = 0           'Interrupts Off
                    CMCON = %00000111    'Disable Comparators
                    OPTION_REG.7 = 0     'Enable Port B Weak Pull-Ups
    
    BitCnt          VAR BYTE
    KBTimeout       VAR BYTE
    ScanCode        VAR Word
    Parity          Var BYTE
    StartButton     Var PortB.3
    PS2Clk          var PortB.4          '0
    PS2Dat          var PortB.5          '0
                    TRISB = %11111111    'Set PORTB pins direction to input
    
    Start:          pause 500
                                    
                    if startbutton = 0 then: goSUB StartSend
    
                    goto start
    
    StartSend:                                       
                    'SEND Q ($15 LSB FIRST)
                    Parity = 1                          'Odd parity
                    scancode.0 = 0
                    Gosub sendbit                       'send START BIT
                    scancode = %00010101                'send 'q'
                    For bitcnt = 1 To 8                 'set for 8 data bits
                        Gosub sendbit                   'send DATA BIT
                        If scancode.0 = 1 Then: parity = parity + 1
                    scancode = scancode >> 1            'shift out next bit
                    Next bitcnt
                    scancode.0 = parity.0
                    Gosub sendbit                       'send PARITY BIT
                    scancode.0 = 1
                    Gosub sendbit                       'send STOP BIT
    
                    'SEND RELEASE ($F0 LSB FIRST)
                    Parity = 1                          'Odd parity
                    scancode.0 = 0
                    Gosub sendbit                       'send START BIT
                    scancode = %11110000                'send '$F0'
                    For bitcnt = 1 To 8                 'set for 8 data bits
                        Gosub sendbit                   'send DATA BIT
                        If scancode.0 = 1 Then: parity = parity + 1
                        scancode = scancode >> 1        'shift out next bit
                    Next bitcnt
                    scancode.0 = parity.0
                    Gosub sendbit                       'send PARITY BIT
                    scancode.0 = 1
                    Gosub sendbit                       'send STOP BIT
    
                    'SEND Q ($15 LSB FIRST)
                    Parity = 1                          'Odd parity
                    scancode.0 = 0
                    Gosub sendbit                       'send START BIT
                    scancode = %00010101                'send 'q'
                    For bitcnt = 1 To 8                 'set for 8 data bits
                        Gosub sendbit                   'send DATA BIT
                        If scancode.0 = 1 Then: parity = parity + 1
                        scancode = scancode >> 1        'shift out next bit
                    Next bitcnt
                    scancode.0 = parity.0
                    Gosub sendbit                       'send PARITY BIT
                    scancode.0 = 1
                    Gosub sendbit                       'send STOP BIT
            
                    Return
         
    SendBit:
            'Looking for keyboard clock and data line to go high, then send data bit to it!
            ;If NOT(PS2Clk = 1 AND PS2Dat = 1) Then sendbit  'loop until clock line goes low
            PS2Dat = scancode.0                             'send data bit
            return
    Any advice appreciated.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Take a look at post #6 at
    http://www.picbasic.co.uk/forum/showthread.php?t=7962

    Also, I am not sure about the way you control the Clock line in your code.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Yeah, your code seems to indicate that you are waiting for the clock line to do something?

    Your device must generate the clock in this case.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Ok, I misunderstood.

    I now realized that you are SENDING data TO KB;
    Not reading from it.

    Sorry about that.

    ------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    rookie11, I don't think this code will ever work. Where are the ENDIF commands to terminate the IF statements?

    Dave Purola,
    N8NTA

Similar Threads

  1. MXcom "C-BUS" interface to PIC question
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st May 2014, 03:59
  2. Interface a pic with a Iphone/Itouch
    By Luckyborg in forum General
    Replies: 1
    Last Post: - 6th May 2009, 16:02
  3. 4 pin 4 x 4 keypad interface using pic basic pro
    By dunlao_john in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th January 2009, 05:21
  4. USB Interface using PIC
    By Tissy in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 22nd May 2006, 16:04
  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