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

📄 repinsw.c

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

	FILE NAME: REPINSW.C

	FILE DESCRIPTION: 

	This program uses the REPINSW command to read blocks of data from
	the fifo.

	The CPU is interrupted by the sample counter and increments
	the global variable "Transfers". When the main program sees this variable
	change, REPINSW is used to read the block of data from the fifo and
	store it in a temporary buffer. After the block of data is read, the
	data is written to a file. When the transfers are stopped, the data
	can be plotted on the screen.

	PROJECT NAME: REPINSW (Part of DM6430 DOS Driver)

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/
#include <alloc.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <stdlib.h>
#include <stdio.h>

#include "drvr6430.h"
#include "dio5812.h"
#include "pcutil.h"
#include "vgraph.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   10000                   // Clock rate in 'Hz'.
#define IRQ_CHANNEL 10                 // IRQ Channel.
#define NUM_OF_SAMPLES 1000            // Number of samples in a buffer.


// Global variables
//------------------
int Busy = 0,Error = 0;
volatile int Transfers = 0;
volatile int far *TBuffer;


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

	The NewISR function is called whenever an interrupt is generated on the
  specified IRQ. It simply checks the busy flag to see if the last transfer
  was completed and increments the "Transfers" variable.

  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
{
	if (Busy == 1) Error = 1;
	Transfers++;
	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("Rep Insw Example");
  gotoxy( 1,25); cprintf("Press enter key to start. . .          ");

  gotoxy(25, 8); cprintf("Transfers: ");
} //SetProgramScreen


int main(void)
{

	FILE* DataFile;
	float Range;
	float Slope;
	unsigned long ClockRate;
	unsigned NumberOfPoints;
	int Test;
	int NUM_OF_BYTES;
	double Actual_PACER_RATE;




	SetProgramScreen();

	TBuffer = ( int far *)farmalloc(NUM_OF_BYTES);		// Allocate data buffer.
	if (TBuffer == NULL){
		cprintf(" Not enough memory.");
		getch();
		_exit(1);
	}  // if
	memset(TBuffer,0,NUM_OF_BYTES);		// Write buffer to all 0.

	SetBaseAddress(BASE_ADDRESS);       // Set Base Address
	InitBoard6430();                    // Board initializing.

	Actual_PACER_RATE = SetPacerClock6430(RATE);	// Program the pacer clock.


	ClockRate = Actual_PACER_RATE;	// Clock rate.
	Range = 20;									// Input voltage range.
	Slope = (20.0/65536.0);					// Voltage per bit.
	NumberOfPoints = NUM_OF_SAMPLES;		// Number of points to graph.
	NUM_OF_BYTES = NUM_OF_SAMPLES * 2;	// Number of bytes.
	DataFile = fopen("REPINSW.DAT", "wb");
	fwrite(&ClockRate, sizeof(ClockRate), 1, DataFile);		// Write header
	fwrite(&Range, sizeof(Range), 1, DataFile);					// information
	fwrite(&Slope, sizeof(Slope), 1, DataFile);					// to file.
	fwrite(&NumberOfPoints, sizeof(NumberOfPoints), 1, DataFile);

	SetStartTrigger6430(0);             // Start Trigger Software.
	SetStopTrigger6430(0);              // Stop Trigger Software.
	SetConversionSelect6430(1);         // Conversion Selected Pacer Clock.
	SetChannelGain6430(CHANNEL, GAIN, SE_DIFF); // Load Channel Latch.
	LoadADSampleCounter6430(NUM_OF_SAMPLES);	  // Load AD sample counter.
	SetIRQ16430(0,IRQ_CHANNEL);         // Set Board IRQ1 Source = sample counter.
													// Set IRQ Channel.
	InitHostIT(NewISR,IRQ_CHANNEL);     // Set the Interrupt Service Routine
													// and enable the appropriate IRQ
													// channel.
	ClearIRQ16430();							// Clear IRQ on DM6430.

	Test = 0;									// Clear variable "Test".

	ClearADFIFO6430();						// Clear AD fifo.
	getch();
	gotoxy( 1,25); cprintf("Press enter key to stop. . .          ");

	StartConversion6430();					// Start board.

	while ( !kbhit() ) {                // Run until any key pressed.
		if(Test != Transfers){				// Compare "Test" and Transfers to see
													// if an interrupt has occured.
			if (Error == 1){					// Check if error flag is set.
				cprintf("Buffer Overflow");
				goto exiterror;
			}
			Busy = 1;                      // Set busy flag before starting
													 // transfers.
			asm {
				mov  dx,BASE_ADDRESS + 4         // Base Address + 4.
				mov  cx,NUM_OF_SAMPLES				// Number of Reads.
				les  di,[TBuffer]    				// Load ES:DI.
				cld                  				// Clear Direction Flag to increase DI.
				rep insw             				// Read Word at a time.
			};  //asm

			fwrite(TBuffer, sizeof(int), NumberOfPoints, DataFile); // Write to File.

			Busy = 0;                     // Reset busy flag after transfer
													// is done.
			Test++;                       // Increment "Test" to equal "Transfers".
			gotoxy(37, 8); cprintf("%4d", Transfers);
		}
	} //while
	getch();										 // Get the pressed character.

exiterror:

	gotoxy( 1,25); cprintf("Press enter key to graph. . .          ");

	RestoreHostIT(IRQ_CHANNEL);         // Restores the original IT vector.
	SetIRQ16430(0,0);				         // Disable board IRQ.
	fclose(DataFile);							// Close data file.
	farfree(TBuffer);							// Free the data buffer.
	getch();										// Stop and wait for key hit.
	vgraph("REPINSW.DAT");              // Graph data from file.
	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 + -