#include #include #define UPPERLIMIT 27 #define LOWERLIMIT 43 #define LEFTLIMIT 25 #define RIGHTLIMIT 55 #define GRIPOPEN 40 #define GRIPCLOSED 53 #define CYCLETIME 150 #define DELAYCYCLES 1 void main() { int done; int count; int vert; int horz; int claw; PORTC = 0x00; DDRC = 0x00; PORTD = 0x00; DDRD = 0xFF; done = 0; vert = 40; /* vertical location */ horz = 30; /* horizontal location */ claw = 40; /* grip location */ while(!done){ count = 0; if(PORTDbits.RD0 == 1){ /* down button */ if(vert < LOWERLIMIT){ /* lower limit block */ vert = vert + 1; /* movement */ } } if(PORTDbits.RD1 == 1){ /* up */ if(vert > UPPERLIMIT){ vert = vert - 1; } } if(PORTDbits.RD2 == 1){ /* left */ if(horz > LEFTLIMIT){ horz = horz - 2; } } if(PORTDbits.RD3 == 1){ /* right */ if(horz < RIGHTLIMIT){ horz = horz + 2; } } if(PORTDbits.RD4 == 1){ /* open grip */ if(claw > GRIPOPEN){ claw = claw - 1; } } if(PORTDbits.RD5 == 1){ /* close grip */ if(claw < GRIPCLOSED){ claw = claw + 1; } } while(count < DELAYCYCLES) { /* location delay */ PORTCbits.RC0 = 1; /* start elevation pulse */ Delay100TCYx(vert); PORTCbits.RC0 = 0; PORTCbits.RC1 = 1; /* start rotation pulse */ Delay100TCYx(horz); PORTCbits.RC1 = 0; PORTCbits.RC2 = 1; /* start grip pulse */ Delay100TCYx(claw); PORTCbits.RC2 = 0; count = count + 1; Delay100TCYx(CYCLETIME); /* delay before restarting pulse generation */ } }} /* end main */