/* X703IntDemo.C: Demo program for X703 Compiler: BC++ 3.1 Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X703funsDemo. ..\..\..\..\lib\7188xbl.lib ..\..\..\..\lib\XBoard\X703.lib Hardware: 7188XB + X703 [16/Oct/2008] by Vic */ /********************************************************************************/ /* X703: 3-axis encoder counter */ /********************************************************************************/ #include #include #include #include "..\..\..\..\lib\7188xb.h" #include "..\..\..\..\lib\XBoard\x703.h" extern unsigned long EncLatch1,EncLatch2,EncLatch3;//defined in int.c extern void InstallInt0Isr(void); extern void InstallInt1Isr(void); extern void InstallInt4Isr(void); extern void RestoreInt0Isr(void); extern void RestoreInt1Isr(void); extern void RestoreInt4Isr(void); void read_enc1(long *); void read_enc2(long *); void read_enc3(long *); int xor1,xor2,xor3,mode1,mode2,mode3; long EncVal1,EncVal2,EncVal3; main() { char Mode[3][15]={"cw\ccw","pulse/dir","a/b"}; int hwID; InitLib(); X703_Init(); Print("\nxor1 = (0 or 1) ?"); xor1=Getch()-'0'; if (xor1) xor1=1; X703_SetXOR(1,xor1); try_again1: Print("\nmode1 = (1=cw/ccw,2=pule/dir,3=a/b) ?"); mode1=Getch()-'0'; X703_SetMode(1,mode1); Print("\nxor2 = (0 or 1) ?"); xor2=Getch()-'0'; if (xor2) xor2=1; X703_SetXOR(2,xor2); try_again2: Print("\nmode2 = (1=cw/ccw,2=pule/dir,3=a/b) ?"); mode2=Getch()-'0'; X703_SetMode(2,mode2); Print("\nxor3 = (0 or 1) ?"); xor3=Getch()-'0'; if (xor3) xor3=1; X703_SetXOR(3,xor3); try_again3: Print("\nmode3 = (1=cw/ccw,2=pule/dir,3=a/b) ?"); mode3=Getch()-'0'; X703_SetMode(3,mode3); X703_ResetEncoder(1); X703_ResetEncoder(2); X703_ResetEncoder(3); InstallInt0Isr();//Install interrupt service routine for Z1 InstallInt1Isr();//Install interrupt service routine for Z2 InstallInt4Isr();//Install interrupt service routine for Z3 for (;;) { if (Kbhit()) { RestoreInt0Isr(); RestoreInt1Isr(); RestoreInt4Isr(); Getch(); return; } read_enc1(&EncVal1); read_enc2(&EncVal2); read_enc3(&EncVal3); Print("\n(mode1=%s,enc1=%lx) (mode2=%s,enc2=%lx) (mode3=%s,enc3=%lx)",Mode[mode1-1],EncVal1,Mode[mode2-1],EncVal2,Mode[mode3-1],EncVal3); Print("(Latch1=%lx,Latch2=%lx,Latch3=%lx)",EncLatch1,EncLatch2,EncLatch3); DelayMs(100); } } // --------------------------------------------------------------- void read_enc1(long *enc1) { X703_Read24BitEncoder(1,enc1); //X703_Read32BitEncoder(1,enc1); } void read_enc2(long *enc2) { X703_Read24BitEncoder(2,enc2); //X703_Read32BitEncoder(2,enc2); } void read_enc3(long *enc3) { X703_Read24BitEncoder(3,enc3); //X703_Read32BitEncoder(3,enc3); }