Main Page   Compound List   File List   Compound Members   File Members  

rprintf.h

Go to the documentation of this file.
00001 
00002 //****************************************************************************
00003 //
00004 // File Name    : 'rprintf.h'
00005 // Title                        : printf routine and associated routines
00006 // Author               : Pascal Stang - Copyright (C) 2000-2002
00007 // Created              : 2000.12.26
00008 // Revised              : 2002.08.23
00009 // Version              : 0.8
00010 // Target MCU   : Atmel AVR series and other targets
00011 // Editor Tabs  : 3
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //              which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //****************************************************************************
00021 
00022 #ifndef RPRINTF_H
00023 #define RPRINTF_H
00024 
00025 // needed for use of PSTR below
00026 #include <progmem.h>
00027 
00028 // defines/constants
00029 #define STRING_IN_RAM   0
00030 #define STRING_IN_ROM   1
00031 
00032 // make a putchar for those that are used to using it
00033 #define putchar(c)      rprintfChar(c);
00034 
00035 // functions
00036 
00037 // initializes the rprintf library for an output stream
00038 // you must call this initializer once before using any other rprintf function
00039 // the argument must be a single-character stream output function
00040 void rprintfInit(void (*putchar_func)(unsigned char c));
00041 
00042 // prints a single character to the current output device
00043 void rprintfChar(unsigned char c);
00044 
00045 // prints a string stored in RAM
00046 void rprintfStr(char str[]);
00047 
00048 // prints a section of a string stored in RAM
00049 // begins printing at position indicated by <start>
00050 // prints number of characters indicated by <len>
00051 void rprintfStrLen(char str[], unsigned char start, unsigned char len);
00052 
00053 // prints a string stored in program rom
00054 // NOTE: this function does not actually store your string in
00055 // program rom, but merely reads it assuming you stored it properly.
00056 void rprintfProgStr(char str[]);
00057 // Using the function rprintfProgStrM(...) automatically causes 
00058 // your string to be stored in ROM, thereby not wasting precious RAM
00059 // Example usage:
00060 // rprintfProgStrM("Hello, this string is stored in program rom");
00061 #define rprintfProgStrM(string)                 (rprintfProgStr(PSTR(string)))
00062 
00063 // prints a carriage return and line feed
00064 // **useful when printing to serial ports/terminals
00065 void rprintfCRLF(void);
00066 
00067 // prints the number contained in "data" in hex format
00068 // u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively
00069 void rprintfu04(unsigned char data);
00070 void rprintfu08(unsigned char data);
00071 void rprintfu16(unsigned short data);
00072 void rprintfu32(unsigned long data);
00073 
00074 // a flexible integer number printing routine
00075 void rprintfNum(char base, char numDigits, char isSigned, char padchar, long n);
00076 
00077 void rprintfFloat(char numDigits, double x);
00078 
00079 // NOTE: Below you'll see the function prototypes of rprintf1RamRom and 
00080 // rprintf2RamRom.  rprintf1RamRom and rprintf2RamRom are both reduced versions
00081 // of the regular C printf() command.  However, they are modified to be able
00082 // to read their text/format strings from RAM or ROM in the Atmel microprocessors.
00083 // Unless you really intend to, do not use the "RamRom" versions of the functions
00084 // directly.  Instead use the #defined function versions:
00085 //
00086 // printfx("text/format",args)    ...to keep your text/format string stored in RAM
00087 //              - or -
00088 // printfxROM("text/format",args) ...to keep your text/format string stored in ROM
00089 //
00090 // where x is either 1 or 2 for the simple or more powerful version of printf()
00091 //
00092 // Since there is much more ROM than RAM available in the Atmel microprocessors,
00093 // and nearly all text/format strings are constant (never change in the course
00094 // of the program), you should try to use the ROM printf version exclusively.
00095 // This will ensure you leave as much RAM as possible for program variables and
00096 // data.
00097 
00098 // a simple printf routine
00099 int rprintf1RamRom(unsigned char stringInRom, const char *format, ...);
00100 // #defines for RAM or ROM operation
00101 #define rprintf1(format, args...)               rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
00102 #define rprintf1RAM(format, args...)    rprintf1RamRom(STRING_IN_RAM, format, ## args)
00103 
00104 // a more powerful printf routine
00105 int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...);
00106 // #defines for RAM or ROM operation
00107 #define rprintf2(format, args...)               rprintf2RamRom(STRING_IN_ROM, format, ## args)
00108 #define rprintf2RAM(format, args...)    rprintf2RamRom(STRING_IN_RAM, format, ## args)
00109 
00110 // *** Default rprintf(...) ***
00111 // this next line determines what the the basic rprintf() defaults to:
00112 #define rprintf(format, args...)                rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
00113 
00114 #endif

Generated at Fri Oct 25 15:36:38 2002 for avrlib by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001