/************************************************/
/* Example program for communicating with the keyboard through the 8042 chip */
/* Author: xy_god */
/************************************************/
#include "dos.h"
#include "stdio.h"
#include "conio.h"
int iCode=0;
int blKey=0;
void interrupt ( *oldhandler)(void);/*interrupt handler function pointer*/
void interrupt handler(void);
int getbit(char c,int i);
void getkeystate();
int main(void)/***********************main function***********************/
{
int a;
oldhandler = getvect(0X09);/*get the original keyboard interrupt address*/
setvect(0X09, handler);/*install the new keyboard interrupt*/
getkeystate();
printf("*********************************************\n"
;
while (1)
{
if(blKey==1)
{
blKey=0;
printf("%X",iCode);
printf("****"
;
getkeystate();
}
}
setvect(0X09, oldhandler);/*restore the keyboard interrupt*/
return 0;
}/*****************************************************************/
void interrupt handler(void)/*keyboard interrupt handler*/
{
blKey=1;
iCode=inport(0x60);
oldhandler();
}
int getbit(char c,int i)/*get the value of bit i of the byte*/
{
int mi;
mi=c<127)
return 1;
else
return 0;
}
void getkeystate()/*get keyboard status*/
{
int i,ic=0,bitvalue;
for(ic=0;ic<8;ic++)
{
i=inport(0x64);
bitvalue=getbit(i,ic);
switch(ic)
{
case 0:
if(bitvalue) printf("OBF=TRUE\n"
; else printf("OBF=FALSE\n"
;
break;
case 1:
if(bitvalue) printf("IBF=TRUE\n"
; else printf("IBF=FALSE\n"
;
break;
case 2:
if(bitvalue) printf("SYS=TRUE\n"
; else printf("SYS=FALSE\n"
;
break;
case 3:
if(bitvalue) printf("A2=TRUE\n"
; else printf("A2=FALSE\n"
;
break;
case 4:
if(bitvalue) printf("INTH=TRUE\n"
; else printf("INH=FALSE\n"
;
break;
case 5:
if(bitvalue) printf("TxTO=TRUE\n"
; else printf("TxTO=FALSE\n"
;
break;
case 6:
if(bitvalue) printf("RxTO=TRUE\n"
; else printf("RxTO=FALSE\n"
;
break;
case 7:
if(bitvalue) printf("PERR=TRUE\n"
; else printf("PERR=FALSE\n"
;
break;
}
}
}
/* Example program for communicating with the keyboard through the 8042 chip */
/* Author: xy_god */
/************************************************/
#include "dos.h"
#include "stdio.h"
#include "conio.h"
int iCode=0;
int blKey=0;
void interrupt ( *oldhandler)(void);/*interrupt handler function pointer*/
void interrupt handler(void);
int getbit(char c,int i);
void getkeystate();
int main(void)/***********************main function***********************/
{
int a;
oldhandler = getvect(0X09);/*get the original keyboard interrupt address*/
setvect(0X09, handler);/*install the new keyboard interrupt*/
getkeystate();
printf("*********************************************\n"
;while (1)
{
if(blKey==1)
{
blKey=0;
printf("%X",iCode);
printf("****"
;getkeystate();
}
}
setvect(0X09, oldhandler);/*restore the keyboard interrupt*/
return 0;
}/*****************************************************************/
void interrupt handler(void)/*keyboard interrupt handler*/
{
blKey=1;
iCode=inport(0x60);
oldhandler();
}
int getbit(char c,int i)/*get the value of bit i of the byte*/
{
int mi;
mi=c<127)
return 1;
else
return 0;
}
void getkeystate()/*get keyboard status*/
{
int i,ic=0,bitvalue;
for(ic=0;ic<8;ic++)
{
i=inport(0x64);
bitvalue=getbit(i,ic);
switch(ic)
{
case 0:
if(bitvalue) printf("OBF=TRUE\n"
; else printf("OBF=FALSE\n"
;break;
case 1:
if(bitvalue) printf("IBF=TRUE\n"
; else printf("IBF=FALSE\n"
;break;
case 2:
if(bitvalue) printf("SYS=TRUE\n"
; else printf("SYS=FALSE\n"
;break;
case 3:
if(bitvalue) printf("A2=TRUE\n"
; else printf("A2=FALSE\n"
;break;
case 4:
if(bitvalue) printf("INTH=TRUE\n"
; else printf("INH=FALSE\n"
;break;
case 5:
if(bitvalue) printf("TxTO=TRUE\n"
; else printf("TxTO=FALSE\n"
;break;
case 6:
if(bitvalue) printf("RxTO=TRUE\n"
; else printf("RxTO=FALSE\n"
;break;
case 7:
if(bitvalue) printf("PERR=TRUE\n"
; else printf("PERR=FALSE\n"
;break;
}
}
}
临河居士
http://www.xygod.pc5.org
http://www.xygod.pc5.org



