/* FILE: MAX158GG.C DESC: WIRED UP 7414 TO MAX158 PIN 13 (/INT) NOTE: MAX158 data sheet says that /INT goes low when conversion is complete. /INT is inverted by the 7414 thus going high. This high signal feeds into IRQ3. */ #include #include #include #include void interrupt (*bookmarkedIrq)(void); void interrupt doTask(void); /* int readData; float outputVoltage; float timePastInSeconds; */ int i = 0; long j = 0; int EOC; #define VREF 2.5 #define baseAddress 608 /* shorting block on row 4 of 74138 */ #define desiredChannel 0 /* function generator on AIN1 */ #define TRUE 1 #define FALSE 0 int main(void) { EOC = FALSE; /* set MAX158 end-of-conversion to false */ window(5,5,50,75); clrscr(); gotoxy(1,3); cprintf("Do-while loop iteration #"); bookmarkedIrq = getvect(irq3); /* save the old interrupt vector */ setvect(irq3, doTask); /* install the new interrupt handler */ /* Unmask (i.e. enable) IRQ3. This requires turning bit 3 to 0 */ /* and bits 0,1,2,4,5,6,7 to 1. Hence 11110111 binary = F7 hex */ outportb(0x21, ( inportb(0x21) & 0xF7 ) ); /* Unmask (Enable) IRQ3 */ do { j++; gotoxy(27,3); cprintf("%ld\n", j); outportb(baseAddress, desiredChannel); while(!EOC) { /* do nothing */ }; /* MAX158 pin 13 triggered hardware intertupt and sets EOC to TRUE */ /* Can now acquire data */ readData = inportb(baseAddress); gotoxy(32,3); cprintf("i = %d\n", i); gotoxy(39,3); cprintf("readData = %d\n", readData); */ EOC = FALSE; /* reset end-of-conversion to false */ } while(!kbhit()); /* reset interrupt back to original */ setvect(irq3, bookmarkedIrq); outportb(0x21, (inportb(0x21) | 0x08) ); printf("bye!\n"); return 0; } /* end of main */ /* this ISR should execute each time IRQ3 is triggered */ void interrupt doTask(void) { /* disable(); */ #pragma asm pushf; #pragma asm cli; i++; EOC = TRUE; /* tell main() that MAX158 generated interrupt */ outportb(0x20, 0x20); /* send EOI signal */ /* enable(); */ #pragma asm popf; return; } /* end of doTask */