/* Demo for 8080 (Basic mode) Software: Compiler: BC++ 3.1 Compile mode: large Project: Basic.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 Use 8080 lib version 2.0.1 Clear 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; int ChannelMode,XOR,LPF_Status; unsigned int LPF_Us; Print("/*********************************/\n\r"); Print("/* 8080 demo (Basic mode) */\n\r"); Print("/* */\n\r"); Print("/* [2004,Mar,07] */\n\r"); Print("/*********************************/\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++) { Print("Ch%d:",channel); i8080_ReadChannelMode(slot,channel,&ChannelMode); switch(ChannelMode) { case 0: Print("Pulese/Dir mode "); break; case 1: Print("Up/Down mode "); break; case 2: Print("Freq mode "); break; case 3: Print("Up mode "); break; } i8080_ReadXorRegister(slot,channel,&XOR); Print("XOR=%d ",XOR); i8080_ReadLowPassFilter_Status(slot,channel,&LPF_Status); Print("LPF status(On/Off)=%d ",LPF_Status); i8080_ReadLowPassFilter_Us(slot,channel,&LPF_Us); Print("LPF signal width(0.001ms)=%d ",LPF_Us); Print("\n\r"); } Print("Press any key to start.\n\r"); Getch(); //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) >250) // Print frequency every 500 ms { T2=T3; for(channel=0;channel<8;channel++) { if(i8080_ChannelMode[slot][channel]==0) { i8080_ReadCntPulseDir(slot,channel,&Counter,&Overflow); Print("Ch%d Pulse/Dir Count=%08lX [Hex] Overflow=%04X [Hex]\n\r",channel,Counter,Overflow); channel++; } else if(i8080_ChannelMode[slot][channel]==1) { i8080_ReadCntUpDown(slot,channel,&Counter,&Overflow); Print("Ch%d Up/Down Count=%08lX [Hex] Overflow=%04X [Hex]\n\r",channel,Counter,Overflow); channel++; } else if(i8080_ChannelMode[slot][channel]==2) { i8080_ReadFreq(slot,channel,&Frequency); Print("Ch%d Freq=%08ld [Dec]\n\r",channel,Frequency); } else if(i8080_ChannelMode[slot][channel]==3) { i8080_ReadCntUp(slot,channel,&UpCounter,(unsigned int*)&Overflow); Print("Ch%d Up Count=%08lX [Hex] Overflow=%04X [Hex]\n\r",channel,UpCounter,Overflow); } } Print("\n\r"); } } } return; }