| Menu | JAQForum Ver 19.10.27 |
Forum Index : Microcontroller and PC projects : PS2 keyboard emulation from MM basic
Pardon my ignorance I have not not much experience of MM basic. There is not much choice these days when it comes to PS2 keyboards. I have few questions. 1)From MM basic (no C functions or PIO jiggery pokery) is it possible to produce a PS2 keyboard with all of the keys pertinent to MM basic. 2)Would it be possible to enable redefining a keys output e.g. Shift/2 = (") UK keyboard. Shift/2 = (@) US keyboard. 3)Has someone already done it. I know MM basic has it's limits this may be it. I though it might be of use for producing dedicated keypads for specialist functions, or for game pads to avoid over enthusiastic gamers beating the life out of their regular PS2 keyboard . There are a number of projects that require a scaled down PS2 keyboard from the retro computer scene. Just a thought. |
||||||
I can't think of a way of doing it reliably with current functionality other than a csub. However, I have an idea.... watch this space |
||||||
https://github.com/No0ne/ps2x2pico https://nl.aliexpress.com/item/1005004294259686.html?spm=a2g0o.productlist.main.21.298cUARJUARJJR&algo_pvid=dca82346-b71e-4630-a986-ad7538bc7c12&algo_exp_id=dca82346-b71e-4630-a986-ad7538bc7c12-20&pdp_ext_f=%7B%22order%22%3A%229%22%2C%22eval%22%3A%221%22%2C%22fromPage%22%3A%22search%22%7D&pdp_npi=6%40dis%21EUR%2112.55%2110.79%21%21%2199.29%2185.37%21%40211b80f717685069886698835e5ef8%2112000028661020762%21sea%21NL%210%21ABX%211%210%21n_tag%3A-29910%3Bd%3Ae83380a4%3Bm03_new_user%3A-29895&curPageLogUid=MMes8iJJrDtW&utparam-url=scene%3Asearch%7Cquery_from%3A%7Cx_object_id%3A1005004294259686%7C_p_origin_prod%3A Volhout Edited 2026-01-16 05:58 by Volhout |
||||||
Thanks for the replies I thought it would be tricky. The most of the PS2 keyboards I have tend to be rather large, a USB PS2 converter with a Pico would enable the use of some of the smaller USB units. I wanted to make a small semi-portable computer just for the novelty value. I will be watching this space! |
||||||
My latest game platform, GAP1, uses a PGA2350, HDMI and a PS2 keyboard and mouse (if you have a Y adapter). I decided to leave off USB this time. :) More later. I got some PCBs today. |
||||||
Please give more info. E.g. What sort of computer? Able to run/do what? It may already be available. John |
||||||
I own the ps2 keyboard in the link I provided, and it works well in combination with picomite. Volhout |
||||||
![]() |
||||||
Typo on the picure. Should say 0xE0,0x6B for left arrow. Here is the code. Needs RC7 to run. I'll post this later today ' PS2 Keyboard Scan Code Transmitter ' Uses dual bitstream with two pins in open-collector mode ' Simulates PS2 device-to-host transmission ' ' PS2 Protocol (device to host): ' - Clock: 10-16kHz, open-collector ' - Data: open-collector, changes when clock is HIGH ' - Data sampled on falling edge of clock ' ' Frame format (11 bits): ' 1. Start bit: DATA = 0 ' 2. Data bits 0-7: LSB first ' 3. Parity bit: Odd parity ' 4. Stop bit: DATA = 1 Const CLK_PIN = 19 ' PS2 Clock pin Const DAT_PIN = 20 ' PS2 Data pin ' PS2 timing (microseconds) Const CLK_LOW = 40 ' Clock low time Const CLK_HIGH = 40 ' Clock high time Const INIT_DELAY = 50 ' Initial delay before first clock ' Initialize pins (call once at startup) Sub PS2_Init SetPin CLK_PIN, DOUT SetPin DAT_PIN, DOUT End Sub ' Transmit a PS2 scan code ' scanCode: 8-bit scan code to send Sub PS2_Send(scanCode As Integer) Local bits(10) As Integer Local clkTiming(30) As Integer Local datTiming(30) As Integer Local clkIdx As Integer = 0 Local datIdx As Integer = 0 Local currentData As Integer = 1 Local dataTime As Integer = 0 Local bitVal As Integer Local i As Integer Local parity As Integer Local count As Integer = 0 ' Calculate parity (odd parity) For i = 0 To 7 If (scanCode >> i) And 1 Then count = count + 1 Next i parity = (count + 1) And 1 ' Build the 11-bit frame bits(0) = 0 ' Start bit For i = 0 To 7 bits(i + 1) = (scanCode >> i) And 1 Next i bits(9) = parity bits(10) = 1 ' Stop bit ' First bit - data changes before first clock falling edge bitVal = bits(0) If bitVal <> currentData Then datTiming(datIdx) = INIT_DELAY - 5 : datIdx = datIdx + 1 currentData = bitVal dataTime = 5 Else dataTime = INIT_DELAY EndIf ' First clock transitions clkTiming(clkIdx) = INIT_DELAY : clkIdx = clkIdx + 1 clkTiming(clkIdx) = CLK_LOW : clkIdx = clkIdx + 1 ' Process remaining bits (1-10) For i = 1 To 10 bitVal = bits(i) If bitVal <> currentData Then datTiming(datIdx) = dataTime + CLK_LOW + 5 : datIdx = datIdx + 1 currentData = bitVal dataTime = CLK_HIGH - 5 Else dataTime = dataTime + CLK_LOW + CLK_HIGH EndIf clkTiming(clkIdx) = CLK_HIGH : clkIdx = clkIdx + 1 clkTiming(clkIdx) = CLK_LOW : clkIdx = clkIdx + 1 Next i ' Return data to HIGH if needed If currentData = 0 Then datTiming(datIdx) = dataTime + CLK_LOW + CLK_HIGH : datIdx = datIdx + 1 EndIf ' Ensure even number of data transitions If (datIdx And 1) = 1 Then datTiming(datIdx) = 50 : datIdx = datIdx + 1 EndIf ' Transmit Device BITSTREAM CLK_PIN, clkIdx, clkTiming(), 1, DAT_PIN, datIdx, datTiming(), 1 End Sub ' ============ Test Program ============ Print "PS2 Scan Code Transmitter" Print "Initializing..." PS2_Init Pause 1000 Print "Sending 'a' (0x1C)..." PS2_Send(&H1C) PS2_Send(&HF0):PS2_Send(&H1C) 'send the key up Print "Done!" Pause 500 Print "Sending 'b' (0x32)..." PS2_Send(&H32) PS2_Send(&HF0):PS2_Send(&H1C) 'send the key up Print "Done!" Pause 500 Print "Sending 'c' (0x21)..." PS2_Send(&H21) PS2_Send(&HF0):PS2_Send(&H1C) 'send the key up Print "Done!" Print "Sending left arrow (0xE0,0x21)..." PS2_Send(&HE0):PS2_Send(&H6B) PS2_Send(&HE0):PS2_Send(&H6B):PS2_Send(&H1C) 'send the key up Print "Done!" Print "All transmissions complete!" End |
||||||
I like to tinker I'm not really into computers I had something eight bit in mind. I actually still have a couple of Zx81's they fit the bill in as much as they were so limited and slow that the fun is trying to make them better, but I do not wish to risk damaging them. What I am describing is basically an executive toy I can mess with when I am drinking endless cups of coffee in my local café (I'm not a gamer, hand eye co-ordination rubbish). There are plenty of simple AVR and pic single board computers and displays around, the stumbling block is most require a PS2 keyboard and they tend to be the size of a skateboard, a keyboard about the size of a A5 notebook that I could customise is what I was had in mind. There is the M5 stack card keyboard but uses I2C protocol. Any of the MM basic Micromites Maximites or Pico Mites would probably do great but I wanted to keep to a minimalist language like tiny basic or if I could find it VTL2 (very tiny language 2). |
||||||
WOW that was quick! I takes me months to write a couple of hundred lines of code I will need some time to digest this I am much in awe and truly grateful |
||||||
' Transmit Device BITSTREAM CLK_PIN, clkIdx, clkTiming(), 1, DAT_PIN, datIdx, datTiming(), 1 Two pin BITSTREAM !! Yes please! Edit. Already have a program that could use it. Currently cramming clock and data and latch on one pin then using RC time-constants to separate them at the Rx end. Edited 2026-01-17 07:11 by phil99 |
||||||
Since reading this thread piqued my curiosity to learn more about the PS2 protocol, I did a quick Google search. So, for anyone who might be interested: https://www.burtonsys.com/ps2_chapweske.htm Same in German: https://www.marjorie.de/ps2/ps2_protocol.htm Another page: https://www.eecg.utoronto.ca/~jayar/ece241_08F/AudioVideoCores/ps2/ps2.html @Peter: I know, nothing new for you... ![]() |
||||||
Ah. I had wondered if you wanted this kind of small computer Here's a more recent thread John Edited 2026-01-17 09:10 by JohnS |
||||||
Here is a usb keyboard to ps2 converter using a pico. https://github.com/No0ne/ps2pico |
||||||
| The Back Shed's forum code is written, and hosted, in Australia. |