📄 intrpts.c
字号:
/*
C language header file for sample programs for the CTD800.
Science & Technology CO.,LTD.
W2-B5 Shenzhen High-Tech Industrial Park,ShenZhen,GuangDong,P.R.C.
Tel: 86-755-6544000
Fax: 86-755-6549140
Zip: 518057
Compiler: Turbo C (r) version 1.0, 2.0
Turbo C++ (r) version 1.0
Borland C++ (r) version 2.0, 3.0
Last update: February 23, 2002
DESCRIPTION
~~~~~~~~~~~
Sample program that demonstrates how to program the 9513 counter/timer
and interrupt operation on the CDT800. First the counter mode register
muse be set to indicate the desired operating characteristics of the counter,
such as gating level and type,count direction and type,and output type.
the next step is to load the appropriate data into the counter's load
and hold register. the final step are to load the data into the
counter's count register and to "arm",or enable the counter. When the
output of counter is driven high, an interrupt request will be generated.
the interrupt routine is responsible for clearing the interrupt request
signal.
*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include "cdt800.c"
enum IRQV {IRQ7,IRQ5,IRQ3};
unsigned char int_num;
int flag=0;
void interrupt(*old_int)()=NULL;
/* Disable interrupt */
void Close_Rece(IRQ)
enum IRQV IRQ;
{
if(IRQ == IRQ7) int_num=0x0f;
else if(IRQ == IRQ5) int_num=0x0d;
else if(IRQ == IRQ3) int_num=0x0b;
disable();
if(IRQ == IRQ7)
outportb(0x21,(inportb(0x21))|0x80);
else if(IRQ == IRQ5)
outportb(0x21,(inportb(0x21))|0x20);
else if(IRQ == IRQ3)
outportb(0x21,(inportb(0x21))|0x08);
setvect(int_num,old_int);
enable();
}
/* Interrupt subprogramm */
void interrupt new_int()
{
if(ReadIRQStatus() == 1) /* Return 1 that an interrupt has occurred */
{
flag=1; /* Set flag bit */
ClearIRQ(); /* Clear the interrupt status bit */
}
outportb(0x20,0x20);
}
/* Interrupt receive */
void Inter_Rece(IRQ)
enum IRQV IRQ;
{
if(IRQ == IRQ7) int_num=0x0f;
else if(IRQ == IRQ5) int_num=0x0d;
else if(IRQ == IRQ3) int_num=0x0b;
old_int=getvect(int_num);
disable();
if(IRQ == IRQ7)
outportb(0x21,(inportb(0x21))&0x7f);
else if(IRQ == IRQ5)
outportb(0x21,(inportb(0x21))&0xdf);
else if(IRQ == IRQ3)
outportb(0x21,(inportb(0x21))&0xf7);
setvect(int_num,new_int);
enable();
}
void main()
{
int t,BA,chip,channel;
BA=0x300;
chip=0;
channel=5;
t=0;
clrscr();
InitializeBoardSettings(BA); /* Set baseaddress */
Master_Reset(chip); /* Duplicate the action the power-on reset circuitry */
WriteData(0xd0b0,MM_Reg,chip); /* Program master mode register */
Inter_Rece(IRQ7); /* Interrupt subprogramm */
SetIRQStatus(1); /* Set the IRQ enable bit */
WriteData(0x8e21,COUNTER5_MODE,chip); /* Program counter mode register */
WriteData(5000,COUNTER5_LOAD,chip); /* Load initial data into Load register */
LOAD_COUNTER(channel,chip); /* Load initial data into Hold register */
ARM(channel,chip); /* lssue Load and Arm command for counter */
gotoxy(35,13);
printf("Time: s");
while(TRUE)
{
if(flag == 1)
{
flag=0;
gotoxy(41,13);
printf("%d",t);
t++;
if(t>60)
{
break;
}
}
if(kbhit()) break;
}
SetIRQStatus(0); /* Clear the IRQ enable bit */
Close_Rece(IRQ7); /* Disable interrupt */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -