As my first PIC project I tried to make a simple robot. It has two motors, driving two wheels. It also has two bumper switches. This has been done many times, but not by me. I used the normally open contacts of the switches. The program would have been slightly simpler if I had used the normally closed contacts. I typed a C program, using the MCC18 compiler. Here is the program: #include #pragma config WDT = OFF #pragma config OSC = HSPLL #define bumper_left 1 // RD0 #define bumper_right 2 // RD1 #define motor_left_rev 1 // RA0 #define motor_left_fwd 2 // RA1 #define motor_right_fwd 4 // RA2 #define motor_right_rev 8 // RA3 #define LED 16 // RA4 void wait(int i){ long count; for(count = 100000*i; count>0; count--)Nop(); } void main (void) { unsigned char bump; TRISD = bumper_left + bumper_right; // two bits input TRISA = 0xE0; // bits 0-4: output while(1){ PORTA = motor_left_fwd + motor_right_fwd; bump = PORTD & (bumper_left + bumper_right); if(bump<(bumper_left + bumper_right)){ PORTA = motor_left_rev + motor_right_rev + LED; wait(2); // turn if(bump == bumper_right) PORTA = motor_left_fwd + LED; else PORTA = motor_right_fwd + LED; wait(1); } } } When the program is started the contraption moves forward until it hits something. Then it just switches off the motors, does not go back, does not light the led. I tried every change I could think of, nothing worked. Until finally I moved just one line: void main (void) { unsigned char bump; TRISD = bumper_left + bumper_right; // two bits input TRISA = 0xE0; // bits 0-4: output while(1){ // the PORTA line is moved to the end............................. bump = PORTD & (bumper_left + bumper_right); if(bump<(bumper_left + bumper_right)){ PORTA = motor_left_rev + motor_right_rev + LED; wait(2); // turn if(bump == bumper_right) PORTA = motor_left_fwd + LED; else PORTA = motor_right_fwd + LED; wait(1); } PORTA = motor_left_fwd + motor_right_fwd; } } ...and then it worked. Once the while(1) loop is entered it should not make any difference where this line is. I tried to read the .lst file as produced by MCC18. I am not too familiar with the Assembler code yet, but I could not find anything unexpected there. Do you people have any ideas? Frank Abbing -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist