函数名: setvect
功 能: 设置中断矢量入口
用 法: void setvect(int intr_num, void interrupt(*isr)());
程序例:
/***NOTE:
This is an interrupt service routine. You can NOT compile this
program with Test Stack Overflow turned on and get an executable
file which will operate correctly. */
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C /* The clock tick interrupt */
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/* increase the global counter */
count++;
/* call the old routine */
oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR, handler);
/* loop until the counter exceeds 20 */
while (count < 20)
printf("count is %d/n",count);
/* reset the old interrupt handler */
C语言中断程序解读
C语言中断程序解析与应用
最新推荐文章于 2025-10-13 10:16:05 发布
本文通过示例解释了如何在DOS环境下使用C语言设置中断矢量,包括使用`setvect`和`getvect`函数替换和恢复中断处理程序,以及中断服务程序的工作原理。当时钟中断发生时,自定义的中断处理程序会增加计数器并调用原有服务程序,直到计数达到20次后恢复原始中断处理程序,以确保系统正常运行。

最低0.47元/天 解锁文章
1405

被折叠的 条评论
为什么被折叠?



