You are currently viewing How to Interface PS/2 with LPC2148 ARM7 Advanced development board

How to Interface PS/2 with LPC2148 ARM7 Advanced development board

Spread the love

The ARM7 LPC2148 Advanced Development Board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Advanced Development kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.

PS/2 (Play Station 2)

The PS/2 connector is a round shape of 6-pin Mini-DIN connector used for connecting some keyboards and mice to a PC compatible compute r system.

Interfacing PS/2

Fig. 1 shows how to interface PS/2 port to microcontroller. The PS/2 bus includes both clock and data. Both a mouse and keyboard drive the bus with identical signal timings and both use 11-bit words that include a start, stop and odd parity bit. However, the data packets are organized differently for a mouse and keyboard. Furthermore, the keyboard interface allows bidirectional data transfers so the host device can illuminate state LEDs on the Keyboard.

Interfacing PS/2 with LPC2148

The ARM214X Advanced Development kit includes a PS/2 port and the standard 6-pin mini-DIN connector, labeled U11 on the board. User can connect PS/2 Devices like keyboard, mouse to the ARM7 kit. PS/2’s DATA (P1.17) and CLK (P1.18) lines connected to LPC2148 I/O Lines.

Pin Assignment with LPC2148

Both a PC mouse and keyboard use the two-wire PS/2 serial bus to communicate with a host device, the ARM7-2148 in this case.

Circuit Diagram to Interface PS/2 with LPC2148

Source Code

The Interfacing PS/2 with LPC2148 program is very simple and straight forward, which controls keyboard and display the keys position into PC through serial port. The C programs are written in Keil software. Some time delay occurring for a single data transmitted into PC. The baud rate used in microcontroller is 9600.

C Program to interface PS/2 using LPC2148

**************************************************************************************************

Title : Program to control PC through PS/2

*************************************************************************************************

#include 
#include 
#include "ps2.h"
#include "Serial.h"
#include "Utility.h" unsigned char raw_data[16],raw_pos;
unsigned long n;
int main (void)
{
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
UART0_init(38400, 15000, length_8_bit, stop_bit_1, parity_disable, parity_odd);
U0THR = 'A';
// Init PS/2 Keyboard 
Ps2_Init(&IOPIN1, 16/*CLK*/, 17/*DATA*/);
// Delay 100ms, Wait for keyboard to finish delay_Nx10cyc(599999);
// Set Keyboard Delay and Typematic Rate Ps2_Adjust_Rate(TR_Delay_750ms, TR_Rate_10);
delay_Nx10cyc(599999);
delay_Nx10cyc(599999);
do
{
Ps2_Data_Read(&raw_pos, raw_data);
if (raw_pos != 0)
{
for (n=0; n<raw_pos; n++)
{
UART0_WriteNum ("0x", raw_data[n]);
UART0_sendchar (' ');
}
UART0_sendstring ("\n");
}
}
while (1);
}

To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In KEIL, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Advanced Development Board.

The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.

Testing the PS/2 with LPC2148

Give +3.3V power supply to LPC2148 Advanced Development Board; a keyboard is connected with LPC2148 Advanced Development kit.

If a key is pressed and held, the keyboard repeatedly sends the scan code every 100 ms or so. When a key is released, the keyboard sends an “f0” key-up code, followed by the scan code of the released key. the keyboard sends the same scan code, regardless if a key has different shift and non-shift characters and regardless whether the shift key is pressed or not.

The host determines which character is intended. Some keys, called extended keys, send an “e0” ahead of the scan code and furthermore, they might send more than one scan code.

When an extended key is released, an “e0 f0” key-up code is sent, followed by the scan code.

CommandDescription
EDTurn on/off Num Lock, Caps Lock, and Scroll Lock LEDs
EEEcho. Upon receiving an echo command, the keyboard replies with the same scan code “EE”.
F3Set scan code repeat rate. The keyboard acknowledges receipt of an “F3” by returning an “FA”, after which the host sends a second byte to set the repeat rate.
FEResend. Upon receiving a resend command, the keyboard resends the last scan code sent
FFReset. Resets the keyboard

The PS/2 output is not working; you first check the keyboard is working. Otherwise you just check the port output in debugging mode in KEIL. If you want to see more details about debugging just see the videos in below link.

 How to Create & Debug a Project in KEIL.

General Information

☞For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.

☞Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.

☞Use the exact value crystal shown in schematic.

☞More instructions are available in following articles,

User Manual for NXP LPC213X Advanced Development Board

Creating & Debugging a Project in KEIL

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.