| Details | Message |
|---|
Read-Only Author heibuluo heibuluo Posted 17-Mar-2002 14:21 GMT Toolset None |  How to rework "printf" function to use for two UARTS in the cygnal's MCU? heibuluo heibuluo Hi,everyone! A problem here:The cygnal's MCU has two serial ports,so "printf" function must be reworked.But I don't know how to do it. Give me a hand! Thanks a lot!
|
|
Read-Only Author Mike Kleshov Posted 17-Mar-2002 14:56 GMT Toolset None |  RE: How to rework Mike Kleshov You can rework putchar to use both ports. There is also sprintf which knows nothing about ports. Regards, - Mike
|
|
Read-Only Author Mark Odell Posted 17-Mar-2002 16:15 GMT Toolset None |  RE: How to rework Mark Odell See my UART driver example at http://www.embeddedfw.com for how to do this. Basically, you just re-define putchar() which Keil's printf() calls. When ever you override a library function, the linker will take your function and not the library version.
- Mark |
|
Read-Only Author Andrew Neil Posted 17-Mar-2002 20:27 GMT Toolset None |  RE: How to rework Andrew Neil Note that the printf library function is huge - it has to be to support all those formats & options!
I think you'll find that the classic "Hello, world" first 'C' program will take up nearly all the 2K codespace limit of the C51 Eval version!
For embedded stuff, it's usually better to write your own routines, implementing only those specific features which are actually needed in your application. You could then include a parameter which specifies which serial port to use.
I did this, and included a "null" value for the port - this makes it easy, for example, to turn debug output on & off without obfuscating your mainline code with loads of "if( debug )" clauses. |
|
Read-Only Author Mark Odell Posted 18-Mar-2002 00:05 GMT Toolset None |  RE: How to rework Mark Odell Instead of if (debug) clauses, try this:
#ifdef DBG
# define debug
#else
# define debug while (0)
#endif
// Usage: single line
debug printf("Got here\n");
// Usage: multiple line
debug
{
g_errno = 12;
printf("Got error, %d\n", g_errno);
}
Now watch the magic happen when you don't define DBG.
Regards.
- Mark |
|
Read-Only Author Alex Ruiz Posted 18-Mar-2002 06:32 GMT Toolset C51 |  RE: How to rework Alex Ruiz You may check this info.:
http://www.keil.com/support/docs/788.htm |
|
Read-Only Author Andrew Neil Posted 18-Mar-2002 09:45 GMT Toolset None |  RE: How to rework Andrew Neil Mark,
Yes, of course, that gives you compile-time control to produce an image which either has debug output or doesn't.
I needed the ability to enable/disable the debug output at run-time
In fact, I did also use conditional-compilation so that I could build either a completely "clean" (debug-free) image, or one with the runtime-controllable debug |
|
Read-Only Author heibuluo heibuluo Posted 18-Mar-2002 13:47 GMT Toolset None |  RE: How to rework heibuluo heibuluo Hi,My friends. I will have a try! Thank you very much!
|
|
Read-Only Author Jon Ward Posted 18-Mar-2002 16:57 GMT Toolset None |  RE: How to rework Jon Ward This is a start on this problem:
//-----------------------------------------------
#include "stdio.h"
volatile unsigned char sio_selector = 0;
//-----------------------------------------------
char putchar (char c)
{
if (sio_selector == 0)
{
while (!TI_0); /* wait until transmitter ready */
TI_0 = 0;
SBUF0 = c; /* output character */
}
else
{
while (!TI_1); /* wait until transmitter ready */
TI_1 = 0;
SBUF1 = c; /* output character */
}
return (c);
}
//-----------------------------------------------
char _getkey (void)
{
char c;
if (sio_selector == 0)
{
while (!RI_0); /* wait for a character */
c = SBUF0;
RI_0 = 0; /* clear receive interrupt bit */
}
else
{
while (!RI_1); /* wait for a character */
c = SBUF1;
RI_1 = 0; /* clear receive interrupt bit */
}
return (c);
}
//-----------------------------------------------
void main (void)
{
//Initialize SIO0
//Initialize SIO1
while (1)
{
sio_selector = 0;
printf ("Serial Port 0\r\n");
sio_selector = 1;
printf ("Serial Port 1\r\n");
}
}
//-----------------------------------------------
Of course this is polled and uses the putchar and _getkey functions. You'll have to provide your own code to initialize the serial ports and timers.
Jon |
|