> enable<DOS.H> ~ Online tutorial

enable


   Macros that disable and enable interrupts

 Declaration:


    void enable(void);
   void _enable(void);

 Remarks:


These macros provide programmers with flexible hardware interrupt control.

   enable and _enable enable interrupts,
    allowing any device interrupts to occur.

Only the NMI (non-maskable interrupt) is allowed from any external device.

 Return Value:
 None

program


#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C    /* The clock tick
                        interrupt */

#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

void interrupt (*oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS) /* if C++, need the the ellipsis */
{
/* disable interrupts during the handling of the interrupt */
   disable();
/* increase the global counter */
   count++;
/* reenable interrupts at the end of the handler */
   _enable();
/* call the old routine */
   oldhandler();
}

int main(void)
{
/* save the old interrupt vector */
   oldhandler = _dos_getvect(INTR);

/* install the new interrupt handler */
   _dos_setvect(INTR, handler);

/* loop until the counter exceeds 20 */
   while (count < 20)
      printf("count is %d\n",count);

/* reset the old interrupt handler */
   _dos_setvect(INTR, oldhandler);

   return 0;
}

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: