Hi all, I am trying to debug some code I have written and I can't seem to = understand why it is not working. The code builds fine, and I have = tested it on hardware, and in the simulator. I have included the code below (sorry about the size of it, didn't want = to leave out anything important!) The problem is if I output a character using putch(char) such as the = line directly after main() "putch(success+1);" and I step through using the simulator the program = seems to get stuck on the "while(1)" instruction and never seems to get = to the "if (encoder_count =3D=3D 50)".... If I comment out this first putch and change nothing else, the program = runs all the way through. I am getting consistant results from both the = simulator and hardware. Has anyone got any ideas? I am totally lost here as I don't see why = having that one putch line should cause the program not to work! Thanks for any help. kind regards, James Fitzsimons /********************************************************************** * * Filename: encoder.c *=20 * Description: Counts interrupts on portb from attached motor encoder.=20 * Every 50 clicks the PIC sends a message to the serial port. * =20 * * Notes: The constants in this file are specific to PIC 16F84=20 * hardware. * * Written by James Fitzsimons for PIC hardware * 13/12/01 * * **********************************************************************/ #include __CONFIG(UNPROTECT); // Cofiguration fuses XT|WDT off|PWT off|code = protect off #include "delay.h" void toggleLed(); void putch(char); char getch(void); void DelayMS(unsigned char); /********************************************************************** * * Function: main() * * Description: When the encoder count variable reaches 50 the PIC * sends a message to the PC. *=20 * Notes: An encoder is attached to portb. The code utilitses=20 * the interrupt on change functionality of the portb. * * Returns: This routine contains an infinite loop. * **********************************************************************/ unsigned int encoder_count =3D 0; char success =3D 65; unsigned char temp; void main(void) { // test to see that serial coms is up putch(success+1);=20 //enable interrupts GIE =3D 1; // enable RB port change interrupt RBIE =3D 1; =20 // clear the interrupt flag if set RBIF =3D 0; // setup RB7 as input TRISB7 =3D 1; // setup rest of portb as ouputs so as not to cause interrupts TRISB6 =3D 0; TRISB5 =3D 0; TRISB4 =3D 0; // setup RA1 as output TRISA1 =3D 0;=20 // endless loop counting interrupts on pin 7 of portb while(1) { // wait for interrupt if (encoder_count =3D=3D 50) { // send charater 'A' to terminal // disable interrupts so that timing for serial i/o isn't stuffed up GIE =3D 0; putch(success); // reset encoder_count encoder_count =3D 0; =20 // finished sending char so re-enable interrupts GIE =3D 1; } } } /* main() */ /************************** * * Interrupt Service Routine * **************************/ interrupt void isr(void) { =20 // check to see if interrupt on change flag set if ( RBIE && RBIF ) { // read portb temp =3D PORTB; // increment counter by one encoder_count =3D encoder_count + 1; // clear interrupt flag RBIF =3D 0; // toggle led to show in isr toggleLed(); } } -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body