Bit-Banging a PS/2 Keyboard Interface

advertisement
ECE 381
Lab 8 – Bit-Banging a PS/2 Keyboard Interface
Bit-Banging a PS/2 Keyboard Interface
Objective
Use the bit-banging technique to read scan codes from a PS/2 keyboard, map printable scan codes to
their ASCII equivalent, and have some of the keyboard non-printable scan codes control the brightness
of an LED and made tones on a speaker.
Background
The PS/2 interface is a standard used by many computing platforms for keyboard and mouse
interaction. Keystroke scan codes are sent to the host computer on a data line in data frames that are
similar to RS232 frames using 8-bit LSB first data with odd parity and one stop bit. The similarity ends
there since RS232 has separate transmit and receive lines and clock synchronization between the
devices is handled by a UART on each end. The PS/2 specification includes a separate clock line with the
clock signals on it being generated by the PS/2 device. Furthermore, both the data and clock lines are
pulled-up to VCC inside the keyboard and logic signals are placed on these lines by open-drain (or opencollector) logic gates on both the PS/2 device and the host that either pull these lines low or go highimpedance and let the pull-up resistors on the lines bring them high. Although host-to-keyboard
communication is not used in this lab, the pulled-up data and clock lines allow the host to inform the
keyboard that it has data pending for the keyboard.
In personal computers, specialized hardware is used for PS/2 interfacing. Although some
microcontrollers have similar specialized logic for PS/2 interfacing, most do not. Nevertheless, occasions
arise where interfacing a microcontroller without this hardware to a PS/2 device is necessary or
beneficial. A technique, colloquially know as bit-banging, can be used to interface with devices that
communicate data serially, like RS232 and PS/2.
Bit-banging is a software method of emulating a dedicated hardware interface when dedicated
hardware is not available. Developing reliable and fast bit-banging software requires a fairly in-depth
knowledge of the microcontroller platform and the precise timing requirements for the device to be
interfaced. As such, and because of time limitations of the class, it is considered beyond the scope of
this lab assignment. Instead, in this lab assignment you will be provided with a PSoC project template
that implements a bit-banged PS/2 interface for keyboard-to-host communications that returns scan
codes sent by a PS/2 keyboard and also maps the printable scan codes to ASCII and also takes a specific
action on some of the non-printable scan codes . You will reverse-engineer this PSoC project and build
upon it to meet all the following specifications.
Begin by downloading the project template at this lab’s URL.
ECE 381
Lab 8 – Bit-Banging a PS/2 Keyboard Interface
Hardware Configuration







Be sure jumpers JP1 and JP2 are on both of their pins or by connecting P16 to RX and P27 to TX
on J13.
Connect the DB-9 serial port on the PSoC to the DB-9 serial port of your lab computer.
Obtain a PS/2 Keyboard, with a 6-Pin MiniDIN connector on the end of the cable, from the TA
Obtain a PS/2 MiniDIN 6-Pin socket breakout board from the TA. Be sure to return this after the
lab demonstration!
Connect the PS/2 breakout board to your PSoC evaluation board according to the following
specifications: + to VCC, G to GND, C (clock) to P[1]2 and P[1]3, and D (data) to P[1]4. A
decoupling capacitor and the pull-up resistors are already built into the PS/2 breakout board.
Connect P[1]1 to LED1 on the PSoC evaluation board.
Connect the PSoC to the speaker on the Digi-Designer according to the figure shown below
ECE 381
Lab 8 – Bit-Banging a PS/2 Keyboard Interface
Initial Testing
Run RealTerm, set the baud rate to 57600, and have it open the serial port that is attached to your PSoC.
Compile the template program and upload it to your PSoC. Power on the PSoC and observe what
happens when you do the following:






Type on the “printable” keys on the PS/2 keyboard connected to your PSoC. Be sure to watch
the RealTerm program window.
Try holding down either the left or right shift key.
Press the “Print Screen” key and watch the PSoC Evaluation Board.
Hold down F1 for a long time and watch the PSoC Evaluation Board. Repeat, this time holding
down F2.
Press the “Pause” button once then press the letters in the Q, A, and Z rows, sequentially, from
left to right.
Hold down either Control key and generate control characters by pressing one of the printable
keys. Verify the control characters are being generated using RealTerm.
Requirements






Modify the program so that LED1 has only 8 brightness levels instead of the 256 it currently has.
The brightness should change relatively uniformly from off to full intensity over the 8 levels.
The Delete key current does a rubout sequence on the terminal. Modify the program to also
make the Backspace key perform this function.
Modify the program so that it detects that either Alt key is pressed and a sequence of keys is
pressed, pre-programmed strings will be printed to the terminal. Numeric sequences should
work for both numbers type in the number row or on the keypad with NumLock off. The
sequences and strings are:
o Alt-123 – The quick brown fox jumps over the lazy dog
o Alt-314 – 3.1415926535897932386
o Alt-000 – I love/hate ECE381!
Invalid sequences should be quietly ignored.
Add two additional PWM User Modules to create additional tones to the speaker. Route these
to P[0]1 and P[0]2 respective.
In Piano mode, each of the keyboard rows begging with Q, A, and Z should control one of the
PWM user modules so that three-part musical harmony is possible, at least across octaves.
Make sure that each PWM tone generator stops if none of its assigned keys is pressed.
Add the capability to detect the CTRL-ALT-DELETE key sequence used by many operating
systems. Once detected, your PSoC should perform a software reset. Figure out how.
ECE 381
Lab 8 – Bit-Banging a PS/2 Keyboard Interface
Download