/* X202Demo.c: Demo program for X202 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X202Demo.c ..\..\Lib\7188xbl.lib ..\..\Lib\Xboard\X202.lib Hardware: 7188XB + X202 [20/June/2002] by David [20/May/2005] by Liam [05/July/2005] by Liam */ /********************************************************************/ /* X202: 7 channel 12-Bit A/D (Analog input) 0 ~ 20mA */ /********************************************************************/ /********************************************************************/ /* [Software specific] */ /* Input/Output range: +0.0V(0.0mA) +2.5V(20mA) */ /* Decimal integer: 000 4095 */ /* Hexadecimal: 800 FFF */ /* */ /* [A/D] */ /* sampling rate: 1800 data/sec (with floating convertion) */ /* Accuracy==> Typical: +- 1 LSB (+- 0.6 mV or 4.8mA) */ /* Maximum: +- 2 LSB (+- 1.2 mV or 9.6mA) */ /* [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\X202.h" void main(void) { int iAction, quit; int iChannel,iValue; float fValue; InitLib(); X202_Init(); //Initialize the X202 Puts("\r\nDemo program for 7188XB + X202\r\n"); while(iAction!=3) { iAction=0; quit=0; Puts("\r\n"); Puts("1) Reads setting from EEPROM\r\n"); Puts("2) A/D (Analog input)\n\r"); Puts("\r\n"); Puts("3) 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=X202_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]\n\r",fAD_Offset); else Print("No setting in EEPROM, A/D Offset ==> %8.6f\r\n", fAD_Offset); break; // A/D (Analog input) case 2: Puts("Please select A/D channel(0~6): "); Scanf("%d",&iChannel); if(iChannel>6) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } fValue=X202_AnalogIn(iChannel); Print("AI[%d]= %6.4fmA\r\n", iChannel, fValue); break; case 3: default: quit=1; break; } if(!quit) { Puts("Press any key to continue...\r\n"); Getch(); } } }