- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I couldn't find a useful PS-2 keyboard routine that would produce ASCII codes. This project does that and it includes use of the Shift keys to get upper-and lower-case characters and symbols. Decoding works for only the main keyboard area and doesn't decode the Print Screen, Insert, Delete, and other keys on the right side of the main keys. You could add these as needed. You can add a value for the Fx keys, also. The example includes an array for upper-case and an array for lower-case values that have ASCII codes. Spaces are "saved" with 0x0 so you can insert a code for, say, the F4 key that generates the keyboard scan code of 0x0C. Find that location in the array and substitute the code you want the F4 key to provide. I have included a table of the keyboard-to-ASCII translations that lists all the bytes for both arrays with an index between 0 and 0x7F. This information helps you locate a keyboard scan code and insert the ASCII value you want to produce when pressed. I also include a flow chart that shows how the code operates.
When you press a key, a PS-2 keyboard sends information in an 11-bit serial stream that looks like a UART transmission (LSB first). Each key has an assigned non-ASCII code. This code remains the same when shifted or unshifted. The software looks for the shift key and handles data accordingly. When you release a key, the keyboard send a "key-release" byte (0xF0) followed by the code for the letter. Software handles this, too. A clock signal from the keyboard will strobe the bits into an SPI register. I used the LSB first and mode 1,1, as included in this project.
In typical use you would use the SPI port to generate an interrupt, but the example code simply runs an infinite "keyboard input" routine and echoes characters to a terminal program. This setup makes the software easy to test. I used a CY8CKIT-059 5LP Prototyping Kit. I monitored keyboard data with an Saleae Logic analyzer and ran the Parallax Serial Terminal on my Win-10 PC to check the ASCII output from the project. Have fun. Jon Titus, Herriman, UT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the code.
You can use UART only (baudrate = 12000, Odd)
I have a very simple example, but I don't remember the details anymore:
PS2_NumKey40.zip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the code.
Looking at the PS/2 documentation around (http://retired.beyondlogic.org/keyboard/keybrd.htm ), it looks like the SPI Mode should rather be CPHA=0,CPOL=1 (Clock idle high, data valid on clock falling).
But the code is also working as is. Thanks a lot for sharing.
JJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for sharing your project, i was also thinking about a decoder for PS-2 keyboards but i was interested in develop it using the UDB programmable hardware, in your experience, do you think it is possible to do it that way or should i be fine using your approach?
Regards,
Carlos