You have no items in your shopping cart.

Subtotal: 0.00

How to Interface PS/2 with AVR Development Board

AVR Development Board

The AVR 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 Parallel/Printer port.

ATMEL’s AVR (Atmega8535), AVR Development Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-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.



Fig. 1 Interfacing PS/2 to Microcontroller

Interfacing PS/2 with AVR Development

The AVR 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 AVR kit. PS/2’s DATA (PORTB.0) and CLK (PORTB.1) lines connected to AVR I/O Lines.

Pin Assignment with AVR

 

HARDWARE PIN OUT

CONNECTIONS

OUTPUT

CLK

PORTB.1

Connect the CLK and DATA pin of J9 with PORTB.1 and PORTB.0 respectively.

Connect a PS2 keyboard with J10-PS2 connector.

Connect Serial cable between USART Section on the Board and PC.

Press RESET once.

Press a Key in PS2 key- board, the key will be displayed in HyperTermi-nal

Only Alphanumeric keys and some special keys will be displayed.

DATA

PORTB.0

 





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

 

Circuit Diagram to Interface PS/2 with AVR Development





Source Code

The Interfacing PS/2 with AVR 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 CodeVisionAVR 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 AVR Development

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

Title : Program to control PC through PS/2

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

#include

#include

#include

#define PS2_CLK PINB.1

#define PS2_DATA PINB.0

#define TXIF UCSRA.5

#define FOSC 16000000L //Oscillator Frequency 16Mhz

#define USART_Baud 9600

#define BaudH ((unsigned int)(((FOSC/16/USART_Baud)-1) >> 8))

#define BaudL ((unsigned int)(((FOSC/16/USART_Baud)-1) & 0xFF))

flash unsigned char Key[]={"0F FFFFF FFFFt` as cQ1 ZSAW2 CXDE43 VFTR5 NBHGY6 MJU78 ,KIO09 ./L;P- ' [=\\"};

unsigned char KeyVal,i=0;

void Serial_init();

unsigned char Scan_Data();

void main()

{

DDRB = 0x00;

Serial_init();

delay_ms(50);

while(1)

{

while(PS2_CLK==1);

KeyVal=Scan_Data();

if(KeyVal>85 || KeyVal

To compile the above C code you need the CodeVision AVR software. The software has it’s own IDE and built-in AVR gcc- Compiler. They must be properly installed 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 CodeVision AVR software, you can 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 microcontroller Board.

The AVR Code Blaster software is used to download the hex file into your microcontroller through Parallel port.

Testing the PS/2 with AVR Development

Give +12V power supply to AVR Development Board a keyboard is connected with AVR Development Board

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.

Commands

The host can also send commands and data to the keyboard. Below figure provides a short list of some often-used,

Command

Description

ED

Turn on/off Num Lock, Caps Lock, and Scroll Lock LEDs

EE

Echo. Upon receiving an echo command, the keyboard replies with the same scan code “EE”.

F3

Set 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.

FE

Resend. Upon receiving a resend command, the keyboard resends the last scan code sent

FF

Reset. 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 CodeVisionAVR.

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 ATMEGA Development Kit

How to create & Debug a Project in CodeVision AVR