4. Using the I/O Address Map
CNT16-8(FIT)GY, CNT16-8L(FIT)GY
35
void
ReadData( void );
/* read data */
void
Display( void );
/* display */
void
ResVect( void );
/* restore vector */
void
_interrupt _far inthandler( void );
/* interrupt handler */
void
( _interrupt _far *OrgVect)();
/* original interrupt vector
*/
/* ----- Initialize ---------------------------------------------------------
*/
void
Initialize( unsigned char ch )
{
outp( ADR+0x10, 0x15 );
/* digital filter set */
outp( ADR+0x11, 0x0d );
/* 1024us */
outp( ADR+0x10, 0x12 );
/* sense reset */
outp( ADR+0x11, 0xff );
outp( ADR+0x10, ch );
/* initial data set */
outp( ADR+0x11, CountData.Byte[ch].lower ); /* lower */
outp( ADR+0x11, CountData.Byte[ch].upper ); /* upper */
}
/* ----- change vector -------------------------------------------------------
*/
void
ChgVect( void )
{
OrgVect = _dos_getvect( IntVector[IrqLevel] );
_disable();
_dos_setvect( IntVector[IrqLevel], inthandler );
if ( IrqLevel > IRQ7 ) {
/* IMR and mask clear */
outp( 0x21, ( OrgMasterImr = inp( 0x21 ) ) & 0xfb );
outp( 0xa1, ( OrgSlaveImr = inp( 0xa1 ) ) & PicMask[IrqLevel] );
outp( 0x20, 0x62 );
/* ISR clear (master) */
outp( 0xa0, IsrClear[IrqLevel] );
/* ISR clear (slave) */
} else {
/* IMR and mask clear */
outp( 0x21, ( OrgMasterImr = inp( 0x21 ) ) & PicMask[IrqLevel] );
outp( 0x20, IsrClear[IrqLevel] );
/* ISR clear */
}
_enable();
/* enable */
}
/* ----- Read Data ----------------------------------------------------------
*/
void
ReadData( void )
{
unsigned char ch;
outp( ADR+0x10, 0x10 );
/* data latch */
outp( ADR+0x11, 0xff );
for (ch=0; ch<CH; ch++) {
outp( ADR+0x10, ch );
/* read data */
CountData.Byte[ch].lower = inp( ADR+0x11 );
/* lower */
CountData.Byte[ch].upper = inp( ADR+0x11 );
/* upper */
}
}
/* ----- display -------------------------------------------------------------
*/
void
Display( void )
{