We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm trying to pause at while (TL0 <= 10) {} until I get a count of 10. When I run the program, the program doesn't pause at while (TL0 <= 10) {}. It's like the while is false. Can any one see something I don't? // Setup TH0 Timer0 for 16-bit counter mode TMOD = (TMOD & 0xF0) | 0x05; //Set the counter0 Run control bit. TR0 = 1; while (1) { //reset Tiimer0 (counter) TL0 = 0; // Toggle P3.4 increment the count while (TL0 <= 10) {} //The rest of the code }
Hi Glenn, is your problem concerning real device or debugger? The program is certainly ok and it works well in real device provided that contact toggling T0 pin is debounced. It's easy to demonstrate it if you display the TL0 content on a port with appropriately connected LEDs. Of course, you must stop timer 0 immediately after while(..). It always shows 11, ie. 0x0B. In this demonstration even no contact debouncing is needed. In debugger, when the program is running @ full speed, it really works as you described. When stepping, it works well! A strange thing, in my opinion, is that timer 0 counts when toggling T0 even when program is stopped. I think it should be incremented only after at least one instruction has been executed. I suspect it can have a connection with the problem. I am convinced that this is a bug in the debugger. Eric