#include #include #include #include #include unsigned int BASE = 0x300; #define uint unsigned int void CtrMode(uint addr, char cntr, char mode) { int ctrl; ctrl = (cntr << 6) | 0x30 | (mode << 1); outportb(addr+3,ctrl); } void CtrLoad(uint addr ,int c,int val) { outportb(addr+c,val & 0x00FF); outportb(addr+c,(val>>8) & 0x00FF); } unsigned AskForBaseAddress(unsigned int OldOne) { char msg[8]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("Please enter the Base Address (100-FFFF) 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); if (NewOne >= 0x100) { Success = 1; Dummy = NewOne; } else if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ void intro () { clrscr(); puts("This program will output three wave forms from the 104-DA12-8."); puts("The wave forms will be output on DACS 0 - 2."); puts("The wave forms will stop when the program exits."); } void main (void) { unsigned int BUFFER[30000]; int count; intro(); BASE = AskForBaseAddress(BASE); printf("Address Selected: %04X",BASE); /***************************************************** ** This for loop will fill the buffer with the following ** three wave forms and rescales them to have the same period: ** 1) sin(x^2) from x = -3.3 to 3.3 ** 2) cos(x^2) from x = -3.0 to 3.0 ** 3) sin(x^2) * cos (x^2) from x = -1.9 to 1.9 *****************************************************/ for (count = 0; count < 10000; count++) { BUFFER[(count * 3)] = int(sin(pow(-3.3 + (.00066 * count), 2)) * 2047.0 + 2048.0); BUFFER[(count * 3)] &= 0x0fff; //need to be certain that the control bits are what we want BUFFER[((count * 3) + 1)] = int(cos(pow(-3.0 + (.0006 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 1)] &= 0x0fff; BUFFER[((count * 3) + 2)] = int(sin(pow(-1.9 + (.00038 * count), 2)) * cos(pow(-1.9 + (.00038 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 2)] &= 0x0fff; //let the card know that this is the end of this scan BUFFER[((count * 3) + 2)] |= 0x2000; } BUFFER[29999] |= 0x1000; //this is the end of the stream and the card needs to loop //now we need to fill the SRAM on the card; outportb(BASE + 0x1a, 0); //we will only be writing to the first 30k addresses //so we get to leave bit 16 of the SRAM addr at 0 for (count = 0; count < 30000; count++) { outport(BASE + 0x18, (count * 2)); //set the address we are going to write to outport(BASE + 0x1c, BUFFER[count]); //write the value for that address } CtrMode(BASE + 0x14, 1, 2); //set counter 1 to mode 2 CtrMode(BASE + 0x14, 2, 2); //set counter 2 to mode 2 CtrLoad(BASE + 0x14, 1, 5); //load counter 1 to 5 ticks CtrLoad(BASE + 0x14, 2, 10); //load counter 2 to 10 ticks outportb(BASE + 0x10, 0x41); //tell the card to start and enable the //ARB puts("\nPress any key to stop"); do { NULL; }while (!kbhit()); outportb(BASE + 0x10, 0); //tell the card to stop clrscr(); }