/* Demo for 8080 (Up counter mode) Software: Compiler: BC++ 3.1 Compile mode: large Project: Up.c 8080L.Lib 8000L.Lib Hardware: I-8000 MCU + 8080 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 */ /* [2004,Dec,23] by Kevin Use 8080 lib version 2.0.0 [2004,Mar,07] by Kevin Use 8080 lib version 2.0.1 Clear all count at beginning. */ #include "..\..\..\..\lib\8000E.h" #include "..\..\..\..\lib\8080.h" void main(void) { int i,slot,channel,iRet; unsigned long T1,T2,T3; unsigned long Counter; unsigned int Overflow; Print("/*********************************/\n\r"); Print("/* 8080 demo (Up counter mode) */\n\r"); Print("/* */\n\r"); Print("/* [2004,Dec,23] */\n\r"); Print("/*********************************/\n\r"); Print("Press any key to clear counter (A0/B0).\n\r"); Print("Press 'q' to quit.\n\r\n\r"); 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 (channel=0; channel<8; channel++) { i8080_SetXorRegister(slot,channel,0); // XOR=0 (Low Actived) i8080_SetChannelMode(slot,channel,3); // Up counter mode //mode 0: Pulse/Dir counter mode // 1: Up/Down counter mode // 2: frequency mode // 3: Up counter mode i8080_SetLowPassFilter_Status(slot,channel,0); //Disable LPF i8080_SetLowPassFilter_Us(slot,channel,1); //Set LPF width= 0.001 ms } //Clear all count at beginning. for (channel=0; channel<8; channel++) { i8080_ClrCnt(slot,channel); } T1=GetTimeTicks(); T2=T1; for (;;) { T3=GetTimeTicks(); if ((T3-T1) >50) // Auto scan 8080 every 50 ms (one time one slot) { T1=T3; i8080_AutoScan(); } if ((T3-T2) >500) // Print frequency every 500 ms { T2=T3; i8080_ReadCntUp(slot,0,&Counter,&Overflow); Print("Up: A0 Overflow=%04d,Count=%08lu ",Overflow,Counter); i8080_ReadCntUp(slot,1,&Counter,&Overflow); Print("B0 Overflow=%04d,Count=%08lu\n\r",Overflow,Counter); } if (Kbhit()) { if(Getch()=='q') //Press 'q' to quit the program. { return; } else //Press any key to clear counter 0. { i8080_ClrCnt(slot,0); Print("Clear counter 0.\n\r"); } } } } }