Quick Key Adapter, 10 Button HID Keyboard. Part 2 - Firmware

Part 1 - Schematic

This device's design is based on the Low Pin Count Development Kit hardware from Microchip, Microchip Solutions has example programs for that development kit so it is quite easy to get them running on the device covered in this Instructable.

For the purposes of this project I used the USB Device - HID - Keyboard example for the Low Pin Count Development Kit. But there are various other devices that could be programmed onto this hardware/device, anything that could use 10 switch inputs.

Included in the ZIP on Step 1 is the MPLAB project files, you must install the latest version of MPLAB and the latest release of C18 compiler. Microchip Downloads Can Be Found Here


Firmware Overview:

The included project files were taken and modified from Microchip's example code. They had wrote it in a way so it can run on multiple different PIC devices, so there is a lot of extra code not needed. The rest is mostly USB related code, the only function that was modified was the Keyboard() function.

ProcessIO() -> Keyboard() -> Check if IN endpoint is ready -> Check Switches ->Send Data -> ProcessIO()

The switches state are checked and compared to their previous state. if the states differ the switch is considered pressed and will fill a data buffer with/the required data then send it. Then continue checking the switches.

hid_report_in[0] = is the modifier byte, it holds the state of the shift, alt, ctrl, gui(windows) keys
hid_report_in[1] = 0; is reserved and always 0
hid_report_in[2] thru [7] // Can be a keycode, up to 6 keys can be pressed and reported at once. See the "HID Usage Tables" pg. 52 for keycodes

Modifier key chart:

Bit Key
0 LEFT CTRL
1 LEFT SHIFT
2 LEFT ALT
3 LEFT GUI
4 RIGHT CTRL
5 RIGHT SHIFT
6 RIGHT ALT
7 RIGHT GUI

Example:
hid_report_in[0] = 4; //alt
hid_report_in[0] = 8; //L GUI
hid_report_in[0] = 7; //ctrl+alt + shift


Some commands need a second key sent or key combo sent, by setting filling the data bytes NextModKey and NextKey then setting AnotherFlag flag in the firmware, after the primary command is sent it will send another report with those key values.

Such as Minimize Window which the Windows hotkey is Alt+Spacebar, then press n.

If you have a blank PIC18F14K50 or want to be able to flash the firmware, there are 2 options.

  • Program the chip in an external programmer and insert it into its socket, remove to reprogram if necessary.
  • Or a ICSP header can be attached to the bottom of the PCB, using some wires to connect the proper solder pads to the PIC's ICSP headers, and use that to program and reprogram.

Check everything over well, a short could damage the Host Computers USB bus. All solder joints should be shiny.

Downloads

HID Usage Tables - download
Schematic, PCB, source code - download
HEX file - download
MPLAB project - download

instructables.com