Hi, When I execute the first putchar statement in the code below, nothing is printed to the serial window, when I execute the second putchar statement, the value I thought would print out firstly (0xFF) prints out now. In the for loop I have printed the value i, but likewise the value for i prints out after executing the second putchar statement in that loop. Any ideas why this is happening? Also I have reset the value of counter1 to 2, but as I am stepping through the putchar statements, counter1 increases. I cant see how this can happen as the only way the counter can increment is in the ADC interrupt routine, but the program doesn't jump to this routine in the meantime? If anyone can help, it would be great! Lisa
if(finished) { rec1[buf].cnt = counter1; // store counter1 value in 1st element of array buf ^= 1; // set alternative buffer up counter1 = 2; // reset counter1 to original value // print out whole structure putchar(rec1[!buf].cnt); putchar((char) (rec1[!buf].base_value >> 8)); putchar((char) (rec1[!buf].base_value)); for(i = 0; i < MAX_COUNT-2; i++) { putchar(i); putchar(rec1[!buf].x[i]); } finished = 0; }
"Any ideas why this is happening?" Yes, but I don't know whether they are correct... I've noticed this in the simulator. I wonder whether it tries to do serial output in 'real time', eg one character per millisecond at 9600 baud. Maybe the time the simulator takes to get from the first putchar to the next breakpoint is less than 1ms, hence the character doesn't appear. I also notice that the last character transmitted often doesn't appear in the serial window if the program terminates shortly after stuffing it into SBUF. In general I find the simulator a waste of time as it introduces so many 'variables' that don't exist on the target hardware. I find myself spending too much time wondering why the program doesn't work as expected in the simulator when it does work on the target.
Thanks Stefan, I'm blaming the simulator too!
Hi Jon, That makes sense. Thanks. However, why would the variable, counter1, in the snippet of code in the first message, keep incrementing while these putchar statements are executing? The program has not jumped to my ADC interrupt routine where this value is used. When it does jump to the ADC ISR during putchar(), it is also incremented (as expected). Regards, Lisa
why would the variable, counter1, in the snippet of code in the first message, keep incrementing while these putchar statements are executing? I don't know. I haven't seen the interrupt routine or the A/D initialization code. And, I prefer not to guess. I could come up with 100 things that could be wrong but aren't. Jon
View all questions in Keil forum