当前位置:首页 > 技术学院 > 技术前线
[导读]中断服务程序

下面是一个时钟中断服务程序,是我在一本书上看到的,程序中通过时钟中断来定时改变全局变量count的值,并将结果输出到当前文件夹下新建立的文本文件out.txt中。代码如下。

/* Note:This is a interrupt service routine */

#include "stdio.h"

#include

#include

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

void interrupt (* oldhandler)(void);

int count = 0;

/*INTR中断服务程序*/

void interrupt handler(void)

{

++count;

outportb(0x20, 0x20);

}

void main()

{

FILE *out;

out = fopen("out.txt", "w");

disable(); /*关中断*/

/*保存INTR中断的中断向量*/

oldhandler = getvect(INTR);

/*将中断服务程序的入口地址安装在中断向量表中*/

setvect(INTR, handler);

enable(); /*开中断*/

/**等待中断服务程序执行20次*/

while(count < 20)

fprintf(out, "The count is %d/n", count);

fclose(out);

out = NULL;

getchar();

}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭