Allen-Bradley 1784-KTX Reference Manual page 107

Table of Contents

Advertisement

Appendix B
Programming Examples
/***************************************************************************
**
**
FILE – ktx_int.c
**
**
This file contains a routine for initializing and enabling
**
interrupts to service KTX interrupts and a routine that is a
**
boilerplate for a KTX scanner interrupt service routine
**
***************************************************************************/
#include <dos.h>
#include <assert.h>
#include "ktx_dp.h"
/* 1784–KTX Scanner Dualport definition */
#include "ktx_err.h"
/* 1784–KTX Scanner error codes
#include "ktxconst.h"
/* 1784–KTX Scanner constants
#define LowPICPort 0x20
#define HighPICPort 0xA0
#define EOI 0x20
#define INT_PENDING_BIT 0x01
extern KTX_DUALPORT far *dp;
/***************************************************************************
**
**
void Init_interrupt (unsigned char InterruptNumber, void interrupt
**
**
**
This routine sets the interrupt vector and enables interrupts.
**
The host passes in two parameters: the interrupt number and
**
the interrupt service routine that will handle KTX interrupts.
**
The interrupt number must match the interrupt number selected
**
for this channel using the jumper on the KTX hardware.
**
**
INPUTS
**
KTX_DUALPORT far *dp – points to the base of the KTX dualport
**
UBYTE trans_num
**
USHORT timeout
**
**
OUTPUT
**
Interrupt Vector for KTX installed
**
***************************************************************************/
void interrupt (*OldInterruptServiceRoutine)();
void InitInterrupt(unsigned char InterruptNumber, void interrupt (*InterruptServiceRoutine)())
{
unsigned char
PICMask,
PICPortBase,
SWInterruptNumber;
/* Insure that InterruptNumber is valid one for KTX – leave in for debug only */
assert((InterruptNumber > 2) && (InterruptNumber < 16));
/* Set the base port of the Programmable Interrupt Controller depending on
whether the interrupt is on the first or second PIC */
if (InterruptNumber < 8) PICPortBase = LowPICPort;
else PICPortBase = HighPICPort;
/* Convert from hardware interrupt numbers (0–7) to software interrupt numbers
0x8–0xf and hardware interrupt numbers (8–15) to software interrupt
numbers 0x70–0x78
Allen-Bradley Parts
B-28
ktx_int.c file
/* Port address for Prog. Interrupt Controller for ints 0–7 */
/* Port address for Prog. Interrupt Controller for ints 8–15 */
/* End Of Interrupt to PIC */
/* bit mask for interrupt pending bit in status register */
/* pointer to KTX's dualport */
(*InterruptServiceRoutine)())
– transaction_number
– time (in seconds) to wait for completion
/* pointer to store old interrupt handler */
/* storage for prog. interrupt controller mask */
/* Port address of either first PIC or second PIC */
/* Software Interrupt number, converted from HW */
*/
*/
*/

Advertisement

Table of Contents
loading

This manual is also suitable for:

1784-ktxd1784-kts

Table of Contents