#include #include #include #include #include #include "SSH0XDRV.H" unsigned BaseAddress=0x0350; unsigned LoadValue = 0, InitDelay = 0; void ExitProgram(uint errorCode) { clrscr(); puts("A fatal error occured, program halted!"); printf("Error code returned was %i.\n", errorCode); } unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ int main(void) { uint *buf = (unsigned*) malloc(16); char Choice = 1; uint i, error; clrscr(); BaseAddress=AskForBaseAddress(BaseAddress); // Prompt for base address SetBaseAddress(BaseAddress); // Tell driver the base address // to use puts("Borland C Language Sample for SSH-0x. Version 1.06\n\n"); puts("This sample will show how to use the driver in mode 5."); puts("Specs for mode 5:"); puts(" Software initiated (SEL3)."); puts(" Hardware timed periodic acquisition, with delay.\n"); puts("A/D Card setup:"); printf(" Card is at base address %3X Hex.\n", BaseAddress); puts(""); puts("SSH-0x Card setup:"); puts(" Please place the A/D CH SEL jumper at 0."); puts(" Switch A and C should be ON, B should be OFF on MODE CONTROL."); puts(" MASTER, 1, and 4 should be ON. Switches 2 and 3 should be OFF.\n"); puts("Press any key to continue...\n"); getch(); clrscr(); puts("Counter 1 will be loaded with an initial count and will count down"); puts("until it reaches zero. When it does, the following will occur:"); puts("Hold will be enabled by setting OP3 (PIN 10) high. The SSH-0x card"); puts("will then gather eight data points, one from each channel. (If you"); puts(" are using an SSH-04 card, CH4-CH7 should be ignored.) When"); puts("acquisition is completed, the card will be placed back into Sample"); puts("mode and the values will be displayed. Press a key to proceed..."); getch(); // The clock input is 1Mhz for the AD12-8G card, because of this, the input // to the second counter will be 500000Hz. A load value of 50000 is // required to achieve a 10Hz sampling rate. if (AD_NAME() == AD128GCARD) LoadValue = 50000; // The desired initial delay is 100ms. This requires a load value of 50000. if (AD_NAME() == AD128GCARD) InitDelay = 50000; // The same applies to the AIO8 card. if (AD_NAME() == AIO8CARD) LoadValue = 50000; if (AD_NAME() == AIO8CARD) InitDelay = 50000; clrscr(); while (Choice) { // As long as user wants to // continue // Call driver --- // Parameter list // 1 : First channel is channel number 0 // 2 : Last channel is channel number 7 // 3 : Repeat for 2 passes // 4 : Trigger source is by software // 5 : Initial delay is InitDelay // 6 : Acquistion controlled by counters, so period is LoadValue // 7 : IRQ not necessary, set to 0 // 8 : Use Mode 5 // 9 : Data buffer is buf Sample(); puts("Waiting for terminal count (about .1 secs)...press a key to abort"); error = PerformSSHDataAcquisition(0,7,2,1,InitDelay,LoadValue,0,5,buf); if (error) { ExitProgram(error); return error; } EnableHold(); // Enable Hold clrscr(); puts(" Pass 1 Pass 2 "); puts("\n Channel Volts Channel Volts\n"); // display data for for (i=0;i<=7;i++) // 8 channels used printf(" %2u % 1.3f " " %2u % 1.3f\n\r", i, (float)(buf[i] * (10.0 / 4096.0)) - 5.0, i, (float)(buf[i + 8] * (10.0 / 4096.0)) - 5.0); // display in volts puts("\n"); puts("\n\n\nPress spacebar to repeat or any other key to exit."); Choice = getch() == ' '; // repeat as // long as space // bar is hit } puts("Exiting Sample 5 Program..."); return 0; }