/************************************************************************ Controls the Serial port on the Jackrabbit, and sends quadrature results and whatnot in order to *************************************************************************/ int LQuad; //Used to store the last quadrature value. // General use milli-sec delay function nodebug void msDelay(unsigned int delay) { auto unsigned long done_time; done_time = MS_TIMER + delay; while( (long) (MS_TIMER - done_time) < 0 ); } void cls () { printf ( " \x1Bt" ); // Space Opens Window } int readQuadrature (){ //This function returns + if rolling fwd, - if rolling backwd. int quad,motion; motion=0; quad=RdPortI(PBDR)&3; //Just the lower 3 bits. if (quad==LQuad) return 0; //no change, so get the hell outta here. while (quad!=LQuad){ //printf ("[%d]",quad); if ((LQuad==3)&&(quad==2)) motion++; else if ((LQuad==2)&&(quad==3)) motion--; else if ((LQuad==3)&&(quad==2)) motion++; else if ((LQuad==2)&&(quad==0)) motion++; else if ((LQuad==0)&&(quad==2)) motion--; else if ((LQuad==0)&&(quad==1)) motion++; else if ((LQuad==1)&&(quad==3)) motion++; else if ((LQuad==1)&&(quad==0)) motion--; else if ((LQuad==3)&&(quad==1)) motion--; LQuad=quad; quad=RdPortI(PBDR)&3; //Just the lower 3 bits. }//while quad!=LQuad return motion; } void main() { int temp,but1,but2; temp=serBopen(9600); if (temp)printf("Opened at chosen baud\n"); else printf("Failed to open at chosen baud\n"); serBflowcontrolOff(); serBdatabits (PARAM_8BIT); serBparity (PARAM_NOPARITY); for (;;){ //First we read the quadrature input... temp+=readQuadrature(); //Next we check for over and under 4 ticks, to see if we have //moved. if (temp>=4){ temp-=4; printf("]\n"); serBputs("]\n"); } if (temp<=-4){ temp+=4; printf("[\n"); serBputs("[\n"); } //Next we check the button. Pin 2. if (!(RdPortI(PBDR)&4)){ msDelay(50); //debounce if (!((RdPortI(PBDR)&4))&&(!but1)){ but1=1; printf (" \n");//send the select switch output. serBputs(" \n"); } } else but1=0;//Turn off the flag. The button is up. //Next we check the button. Pin 3. if (!(RdPortI(PBDR)&8)){ msDelay(50); //debounce if (!((RdPortI(PBDR)&8))&&(!but2)){ but2=1; printf ("q\n");//send the select switch output. serBputs("q\n"); } } else but2=0;//Turn off the flag. The button is up. } //for ;; }