/* X303Demo.c: Demo program for X303 Compiler: BC++ 3.1 Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X303Demo.c ..\..\lib\7188xbl.lib ..\..\lib\XBoard\X303.lib Hardware: 7188XB + X303 [June/5/2002] by David [May/20/2005] by Liam [05/July/2005] by Liam */ /********************************************************************/ /* X303: 1 channel 12-Bit A/D (Analog input) +-5.0V */ /* 1 channel 12-Bit D/A (Analog output) +-5.0V */ /* 4 channel D/I */ /* 6 channel D/O */ /********************************************************************/ /********************************************************************/ /* [Software specific] */ /* Input/Output range: -5.0V -0.0V +0.0V +5.0V */ /* Decimal integer: 0 2047 2048 4095 */ /* Hexadecimal: 000 7FF 800 FFF */ /* */ /* [A/D] */ /* sampling rate: 1800 data/sec (with floating convertion) */ /* Accuracy==> Typical: +- 1 LSB (+- 2.4 mV) */ /* Maximum: +- 2 LSB (+- 4.8 mV) */ /* [D/A] */ /* thoughput : 1300 data/sec (with floating convertion) */ /* Accuracy==> Typical: +- 1 LSB (+- 2.4 mV) */ /* Maximum: +- 2 LSB (+- 4.8 mV) */ /* [D/O] */ /* throughput: can generates 2KHz square wave signals. */ /********************************************************************/ /********************************************************************/ /* [Caution] */ /* The block 7 first 16 bytes of EEPROM on X board is used to */ /* store A/D & D/A calibration settings. When you use the */ /* EEPROM on X board, don't overwrite it. */ /********************************************************************/ #include #include "..\..\lib\7188xb.h" #include "..\..\lib\XBoard\X303.h" void main(void) { int iRet, iAction, j, quit; int iValue, iInChannel, iDIValue, iOutChannel, iDOValue, iStatus; float fValue; InitLib(); X303_Init(); //Initialize the X303 Puts("\r\nDemo program for 7188XB + X303\r\n"); while(iAction!=10) { iAction=0; quit=0; Puts("\r\n"); Puts("1) Reads setting from EEPROM\r\n"); Puts("2) A/D (Analog input)\r\n"); Puts("3) D/A (Analog output)\r\n"); Puts("4) Read DI (all channels)\r\n"); Puts("5) Read DI (one channel)\r\n"); Puts("6) Write DO (all channels)\r\n"); Puts("7) Write DO (one channel)\r\n"); Puts("8) DO Readback (all channels)\r\n"); Puts("9) DO Readback (one channel)\r\n"); Puts("\r\n"); Puts("10) Quits demo program\r\n\r\n"); Puts("Choose an option and press [Enter]:"); Scanf("%d", &iAction); Puts("\r\n"); switch(iAction) { // Reads settings from EEPROM(on X board) case 1: iValue=X303_Init(); if((iValue&1)==0) Print("EEPROM A/D Gain ==> [%8.6f]\r\n", fAD_Gain); else Print("No setting in EEPROM, A/D Gain ==> %8.6f\r\n", fAD_Gain); if((iValue&2)==0) Print("EEPROM A/D Offset ==> [%8.6f]\r\n", fAD_Offset); else Print("No setting in EEPROM, A/D Offset ==> %8.6f\r\n", fAD_Offset); if((iValue&4)==0) Print("EEPROM D/A Gain ==> [%8.6f]\n\r",fDA_Gain); else Print("No setting in EEPROM, D/A Gain ==> %8.6f\r\n", fDA_Gain); if((iValue&8)==0) Print("EEPROM D/A Offset ==> [%8.6f]\n\r",fDA_Offset); else Print("No setting in EEPROM, D/A Offset ==> %8.6f\r\n", fDA_Offset); Puts("\n\r"); break; // A/D (Analog input) case 2: fValue=X303_AnalogIn(); iRet=Print("AI[0]= %6.4fV\r\n\r\n", fValue); break; // D/A (Analog output) case 3: Puts("Voltage (-5.0 ~ +5.0): "); Scanf("%f",&fValue); X303_AnalogOut(fValue); Print("AO[0] %5.3fV OK.\r\n\r\n", fValue); break; // Read DI (all channels) case 4: iDIValue=X303_Read_All_DI(); Print("Input value=> 0x%02x\r\n\r\n", iDIValue); break; // Read DI (one channel) case 5: Print("Please select inport channel(0~3): "); Scanf("%d", &iInChannel); if(iInChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iDIValue=X303_Read_One_DI(iInChannel); if(iDIValue) Print("Channel %d ==> OFF\r\n\r\n", iInChannel); else Print("Channel %d ==> ON\r\n\r\n", iInChannel); break; // Write DO (all channels) case 6: Print("Please input Output value(0 ~ 0x3f): "); Scanf("%x", &iDOValue); X303_Write_All_DO(iDOValue); Print("Output value=> 0x%02x\r\n\r\n", iDOValue); break; // Write DO (one channel) case 7: Print("Please select outport channel(0~5) and status(0:OFF, 1:ON)\n\r"); Print("Channel number and status:"); Scanf("%d %d", &iOutChannel, &iStatus); if(iOutChannel>5) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } X303_Write_One_DO(iOutChannel, iStatus); Print("Channel %d ==> %s\r\n\r\n", iOutChannel, (iStatus>=1)?"ON":"OFF"); break; // Read DO (all channels) case 8: iDOValue=X303_Read_All_DO(); Print("Digital Output ReadBack=> 0x%02x\r\n\r\n", iDOValue); break; // Read DO (one channels) case 9: Print("Please select outport channel(0~5): "); Scanf("%d", &iOutChannel); if(iOutChannel>5) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iRet=X303_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 10: default: quit=1; break; } if(!quit) { Puts("Press any key to continue...\n\r"); Getch(); } } }