AT/PS2 Keybord - PIC Interface?


Closed Thread
Results 1 to 40 of 74

Hybrid View

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

    Default AT/PS2 Keybord - PIC Interface?

    Has anyone ever interfaced an AT or PS2 keyboard to a PIC that might be able to give me an idea on how to set it up?

    I know that the keyboard has data and clock lines which i will obviously have to hook up to a couple of the PICs I/O pins, but im not sure how to use pbp to recieve the data.

    Any help would be greatly apreciated.

    *edit* Im using a PIC16F84A
    Last edited by Kamikaze47; - 6th November 2005 at 18:34.

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


    Did you find this post helpful? Yes | No

    Default

    After looking thought the pbp manual im thinking the SHIFTIN *might* do the trick?

    What u guys recon?

  3. #3
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Search the archives, there are some good links there. Also, Shiftin is a master routine. You need a slave routine to work with the keyboard. Tom Enghdahl's? site has some excellent info on the interfacing of a uP to a keyboard. Alas, it's in assembly, but it is fairly easy to translate to PBP.

    Ron

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


    Did you find this post helpful? Yes | No

    Default

    So i take it that pbp doesnt have a slave version of shiftin?

  5. #5
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47
    So i take it that pbp doesnt have a slave version of shiftin?
    Nope. You basically "sit and rotate"... Let me explain, the keyboard line has a data and a clock line. It is controlled by the keyboard clock. I don't remember, but I believe the data is valid on a high to low transition of the clock. This can be confirmed with a Google search. You will also need to know whether the data is clocked in MSB, or LSB first. The shiftin subroutine waits for the clock line to go low(?), puts the data state into the lowest bit of your variable,if MSB,and shift the variable one position to the left. This is followed by a wait for the clock line to go back high, and it is done 7 more times. You can do this in a for next loop, and the code is pretty simple.
    FOR A = 1 to 8
    loop1: IF clock = 1 then loop1
    Key_data.0 = dataline
    Key_data = Key_data *2 ; Shift once to left
    loop2: IF clock = 0 then loop2
    Next A
    Key_data now contains the keypress value. It is not the neat Ascii representation of the character you pressed. Nooooo....Lest it be that simple! Now you must use a lookup table with the proper characters in the right order, but when you are done, you will have the right character. Right? Unless you want upper and lower case. You will have to look at the shift keypress characters and see if they are being held down, or if caps lock has been engaged. Let's not even talk about the "extended characters"!

    Have fun,
    Ron

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for that Ron Marcus. Yep the data comes in when the clock does a high to low transition, is least signicant bit first, and is 11 bits long (1 start bit, 8 data bits, 1 parity bit and 1 stop bit).

    So, hopefully something like this will work:

    FOR A = 1 to 11
    loop1: IF clock = 1 THEN GOTO loop1
    IF A=1 OR A=10 or A=11 THEN GOTO loop2 'No need to store start, stop or partiy bits
    Key_data.7 = dataline
    Key_data = Key_data/2 'Shift once to the right
    loop2: IF clock = 0 THEN GOTO loop2
    NEXT A

  7. #7
    Join Date
    Jun 2004
    Posts
    24


    Did you find this post helpful? Yes | No

    Default PS2/AT Keyboard

    There is a pre-programmed PIC called PAK-VI available from milford instuments. I beleive they cost around £25. I've used them in the past and seems to work fine.

  8. #8
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Arrow PS2 interface code Updated to Version 1.2

    srob:
    There is a pre-programmed PIC called PAK-VI available from milford instuments. I beleive they cost around £25.
    $29.95 USD

    Yes I am familiar with this chip, and it certainly is an option. However when a person can go out and buy something like a PIC18F252 for about $8.00, put this ready-to-run piece of code into it, and still have 14K worth of programming space left, it really doesn't make much sense to do it the other way. The PAK-VI was really aimed more at a situation where a) you don't have an alternative method (i.e.; no keyboard code), or b) the existing processor is just not fast enough, or has enough memory to do this, and be able run your main program as well (i.e; BASIC Stamp).

    Well I think I solved the "A" problem.

    But don't get me wroung srob, it is always good to look at a problem from different angles and avail yourself of all the possible solutions.

    Here is another update to the PS2 interface code. In this version I've added the ability to decode the Print Screen and Pause/Break keys. Also I've included an example of how to read the "alt" register and do something usefull. In the example a Ctrl+Alt+Delete key combo will do a Reset of your PIC. To really see this in action, initiate CapsLock, ScrollLock, or NumLock prior to the reset, and you should see the LED indicator turn off when the PIC re-initializes.
    Attached Files Attached Files
    Last edited by mytekcontrols; - 11th November 2005 at 23:46.

  9. #9
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Exclamation I moved the KBDAT I/O assignment...

    On the last PS2 Keyboard Interface update (V1.2) I failed to mention that I moved KBDAT from PortB.3 to PortB.4

    This allowed me to use the hardware PWM aspect of PortB.3 for something else. As I had stated in an earlier post, the KBDAT I/O line can be freely moved anywhere of your choosing, by simply changing one equate, and without impacting anything else in the code. I simply took advantage of this fact.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for all the time ur putting into this mytekcontrols.

    I was thinking about the problem of fitting this onto a 16F84 (which will be a problem), and i remembered that the 16F84 has 64 bytes of EEPROM data memory. I wonder if I could put some of the lookup tables on that memory in order to free up program memory.

  11. #11
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Smile

    Kamikaze47:
    Thanks for all the time ur putting into this mytekcontrols
    Actually I have a self-serving interest in doing this as well. I am designing a product that incorporates this code (along with a lot of other stuff), and I find it gives me incentive to improve it when someone else is in need of the same thing.

    Kamikaze47:
    I was thinking about the problem of fitting this onto a 16F84 (which will be a problem)
    Just curious. Any reason you are persistant on using this particular processor? You really would be much better off using an 18F series chip like the PIC18F252 or PIC18F2525. Does it have something to do with not having a programmer for these?

    Kamikaze47:
    ...i remembered that the 16F84 has 64 bytes of EEPROM data memory. I wonder if I could put some of the lookup tables on that memory in order to free up program memory
    You certainly could. But it will only be of value if can you preload the eeprom with the DATA function in PBP, or have some other way to do it through your programmer.


    Have fun with your project, and the best of luck squeezing it into your F84. <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=615&stc=1&d=1131930010 " align="absmiddle">
    Attached Images Attached Images  

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

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