/* X702funsDemo.c: Demo program for X702 Compiler: BC++ 3.1 Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X702funs Demo. ..\..\..\..\lib\7188xbl.lib or 7186EL.LIB or 7188EL.LIB ..\..\..\..\lib\XBoard\X702.lib Hardware: 7188XB\7188EX\7186EX + X702 Description: Show how to use every function for X702. Setting for encode: Step1: Set XOR logic Step2: Choose encode counting mode => cw/ccw,pulse/dir,(Quadrant)a/b phase Step3: Read encode counting value and show status for A/B/Z [5/Mar/2010] by Vic */ /********************************************************************************/ /* X702: 2-axis encoder counter */ /********************************************************************************/ #include #include #include "..\..\..\..\lib\7188xb.h" #include "..\..\..\..\lib\XBoard\X702.h" void Show_ABZ(int); void main(void) { char data; int i,LibVer,ch=2,hwID,LatticeVer,read32bit=0; int xor[2],tmpxor,mode[2],tmpmode; long EncVal[2]; unsigned char LibDate; InitLib(); X702_Init(); //Check Hardware is old or new hwID=X702_GetHardwareID(); Print("\nHardware ID is 0x%x",hwID); //Read lattice version (only for new X702 whose hardware ID is 0x72) LatticeVer=X702_GetLatticeVersion(); if(LatticeVer>0) Print("\nLattice Version=%04x",LatticeVer); else Print("\nThe hardware can't use X702_GetLatticeVersion()"); LibVer=X702_GetLibVersion(); Print("\nLibrary version=%04x",LibVer); X702_GetLibDate(&LibDate); Print("\nLibrary date=%02x",LibDate); for(i=0;i3) goto try_again; //Step2: Choose encode counting mode => cw/ccw,pulse/dir,(Quadrant)a/b phase X702_SetMode(i+1,mode[i]); } for(i=0;i