4. Using the I/O Address Map
46
ADI16-4(FIT)GY
{
unsigned int
i;
unsigned char
UpperData, LowerData, sts;
_enable();
/* enable */
sts = (unsigned char)inp( ADR+0x16 );
if ( sts & 0x01 ){
for(i = 0; i < CH; i++) {
LowerData = (unsigned char)inp( ADR+0x10 );
UpperData = (unsigned char)inp( ADR+0x11 );
AdData[i][intcnt] = UpperData*0x100+LowerData;
}
+;
}
sts = (unsigned char)inp( ADR+0x16 );
outp( ADR+0x16, sts & 0x10 );
/* Status reset */
if( sts & 0x20 )
intcnt = 32767;
_disable();
/* disable */
if ( IrqLevel > IRQ7 ) {
/* EOI */
outp( 0xa0, 0x20 );
outp( 0xa0, 0x0b );
if ( !inp( 0xa0 ) )
outp( 0x20, 0x20 );
} else outp( 0x20, 0x20 );
}
/* ----- main ---------------------------------------------------------------
*/
void main( void )
{
unsigned int i, j;
float
Volt;
Initialize();
/* initialize */
ChgVect();
/* change vector */
outp( ADR+0x2, IntEnable[IrqLevel] );
/* interrupt level */
outp( ADR+0x12, CH-1 );
/* Channel data */
outp( ADR+0x18, 0x05 );
/* Conversion Start & Timer Start
*/
while( intcnt <= NUM )
printf("interrupt count = %02d \n", intcnt);
printf("\n\n");
outp( ADR+0x18, 0x06 );
/* Timer Stop */
outp( ADR+0x2, 0x0 );
/* interrupt level */
ResVect();
/* restore vector */
for(j = 0; j < NUM; j++) {
for(i = 0; i < CH; i++) {
Volt = AdData[i][j]*20.0f/65536.0f-10.0f;
printf("%01dch %04x %7.3fV ", i, AdData[i][j], Volt);
}
}
printf("\n\n");
if( intcnt == 32767 ) printf("Sampling Clock Error\n");
}
/* ---------------------------------------------------------- End of file ---
*/