AT/PS2 Keybord - PIC Interface?


Closed Thread
Results 1 to 40 of 74

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    Wow, you really gave me a good idea. Thank you.

    Do you have any idea on how to input keycodes into the PC with the PIC.

    regards
    Is the Search function here on the site broke again or what?

  2. #2
    Join Date
    Mar 2006
    Posts
    41


    Did you find this post helpful? Yes | No

    Cool PIC16f84 PS/2 kbd to asccii @9600 bps n 1

    this project is a milford chip 29.95$ buster!!! I've used it in several of my designs

    http://www.electronic-engineering.ch...#faq_kbd_input
    Last edited by leisryan; - 6th April 2007 at 01:47.

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


    Did you find this post helpful? Yes | No

    Default Pic To Ps/2 Send

    HELLO GURU'S,

    I AM TRYING TO SEND SOME FIXED CHARACTER FROM THE PIC TO THE PC VIA PS/2 WITHOUT ANY RESULT.

    CAN SOMEONE PLEASE HELP !

    BACKGROUND:
    I HAVE JUST ADAPTED A CODE I FOUND ON THE NET FOR BS2 FOR MY PURPOSE. THE FILE IS ATTACHED TO THIS MAIL. ITS GOT SOME VERY GOOD DATA FOR HOW TO........ FOR THE PURPOSE.

    THE ONLY DIFFERENCE IS THAT I HAVE DIRECTLY CONNECTED THE PORTPINS TO THE PC PS/2 CABLE SO AT A COUPLE OF PLACES I HAVE INVERTED THE SENDS.

    MY CODE:

    @ device PIC16F73 , hs_osc, wdt_off, pwrt_on, protect_oN
    Include "MODEDEFS.BAS" ' Include Shiftin/out modes
    '-----------------------------------------------------------------
    Define Osc 8 ' We're using a 8 MHz oscillator
    '-----------------------------------------------------------------
    Adcon1 = 7 ' Set PORTA DIGITAL
    OPTION_REG.7 = 1 ' DISABLE INTERNAL PULLUPS
    Trisa = %00000000 ' SETS ALL PORTA PINS TO OUTPUT
    Trisb = %00001100 ' ALL OUTPUT
    Trisc = %00001011 ' 6 Pins - LCD and 2 Pins RF Module
    '-----------------------------------------------------------------
    SCLK VAR PORTB.1
    SDATA VAR PORTB.0
    LED VAR PORTC.5 ' LED
    '-----------------------------------------------------------------
    temp var BYTE 'Temp variabel
    char var WORD 'Variabel containing the character
    breakcode var WORD 'Variabel containing "Breakcode"
    extcode var WORD 'Variabel containing "Extended charcode"
    I VAR BYTE ' TEMP VARIABLE
    ' -----[ Initialization ]---------------------------------------------
    '
    'Set datpin and clkpin default to high (1)
    HIGH SDATA ' low datpin
    HIGH SCLK ' low clkpin

    'Define breakcode
    ' s--DATA--PS (s=start, DATA=LSB First, P=parity, S=stop)
    breakcode=%00000111111 '/F0H

    'Define extcode
    ' s--DATA--PS (s=start, DATA=LSB First, P=parity, S=stop)
    extcode=%00000011101 '/E0H

    ' -----[ Main Code ]--------------------------------------------------
    '

    PAUSE 4000 : LOW LED

    start:

    temp=0 : pause 1000
    HIGH LED : GOSUB button00 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500
    HIGH LED : GOSUB button01 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500
    HIGH LED : GOSUB button02 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500
    HIGH LED : GOSUB button03 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500
    HIGH LED : GOSUB button04 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500
    HIGH LED : GOSUB button05 : TEMP = 0 : PAUSE 500 : LOW LED : PAUSE 500

    goto start

    ' -----[ Test Characters ]--------------------------------------------
    ' These are inverted
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%10110101110 '/SPACE
    'char=%11100011110 '/a
    'char=%11010010100 '/CR
    'char=%11011001110 '/b
    'char=%11100101110 '/t
    'char=%10100101100 '/r
    'char=%10011101110 '/d
    'char=%10101111100 '/F1
    'char=%11111000110 '/INS

    button00:
    'Assign char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%11100011110 '/a
    char=%00011100001 '/a
    gosub sendchar
    RETURN

    button01:
    'Assign char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%11010010100 '/CR
    char=%00101101011 '/CR
    gosub sendchar
    RETURN

    button02:
    'Assign char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%11011001110 '/b
    char=%00100110001 '/b
    gosub sendchar
    RETURN

    button03:
    'Assigne char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%10110101110 '/SPACE
    char=%01001010001 '/SPACE
    gosub sendchar
    goto start

    button04:
    'Assigne char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%10101111100 '/F1
    char=%01010000011 '/F1
    gosub sendchar
    RETURN

    button05:
    'Assigne char a character with startbit, parity and stopbit. OBS inverted !
    ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit)
    'char=%11111000110 '/INS
    char=%00000111001 '/INS
    gosub sendextchar
    RETURN

    ' -----[ Subroutines ]------------------------------------------------
    '
    sendchar
    'Send character
    shiftout SDATA,SCLK,1,[char\11] : pauseus 10
    'Send breakcode + character
    shiftout SDATA,SCLK,1,[breakcode\11] : pauseus 10
    shiftout SDATA,SCLK,1,[char\11] : pauseus 10
    return

    sendextchar
    'Send extcode + character SDATA
    shiftout SDATA,SCLK,1,[extcode\11] : pauseus 10
    shiftout SDATA,SCLK,1,[char\11] : pauseus 10
    'Send extcode + breakcode + character
    shiftout SDATA,SCLK,1,[extcode\11] : pauseus 10
    shiftout SDATA,SCLK,1,[breakcode\11] : pauseus 10
    shiftout SDATA,SCLK,1,[char\11] : pauseus 10
    return

    ' -----[ End ]--------------------------------------------------------


    ANY BETTER IDEA WOULD ALSO HELP.

    REGARDS
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    HELLO GURU'S,

    I AM TRYING TO SEND SOME FIXED CHARACTER FROM THE PIC TO THE PC VIA PS/2 WITHOUT ANY RESULT.

    CAN SOMEONE PLEASE HELP !

    BACKGROUND:
    I HAVE JUST ADAPTED A CODE I FOUND ON THE NET FOR BS2 FOR MY PURPOSE. THE FILE IS ATTACHED TO THIS MAIL. ITS GOT SOME VERY GOOD DATA FOR HOW TO........ FOR THE PURPOSE.

    THE ONLY DIFFERENCE IS THAT I HAVE DIRECTLY CONNECTED THE PORTPINS TO THE PC PS/2 CABLE SO AT A COUPLE OF PLACES I HAVE INVERTED THE SENDS.

    MY CODE:
    WOW!!!!

    Whilst a few of us here might might have slightly impaired hearing either due to geting older or working in nightclubs...or both... I dont believe we are totally deaf yet!!!

    Please stop shouting or buy a keyboard that also has lower case letters on it as well !!!!
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default Good suggestion.

    Quote Originally Posted by keithdoxey View Post
    WOW!!!!

    Whilst a few of us here might might have slightly impaired hearing either due to geting older or working in nightclubs...or both... I dont believe we are totally deaf yet!!!

    Please stop shouting or buy a keyboard that also has lower case letters on it as well !!!!
    I think i need to take your suggestion and shut my mouth about it.

    regards

  6. #6
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Default PS/2 to 18F4620 timing issues with mytekcontrols code?

    Hello!

    I have implemented the wonderful code PS/2 keyboard code from mytekcontrols in my PIC18F4620. It will only work if I set
    TOcntDLY CON to a value of 100 (originally set to 10 per mytekcontrols).

    Furthermore, if I hit and hold any of the these three keys (Caps Lock, Num Lock, or Scroll Lock), there is no response from the keyboard LEDs and the program just hangs. These keys will work if I hit them VERY quickly (less than .1 second - just hit with a glancing blow).

    Everything else works as it should (with the CON change above).

    Is this a big timing issue for me? Settings when programming?

    Reference:
    PIC 18F4620
    Internal OSC at 8Mhz
    OSCCON = %01110010
    BUT even with an external 20Mhz oscillator, same performance, still hangs!

    I sense severe timing issues. I will welcome all suggestions with regard to fixing this code for me.

    Thank you to all,
    Bob Pigford
    Newark, Delaware

  7. #7
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default May not be

    Hi,

    I used it on a 40MHz oscillator and did not have any issue. However the following may be considered:

    1. Allow enough time (2 seconds or more is safe) before calling the PS2init routine. Your keyboard needs this to boot-up. Indicated by all three LEDs flashing and going off.

    2. The characters are stored using interrupts but the interrupts are re-enabled only when parse it. This may cause the keyboards internal buffer to be overwhelmed.
    Regards

    Sougata

  8. #8
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Default PS/2 to 18F4620 timing issues with mytekcontrols code?

    Thank you sougata,

    Quote Originally Posted by sougata View Post
    Hi,

    I used it on a 40MHz oscillator and did not have any issue. However the following may be considered:

    1. Allow enough time (2 seconds or more is safe) before calling the PS2init routine. Your keyboard needs this to boot-up. Indicated by all three LEDs flashing and going off.

    2. The characters are stored using interrupts but the interrupts are re-enabled only when parse it. This may cause the keyboards internal buffer to be overwhelmed.
    I did allow enough time for the keyboard to start. I see the LEDs flash, so I think that is not the issue.

    I will follow you suggestion and look into the buffer situation. I will also order a 40mhz oscillator just to be sure.

    I will report back on my progress.

    Thank you again,
    Bob Pigford
    Newark, Delaware, USA

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

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

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

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

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 : 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