读书人

TC2.0 停定时器使用 DOS

发布时间: 2013-12-15 22:17:19 作者: rapoo

TC2.0 下定时器使用 DOS
大哥们,小弟想在TC2.0下用定时器,不知道怎么操作?
有前辈写的一下代码,请高手帮忙看下是怎么实现的

#include "main.h"
#include "UserType.h"
#include <dos.h>

void interrupt (*oldproc)();

void main()
{

oldproc=getvect(0x1c);
disable();
setvect(0x1c,newproc);
enable();
while (1);

}

void interrupt newproc()
{
printf("111");
}
TC 定时器 C语言 Dos
[解决办法]

/***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 */

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

void interrupt ( *oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS)
{
/* 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 */
setvect(INTR, oldhandler);

return 0;
}

读书人网 >C语言

热点推荐