📄 scan_n.c
字号:
/***************************************************************************
FILE NAME: SCAN_N.C
FILE DESCRIPTION: SCAN_N (Scanning Multiple Channels)
Sample program that demonstrates how to perform an analog to digital
conversion on multiple channels using the channel gain table. Scan mode
means that the time between two samples is equally divided among the
channels.
Sample program that uses the Pacer Clock and the channel gain table
to acquire data on several channels.
While the measurement is running the acquired data on the A/D channels
is displayed on the screen, one line with every sample.
PROJECT NAME: SCAN_N (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"
/***************************************************************************
Defines
Change these constants to alter the program parameters.
****************************************************************************/
#define BASE_ADDRESS 768 // Base address of DM6430.
#define FIRST_CHAN 0 // First channel to scan.
#define NUM_OF_CHAN 8 // Number of selected channels.
#define GAIN 0 // Global gain.
#define RATE 20.0 // Sample rate in [Hz].
#define ADSLOPE (65536.0/20.0) // Number Bits divided by AD Range.
/***************************************************************************
SetProgramScreen()
The SetProgramScreen() function initializes the screen.
***************************************************************************/
void SetProgramScreen(void)
{
int i;
clrscr();
// Print header and footer.
gotoxy( 1, 1); cprintf(TitleString6430());
gotoxy(50, 1); cprintf("Multi Channel Scan");
gotoxy( 1,25); cprintf("Press any key to exit. . .");
// Prepare window to print data and print header above the samples.
window(1, 3, 80, 23);
gotoxy( 7, 3);
for (i = 0; i < NUM_OF_CHAN; i++)
cprintf(" CH %d ", FIRST_CHAN + i + 1);
} //SetProgramScreen
int main(void)
{
unsigned i; // Sample counter.
float Data; // Store acquired data
int ADData;
ADTableRow ADTable[NUM_OF_CHAN];
SetProgramScreen();
SetBaseAddress(BASE_ADDRESS);
InitBoard6430(); // Board initializing.
SetPacerClock6430(RATE*NUM_OF_CHAN); // Initialize pacer clock.
for (i=0;i<NUM_OF_CHAN;i++) { // Set Up AD Table
ADTable[i].Channel=FIRST_CHAN+i;
ADTable[i].Gain=0;
ADTable[i].Skip=0;
ADTable[i].Se_Diff=0;
ADTable[i].Pause=0;
}
SetStartTrigger6430(0); // Start Trigger = Software
SetStopTrigger6430(0); // Stop Trigger = Software
SetConversionSelect6430(1); // Conversion Select = Pacer Clock
LoadADTable6430(NUM_OF_CHAN,ADTable);// Load AD Table
EnableTables6430(1,0); // Enable AD Table
ClearADFIFO6430(); // Clear FIFO
i = 0; // Clear sample index.
gotoxy(7, 5);
StartConversion6430(); // Start conversion.
while ( !kbhit() ) { // Run until any key pressed
while ( IsADFIFOEmpty6430() ); // Wait until data is ready to read
ADData = ReadADData6430(); // Read acquired data and convert it
Data = ADData / ADSLOPE; // to voltages.
cprintf("%6.3f ", Data); // Display 'Data'.
if ((++i % NUM_OF_CHAN) == 0)
gotoxy(7, 5 + i/NUM_OF_CHAN); // Next line.
if (i == (10 * NUM_OF_CHAN)) {
i = 0; // Next screen.
gotoxy(7, 5);
} //if
} //while
getch(); // Get the pressed character.
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 + -