/* Demo for 8080 (Up counter mode) Software: Compiler: BC++ 3.1 Compile mode: large Project: Up.c 8081L.Lib 8000L.Lib Hardware: I-8000 MCU + 8081 Channel configurations: Xor=0 for Low Actived (signal from High to Low ==> change count) Low pass filters disabled all channel are set to up counter Wiring: Ch0=A0=Up counter Ch1=B0=Up counter Ch2=A1=Up counter Ch3=B1=Up counter Ch4=A2=Up counter Ch5=B2=Up counter Ch6=A3=Up counter Ch7=B3=Up counter */ /* [2005,Mar,08] by Kevin Use 8081 lib version 1.0.0 */ #include "..\..\..\..\lib\8000E.h" #include "..\..\..\..\lib\8081.h" void main(void) { int i,slot,channel,iRet; unsigned long T1,T2,T3; unsigned long Counter; char sTemp[20]; InitLib(); i8081_GetLibDate(sTemp); Print("**************************************\n\r"); Print(" 8081 demo (Up counter mode) \n\r"); Print(" compiled [%s] \n\r",__DATE__); Print("\n\r"); Print(" Lib version %x\n\r",i8081_GetLibVersion()); Print(" Lib dated %s\n\r",sTemp); Print("**************************************\n\r"); Print("Press 'c' to clear all counters.\n\r"); Print("Press 'q' to quit.\n\r\n\r"); Print("Slot number (0~7)="); Scanf("%d",&slot); iRet=i8081_Init(slot); if (iRet==(-1)) { Print("Initiate 8081 on slot%d error!\n\r",slot); Print(" Cannot find 8081."); } else { Print("Initiate 8081 on slot%d ok.\n\r",slot); Print("\n\r"); Print("Firmware version = %d\n\r",i8081_GetFirmwareVersion(slot)); for (channel=0; channel<8; channel++) { i8081_SetXorRegister(slot,channel,0); // XOR=0 (Low Actived) i8081_SetChannelMode(slot,channel,1); // Up counter mode //mode 0: Pulse/Dir counter mode // 1: Up/Down counter mode // 2: A-B phase mode // 3: Stop counting i8081_SetSignalSource(slot,channel,0); // Isolated input i8081_SetLowPassFilter_Status(slot,channel,1); // last argument enables/disables LPF i8081_SetLowPassFilter_Level(slot,1); //Set LPF width (micro seconds) } Print("Press any key to start.\n\r"); Getch(); //Clear all count at beginning. for (channel=0; channel<8; channel++) { i8081_ClrCnt(slot,channel); } T1=GetTimeTicks(); T2=T1; for (;;) { T3=GetTimeTicks(); if ((T3-T1) >=50) // Auto scan 8081 every 50 ms (one time one slot) { T1=T3; i8081_AutoScan(); } if ((T3-T2) >=500) // Print Counter value every 500 ms { T2=T3; for(channel=0;channel<8;channel++) { i8081_ReadCntUp(slot,channel,&Counter); Print("Ch%d=%ld ",channel,Counter); } Print("\n\r"); } if (Kbhit()) { iRet=Getch(); if(iRet=='q') //Press 'q' to quit the program. { return; } else if(iRet=='c') //Press any key to clear counter 0. { for(channel=0;channel<8;channel++) i8081_ClrCnt(slot,channel); Print("Clear all counters.\n\r"); } } } } }