/* Demo for 8080 (Mix mode) Software: Compiler: BC++ 3.1 Compile mode: large Project: PulseDir.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 A0/B0 = Pulse/Dir mode A1/B1 = Up/Down mode A2/B2 = Freq mode (auto mode) A3/B3 = Up mode Wiring: For Ch0, Ch1(A0,B0) = Pulse/Dir mode if (B0 is active) --> A0 = Up counting Ch0, Ch1 if (B0 is inactive) --> A0 = Down counting Ch0, Ch1 For Ch2, Ch3(A1,B1) = Up/Down mode A1 = Up counting B1 = Down counting Ch4=A2=Freq (auto mode) Ch5=B2=Freq (auto mode) 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 Uses 8080 lib version 2.0.1 Clears all count at beginning. */ #include "..\..\..\..\lib\8000E.h" #include "..\..\..\..\lib\8080.h" main(void) { int i,slot,channel,iRet; unsigned long T1,T2,T3; long Counter; int Overflow; unsigned long Frequency; unsigned long UpCounter; unsigned int UpOverflow; Print("/*********************************/\n\r"); Print("/* 8080 demo (Mix mode) */\n\r"); Print("/* */\n\r"); Print("/* A0/B0: Pulse/Dir */\n\r"); Print("/* A1/B1: Up/Down */\n\r"); Print("/* A2,B2: Freq */\n\r"); Print("/* A3,B3: Up */\n\r"); Print("/* */\n\r"); Print("/* [2004,Mar,07] */\n\r"); Print("/*********************************/\n\r"); Print("Press any key to clear all counters.\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_SetLowPassFilter_Status(slot,channel,0); //Disable LPF i8080_SetLowPassFilter_Us(slot,channel,1);//Set LPF width= 0.001 ms } iRet=i8080_SetChannelMode(slot,0,0); // Pulse/Dir counter mode for A0/B0 if(iRet>0) Print("The Pulse/Dir channel has one count offset.\n\r"); i8080_SetChannelMode(slot,2,1); // Up/Down counter mode for A1/B1 i8080_SetChannelMode(slot,4,2); // Freq mode for A2 i8080_SetChannelMode(slot,5,2); // Freq mode for B2 i8080_SetFreqMode(slot,4,0); // 0=Auto mode ==> update time=330 ms i8080_SetFreqMode(slot,5,0); // 0=Auto mode ==> update time=330 ms i8080_SetChannelMode(slot,6,3); // Up counter mode for A3 i8080_SetChannelMode(slot,7,3); // Up counter mode for B3 //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_ReadCntPulseDir(slot,0,&Counter,&Overflow); Print("Pulse/Dir: A0/B0 Overflow=%d,Count=%08ld\n\r",Overflow,Counter); i8080_ReadCntUpDown(slot,2,&Counter,&Overflow); Print("Up/Down : A1/B1 Overflow=%d,Count=%08ld\n\r",Overflow,Counter); i8080_ReadFreq(slot,4,&Frequency); Print("Frequency: A2=%06lu ",Frequency); i8080_ReadFreq(slot,5,&Frequency); Print("B2=%06lu\n\r",Frequency); i8080_ReadCntUp(slot,6,&UpCounter,&UpOverflow); Print("Up : A3 Overflow=%04d,Count=%08lu ",UpOverflow,UpCounter); i8080_ReadCntUp(slot,7,&UpCounter,&UpOverflow); Print("B3 Overflow=%04d,Count=%08lu\n\r\n\r",UpOverflow,UpCounter); } if (Kbhit()) { if(Getch()=='q') //Press 'q' to quit the program. { return; } else //Press any key to clear all counters. { Print("Clear all counters.\n\r"); iRet=i8080_ClrCnt(slot,0); //Clear Pulse/Dir counter A0/B0 if(iRet>0) Print("The Pulse/Dir channel has one count offset.\n\r"); i8080_ClrCnt(slot,2); //Clear Up/Down counter A1/B1 i8080_ClrCnt(slot,6); //Clear Up counter A3 i8080_ClrCnt(slot,7); //Clear Up counter B3 } } } } return; }