<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Printf</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/13723/printf</link><description> When I use printf, the uP hangs. 
When I use SBUF it owrks fine, what can be the problem ??? 
Hope someone can help me. 
I use an Atmel 89c52. 
 
Kindest regards, 
 
Ben Goofers 
 
 
 
#include &amp;lt;At89x52.h&amp;gt; /* special function register declarations *</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Printf</title><link>https://community.arm.com/thread/36895?ContentTypeID=1</link><pubDate>Thu, 28 Sep 2000 08:00:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5cb6f896-4e92-41c9-b94e-9eb6265dc6b6</guid><dc:creator>Mark Odell</dc:creator><description>&lt;p&gt;Be sure you don&amp;#39;t enable that serial interrupt (IE.ES should be 0) since you don&amp;#39;t have an ISR to handle the serial interrupt. I see you figured that out.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
// Override the default putchar() used by printf(). Just put this
// function in your project (maybe uart.c) and link it in.
// ANSI says take in and return int but we&amp;#39;ll use char since we don&amp;#39;t 
// return error status anyway and char is much more friendly to the 8051.
char putchar(char outChar)
{
    // CR -&amp;gt; CR/LF translation if needed.
    if (&amp;#39;\n&amp;#39; == outChar) 
    {
        SBUF = &amp;#39;\r&amp;#39;;
        while (!TI);
        TI = 0;
    }

    // Send the caller&amp;#39;s char and be sure it shifts out before returning.
    SBUF = outChar;
    while (!TI);
    TI = 0;
    
    return outChar;
}
&lt;/pre&gt;
&lt;br /&gt;
Hope this helps. Once you own putchar() you can force printf() to work over any device you want, LCD, Ethernet, shared memory, etc. Of course you wouldn&amp;#39;t use SBUF for these other devices.&lt;br /&gt;
&lt;br /&gt;
- Mark&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>