/* Demo for 8080 (Read/Set config) Software: Compiler: BC++ 3.1 Compile mode: large Project: Config.c 8080L.Lib 8000L.Lib Hardware: I-8000 MCU + 8080 */ /* [2004,Dec,23] by Kevin Use 8080 lib version 2.0.0 [2004,Mar,07] by Kevin Uses 8080 lib version 2.0.1 */ #include "..\..\..\..\lib\8000E.h" #include "..\..\..\..\lib\8080.h" void Print_Binary(int value); main(void) { int lib_version; char lib_date[20]; int slot,channel,iRet; unsigned long T1,T2,T3; unsigned long Frequency,Count; int Overflow; int option,mode; unsigned int width; int updatetime_auto,updatetime_low,updatetime_high; Print("/*********************************/\n\r"); Print("/* 8080 demo (Read/Set config) */\n\r"); Print("/* */\n\r"); Print("/* [2004,Mar,07] */\n\r"); Print("/*********************************/\n\r"); lib_version=i8080_GetLibVersion(); Print("8080 Lib version = %d.%d.%d\n\r",(lib_version&0xF00)>>8, (lib_version&0xF0)>>4, lib_version&0xF); i8080_GetLibDate(lib_date); Print("8080 Lib data = %s\n\r\n\r",lib_date); Print("Slot number (0~7)="); Scanf("%d",&slot); iRet=i8080_InitDriver(slot); if (iRet==(-1)) { Print("Initiate 8080 on slot%d error!\n\r",slot); Print(" Cannot find 8080."); } else { Print("Initiate 8080 on slot%d ok.\n\r",slot); if(iRet>0) { Print(" Some Pulse/Dir channels have one count offset.\n\r"); Print(" Return code:%02X\n\r",iRet); } for(;;) { Print("0) quit\n\r"); Print("1) Read Channel mode\n\r"); Print("2) Read XOR registers\n\r"); Print("3) Read Low Pass filter status (Disable/Enasable)\n\r"); Print("4) Read Low Pass filter signal width\n\r"); Print("5) Read Frequency opration mode\n\r"); Print("6) Read Frequency update time\n\r"); Print("\n\r"); Print("11) Set Channel mode\n\r"); Print("12) Set XOR registers\n\r"); Print("13) Set Low Pass filter status (Disable/Enasable)\n\r"); Print("14) Set Low Pass filter signal width\n\r"); Print("15) Set Frequency opration mode\n\r"); Print("16) Set Frequency update time\n\r"); Print("17) Recover Default Setting\n\r"); Print("Please choose (0~17):"); Scanf("%d",&option); Print("\n\r"); if(option==0) return 0; switch(option) { case 1: Print("Read Channel mode:\n\r"); for(channel=0;channel<8;channel++) { i8080_ReadChannelMode(slot,channel,&mode); if(mode==0) Print(" ==> Ch%d=0: Pulse/Dir\n\r",channel); else if(mode==1) Print(" ==> Ch%d=1: Up/Down\n\r",channel); else if(mode==2) Print(" ==> Ch%d=2: Freq\n\r",channel); else if(mode==3) Print(" ==> Ch%d=3: Up\n\r",channel); } break; case 2: Print("Read XOR register\n\r"); for(channel=0;channel<8;channel++) { i8080_ReadXorRegister(slot,channel,&mode); if(mode==0) Print(" ==> XOR %d = 0 (Low Actived)\n\r",channel); else Print(" ==> XOR %d = 1 (High Actived)\n\r",channel); } break; case 3: Print("Read Low Pass Filter status\n\r"); for(channel=0;channel<8;channel++) { i8080_ReadLowPassFilter_Status(slot,channel,&mode); if(mode==0) Print(" ==> Ch%d=0: disabled\n\r",channel); else Print(" ==> Ch%d=1: enabled\n\r",channel); } break; case 4: Print("Read Low Pass filter signal width\n\r"); for(channel=0;channel<8;channel++) { i8080_ReadLowPassFilter_Us(slot,channel,&width); Print(" ==> Ch%d=%u (0.001 ms)\n\r",channel,width); } break; case 5: Print("Read Frequency opration mode\n\r"); for(channel=0;channel<8;channel++) { i8080_ReadFreqMode(slot,channel,&mode); if(mode==0) Print(" ==> Ch%d=Auto mode\n\r",channel); else if(mode==1) Print(" ==> Ch%d=Low freq mode\n\r",channel); else Print(" ==> Ch%d=High freq mode\n\r",channel); } break; case 6: Print("Read Frequency update time\n\r"); i8080_ReadFreqUpdateTime(slot,&updatetime_auto,&updatetime_low,&updatetime_high); Print(" ==> Auto mode=%d ms\n\r",updatetime_auto); Print(" ==> Low mode=%d ms\n\r",updatetime_low); Print(" ==> High mode=%d ms\n\r",updatetime_high); break; case 11: Print("Set channel mode\n\r"); Print(" Channel(0~7)="); Scanf("%d",&channel); Print(" Channel mode(0~3)="); Scanf("%d",&mode); iRet=i8080_SetChannelMode(slot,channel,mode); Print("iRet=%d\n\r",iRet); if(iRet>0) Print("Set ok. But the Pulse/Dir channel has one count offset.\n\r"); break; case 12: Print("Set XOR registers\n\r"); Print(" Channel(0~7)="); Scanf("%d",&channel); Print(" XOR (0: Low Actived, 1:High Actived)="); Scanf("%d",&mode); iRet=i8080_SetXorRegister(slot,channel,mode); if(iRet>0) Print("Set ok. But the Pulse/Dir channel has one count offset.\n\r"); break; case 13: Print("Set Low Pass Fileter status\n\r"); Print(" Channel(0~7)="); Scanf("%d",&channel); Print(" Disable/Enable(0 or 1)="); Scanf("%d",&mode); i8080_SetLowPassFilter_Status(slot,channel,mode); break; case 14: Print("Set Low Pass filter signal width\n\r"); Print(" Channel(0~7)="); Scanf("%d",&channel); Print(" width(1~32767)(Unit: 0.001ms)="); Scanf("%d",&width); i8080_SetLowPassFilter_Us(slot,channel,width); break; case 15: Print("Set Frequency opration mode\n\r"); Print(" Channel(0~7)="); Scanf("%d",&channel); Print(" 0)Auto mode\n\r"); Print(" 1)Low freq mode\n\r"); Print(" 2)High freq mode\n\r"); Print(" Mode(0~2)="); Scanf("%d",&mode); i8080_SetFreqMode(slot,channel,mode); break; case 16: Print("Set Frequency update time (1~32757ms)\n\r"); Print(" 0)Auto mode update time="); Scanf("%d",&updatetime_auto); Print(" 1)Low freq mode update time="); Scanf("%d",&updatetime_low); Print(" 2)High freq mode update time="); Scanf("%d",&updatetime_high); i8080_SetFreqUpdateTime(slot,updatetime_auto, updatetime_low, updatetime_high); break; case 17: i8080_RecoverDefaultSetting(slot); iRet=i8080_InitDriver(slot); break; } Print("=============================================\n\r\n\r"); } } return 0; } void Print_Binary(int value) { if (value&0x80) Print("Ch7=1 "); else Print("Ch7=0 "); if (value&0x40) Print("Ch6=1 "); else Print("Ch6=0 "); if (value&0x20) Print("Ch5=1 "); else Print("Ch5=0 "); if (value&0x10) Print("Ch4=1 "); else Print("Ch4=0 "); if (value&0x08) Print("Ch3=1 "); else Print("Ch3=0 "); if (value&0x04) Print("Ch2=1 "); else Print("Ch2=0 "); if (value&0x02) Print("Ch1=1 "); else Print("Ch1=0 "); if (value&0x01) Print("Ch0=1 \n\r"); else Print("Ch0=0 \n\r"); }