C语言中断程序解读

C语言中断程序解析与应用
本文通过示例解释了如何在DOS环境下使用C语言设置中断矢量,包括使用`setvect`和`getvect`函数替换和恢复中断处理程序,以及中断服务程序的工作原理。当时钟中断发生时,自定义的中断处理程序会增加计数器并调用原有服务程序,直到计数达到20次后恢复原始中断处理程序,以确保系统正常运行。

函数名: 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 */

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值