Search This Blog

C Program to Display SCAN and ASCII Codes of Keys on Keyboard Using 8086 Interrupt

output of C program source code to find scan code and ASCII code of any key pressed on keyboard asci ascii A 65 97 32 30 keyboard code using 8086 interrupt 16 0x16 16h INT16 int86 int86x
Output (ASCII and SCAN code) when a is pressed
This program displays SCAN code and ASCII code of any key pressed on the keyboard. We use inregs is made zero in the program. Then interrupt 16h is called using int86() function in dos.h. The arguments are interrupt number (in hexadecimal ; in C 0x16) pointer to input register and pointer to output register.
The interrupt stores scan code in higher byte of accumulator and ASCII code in lower byte of accumulator.

8086 interrupt number 16h (hexadecimal) to read a keystroke from keyboard. The condition for this interrupt is that the higher byte of accumulator (AH) should be 00h.

#include<stdio.h>
#include<dos.h>
#include<conio.h>
void main()
{
union REGS inregs,outregs; //declaring 2 register files
clrscr();
inregs.h.ah=0x0; //pre-requisite for desired operation of interrupt 16h
int86(0x16,&inregs,&outregs); //calling interrupt 16h
printf("\nScan Code :%d\nASCII code:%d\n",outregs.h.ah,outregs.h.al);
getch();
}

No comments: