⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intrpts.c

📁 rt采集卡dos下dm6430驱动源代码
💻 C
字号:
/***************************************************************************

	FILE NAME: INTRPTS.C

	FILE DESCRIPTION: INTRPTS (Interrupts)

    Sample program that demonstrates how to use the timer as an interrupt
    source and how to write an Interrupt Service Routine (ISR).

	 This program sets up the User Timer to generate interrupts at a selected
	 rate. An interrupt service routine (ISR) is provided that simply samples
	 from one channel on the A/D board each time the interrupt is activated.
	 The value is displayed on the screen as a foreground process. Although
	 the ISR in this program is trivial, all the ingredients for powerful
	 interrupt driven data acquisition are included.

	PROJECT NAME: INTRPTS (Part of DM6430 DOS Driver)

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/

#include <conio.h>
#include <dos.h>

#include "drvr6430.h"
#include "dio5812.h"
#include "pcutil.h"

/***************************************************************************
  Defines

  Change these constants to alter the program parameters.
****************************************************************************/

#define BASE_ADDRESS   768             // Base address of DM6430.


#define CHANNEL 0                      // A/D channel
#define GAIN    0                      // Gain
#define SE_DIFF 0                      // Single ended
#define RATE   20                      // Clock rate in 'Hz'
#define ADSLOPE (65536.0/20.0)         // Number Bits divided by AD Range.
#define IRQ_CHANNEL 10                 // IRQ Channel

// Global variables
//------------------

volatile int Value;                    // Global variable to store the data
													// acquired by the Interrupt Service
													// Routine (ISR). The foreground
													// program and the ISR communicate
													// trought this variable.


/****************************************************************************
  NewISR()

  The NewISR function is called whenever an interrupt is generated on the
  specified IRQ. It simply gets a single value from the A-D board.

  Do not try to access any functions that use DOS calls (disk access, screen
  writes, read keyboard, etc) and do not use floating point operations in
  this function. DOS and the Floating Point Emulator are not reentrant and
  will cause unexpected happenings if used inside an interrupt.

  Before exiting the function passes the End of Interrupt (EOI) command
  to the 8259 interrupt controller. Don't forget the EOI command; it is
  required even if your ISR does nothing.
****************************************************************************/

#ifdef __cplusplus
 void interrupt NewISR(...)            // C++ style interrupt function
#else
 void interrupt NewISR(void)           // C style interrupt function
#endif
{
  StartConversion6430();               // Start the conversion.
  while(IsADFIFOEmpty6430());          // Check if data is ready.
  Value= ReadADData6430();             // Read data.
  ClearIRQ16430();							// Clear IRQ on DM6430.

  EndOfIT(IRQ_CHANNEL);                // VERY IMPORTANT !!!
													// 'End of Interrupt' command.
} //NewISR


/****************************************************************************
  SetProgramScreen()

  The SetProgramScreen() function initializes the screen.
****************************************************************************/

void SetProgramScreen(void)
{
  clrscr();

  // Print footer and header.
  gotoxy( 1, 1); cprintf(TitleString6430());
  gotoxy(50, 1); cprintf("Interrupt Example");
  gotoxy( 1,25); cprintf("Press any key to exit. . .");

  window(1, 3, 80, 23);
  gotoxy(25, 8); cprintf("Channel %d :           Volts", CHANNEL + 1);
} //SetProgramScreen


int main(void)
{
  float ActualRate0;					// Actual clock rate returned from timer 0.

  SetProgramScreen();

  SetBaseAddress(BASE_ADDRESS);
  InitBoard6430();                        // Board initializing.

  ActualRate0 = SetUserClock6430(0, 8000000.0, 20000.0);	// Initialize User Clock0.
  SetUserClock6430(1, ActualRate0, RATE); 		    		// Initialize User Clock1.

  SetConversionSelect6430(0);             // Conversion Select =  Software.
  SetChannelGain6430(CHANNEL, GAIN, SE_DIFF); // Load Channel Latch.
  Value = 0;     		                     // Set 'Value'.

  SetIRQ16430(13,IRQ_CHANNEL);            // Set Board IRQ1 Source User TC out 1.
														// Set IRQ Channel.

  InitHostIT(NewISR,IRQ_CHANNEL);     	  	// Set the Interrupt Service Routine
														// and enable the appropriate IRQ
														// channel.
  ClearIRQ16430();								// Clear IRQ on DM6430.

  while ( !kbhit() ) {                 	// Run until any key pressed.
	 gotoxy(37, 8); cprintf( "%6.3f V", Value/ADSLOPE);
														// Display Value stored in NewISR
  } //while
  getch();                             	// Get the pressed character.

  SetIRQ16430(13,0);				            // Disable board IRQ.
  RestoreHostIT(IRQ_CHANNEL);          	// Restores the IT vector and disable
														// the appropriate IRQ channel.
  DoneTimer6430();                        // Reset timer.

  window(1,1,80,25);                   	// Reset original screen coordinates,
  clrscr();                            	// and clear the screen.
  return 0;
} //main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -