Hi,
Sorry for the mistake. Here is the question again:
I need to use 89C52 timer2 counter function. However, when I use the timer2, I cannot use printf function to debug my program, that is, no display output. However, printf function works fine for timer0 and timer1 function.
How I can use printf within the timer2 program?
Thanks
Ed
are you trying to do a prinf in an ISR?, that does not work
Erik
I wrote timer0, timer1 and timer2 counter all in one program. When I invoke timer0, or timer1, I can use printf in the main program and the ISR. However, when I invoke timer2, I cannot use the printf in the ISR and the main program. System not hang, but just ignore to display.
Any idea?
I posted are you trying to do a prinf in an ISR?, that does not work
you reply I cannot use the printf in the ISR
what's the issue?
Erik, sorry for the confusion. My questions are:
1. Timer2 cannot use printf in ISR. Can I use printf in the main program?
2. Why timer0 and timer1 can use printf in the main program and ISR?
Once again, thanks for your prompt reply.
Unless I am missing something is not T2 or T1 to be dedicated as a baud rate generated for serial output? If you are using printf through the serial port (which is the default behavior with putchar). This means you either cannot use T1 or you cannot use T2 as a regular timer and use the serial port. If you intend to use both those timers no serial port, otherwise you must select one timer to generate the baud clock. Some variants of the C51 allow external baud rate generation I believe.
Stephen
It's not so much that you can't use printf in an ISR - you can do it, and you might get away with it...
The trouble is:
* printf is a huge function - and that's Bad for an ISR;
* the default printf uses polled output - and that's Bad for an ISR;
* printf is not reentrant - and that's really bad if you also call it from main!
Thanks for all info.
I am not intent to use printf in timer2 ISR but in the main to debug my program.
Any method to get this done or forget printf in timer2 environment?
If you want to use printf() in a configuration where you don't have a baudrate generator, then you have to bit-blit some I/O pins to emulate the UART. Not funny at all. And really dreadful if you need to be able to receive data too.
I am using Keil uVision 3 - Keil Monitor-51 to simulate/debug my program. Keil using TX/RX pin for the serial I/O to download the program. In that case, they already config baud rate generator.
I don't know why printf cannot work under timer2 counter environment, but working under timer0,timer1 environment using Keil Monitor-51?
My mistake of using Keil Monitor or malfuntion of my hardware?