/* X324Demo.c: Demo program for X324 Compiler: MSC 6.0 MSVC 1.52 Compile mode: large Project: X324Demo.c ..\..\Lib\7188el.lib ..\..\lib\Xboard\X324.lib [Jan, 2, 2011] by Nicholas */ /******************************************************************/ /* X324: 4 channel 12-Bit D/A (Analog output) 0.0~5.0V */ /* 4 channel D/O */ /******************************************************************/ /******************************************************************/ /* [Software specific] */ /* Output range: +0.0V +10.0V */ /* Decimal integer: 0 4095 */ /* Hexadecimal: 000 FFF */ /* */ /* [D/A] */ /* thoughput: 1300 data/sec (with floating convertion) */ /* Accuracy==> Maximum: +/- 0.002% LSB */ /* */ /* [D/O] */ /* throughput: can generates 2KHz square wave signals. */ /******************************************************************/ /******************************************************************/ /* [Caution] */ /* The EEPROM block 7 on Xboard is used to */ /* store A/D & D/A calibration settings. When you use the */ /* EEPROM on Xboard, do not overwrite it. */ /******************************************************************/ #include #include "..\..\lib\7188e.h" #include "..\..\lib\XBoard\X324.h" void main(void) { int iRet, iAction, i, quit; int iOutChannel, iDOValue, iStatus; float fValue; char buf[100]; InitLib(); iRet=X324_Init(); if(iRet!=0) { for(i=0; i<4; i++) { if((iRet>>i*2)&0x1) Print("No setting in EEPROM, D/A Gain (Ch%d) ==> %+8.6f\r\n", i, X324_fDA_Gain[i]); if((iRet>>i*2+1)&0x1) Print("No setting in EEPROM, D/A Offset (Ch%d) ==> %+8.6f\r\n", i, X324_fDA_Offset[i]); } } Puts("\n\rDemo program for 7188EX + X324\n\r"); while(iAction!=6) { iAction=0; quit=0; Puts("\n\r"); Puts("1) D/A (Analog output)\n\r"); Puts("2) Write DO (all channels)\n\r"); Puts("3) Write DO (one channel)\n\r"); Puts("4) DO Readback (all channels)\n\r"); Puts("5) DO Readback (one channel)\n\r"); Puts("\n\r"); Puts("6) Quits demo program\n\r\n\r"); Puts("Choose an option and press [Enter]:"); LineInput(buf,99); sscanf(buf, "%d", &iAction); Puts("\n\r"); switch(iAction) { // D/A (Analog output) case 1: Puts("Channel (0 ~ 3): "); LineInput(buf,99); sscanf(buf, "%d", &iOutChannel); Puts("Voltage (0.0 ~ +5.0): "); LineInput(buf,99); sscanf(buf, "%f", &fValue); X324_AnalogOut(iOutChannel, fValue); Print("AO[%d] %5.3fV OK.\n\r", iOutChannel, fValue); break; // Write DO (all channels) case 2: Print("Please input Output value(0 ~ 0xF): "); LineInput(buf,99); sscanf(buf, "%x", &iDOValue); X324_Write_All_DO(iDOValue); Print("Output value=> 0x%02X\r\n\r\n", iDOValue); break; // Write DO (one channel) case 3: Print("Please select outport channel(0~3) and status(0:OFF, 1:ON)\n\r"); Print("Channel number and status:"); LineInput(buf,99); sscanf(buf, "%d %d", &iOutChannel,&iStatus); if(iOutChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } X324_Write_One_DO(iOutChannel, iStatus); Print("Channel %d ==> %s\r\n\r\n", iOutChannel, (iStatus>=1)?"ON":"OFF"); break; // Read DO (all channels) case 4: iDOValue=X324_Read_All_DO(); Print("Digital Output ReadBack=> 0x%02X\r\n\r\n", iDOValue); break; // Read DO (one channels) case 5: Print("Please select outport channel(0~3): "); LineInput(buf,99); sscanf(buf, "%d", &iOutChannel); if(iOutChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iRet=X324_Read_One_DO(iOutChannel); if(iRet) Print("Channel %d ==> ON\r\n\r\n", iOutChannel); else Print("Channel %d ==> OFF\r\n\r\n", iOutChannel); break; case 6: default: quit=1; break; } if(!quit) { Puts("Press any key to continue...\n\r"); Getch(); Print("\n\r"); } } }