📄 rprintf_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: rprintf.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>rprintf.h</h1><a href="rprintf_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file rprintf.h \brief printf routine and associated routines. */</span>00002 <span class="comment">//****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'rprintf.h'</span>00005 <span class="comment">// Title : printf routine and associated routines</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>00007 <span class="comment">// Created : 2000.12.26</span>00008 <span class="comment">// Revised : 2003.5.1</span>00009 <span class="comment">// Version : 1.0</span>00010 <span class="comment">// Target MCU : Atmel AVR series and other targets</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//****************************************************************************</span>00021 00022 <span class="preprocessor">#ifndef RPRINTF_H</span>00023 <span class="preprocessor"></span><span class="preprocessor">#define RPRINTF_H</span>00024 <span class="preprocessor"></span>00025 <span class="comment">// needed for use of PSTR below</span>00026 <span class="preprocessor">#include <avr/pgmspace.h></span>00027 00028 <span class="comment">// include configuration</span>00029 <span class="preprocessor">#include "<a class="code" href="rprintfconf_8h.html">rprintfconf.h</a>"</span>00030 00031 <span class="comment">// defines/constants</span>00032 <span class="preprocessor">#define STRING_IN_RAM 0</span>00033 <span class="preprocessor"></span><span class="preprocessor">#define STRING_IN_ROM 1</span>00034 <span class="preprocessor"></span>00035 <span class="comment">// make a putchar for those that are used to using it</span>00036 <span class="comment">//#define putchar(c) rprintfChar(c);</span>00037 00038 <span class="comment">// functions</span>00039 <span class="comment"></span>00040 <span class="comment">//! initializes the rprintf library for an output stream</span>00041 <span class="comment"></span><span class="comment">// you must call this initializer once before using any other rprintf function</span>00042 <span class="comment">// the argument must be a single-character stream output function</span>00043 <span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a6">rprintfInit</a>(<span class="keywordtype">void</span> (*putchar_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c));00044 <span class="comment"></span>00045 <span class="comment">//! prints a single character to the current output device</span>00046 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a7">rprintfChar</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);00047 <span class="comment"></span>00048 <span class="comment">//! prints a null-terminated string stored in RAM</span>00049 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a8">rprintfStr</a>(<span class="keywordtype">char</span> str[]);00050 <span class="comment"></span>00051 <span class="comment">//! prints a section of a string stored in RAM</span>00052 <span class="comment"></span><span class="comment">// begins printing at position indicated by <start></span>00053 <span class="comment">// prints number of characters indicated by <len></span>00054 <span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a9">rprintfStrLen</a>(<span class="keywordtype">char</span> str[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> start, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len);00055 <span class="comment"></span>00056 <span class="comment">//! prints a string stored in program rom</span>00057 <span class="comment"></span><span class="comment">// NOTE: this function does not actually store your string in</span>00058 <span class="comment">// program rom, but merely reads it assuming you stored it properly.</span>00059 <span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a10">rprintfProgStr</a>(<span class="keyword">const</span> prog_char str[]);00060 <span class="comment">// Using the function rprintfProgStrM(...) automatically causes </span>00061 <span class="comment">// your string to be stored in ROM, thereby not wasting precious RAM</span>00062 <span class="comment">// Example usage:</span>00063 <span class="comment">// rprintfProgStrM("Hello, this string is stored in program rom");</span>00064 <span class="preprocessor">#define rprintfProgStrM(string) (rprintfProgStr(PSTR(string)))</span>00065 <span class="preprocessor"></span><span class="comment"></span>00066 <span class="comment">//! prints a carriage return and line feed</span>00067 <span class="comment"></span><span class="comment">// useful when printing to serial ports/terminals</span>00068 <span class="keywordtype">void</span> <a class="code" href="rprintf_8c.html#a9">rprintfCRLF</a>(<span class="keywordtype">void</span>);00069 00070 <span class="comment">// prints the number contained in "data" in hex format</span>00071 <span class="comment">// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively</span>00072 <span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a12">rprintfu04</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data); <span class="comment">///< print 4-bit hex number</span>00073 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a13">rprintfu08</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data); <span class="comment">///< print 8-bit hex number</span>00074 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a14">rprintfu16</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> data); <span class="comment">///< print 16-bit hex number</span>00075 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a15">rprintfu32</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> data); <span class="comment">///< print 32-bit hex number</span>00076 <span class="comment"></span><span class="comment"></span>00077 <span class="comment">//! a flexible integer number printing routine</span>00078 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="rprintf_8h.html#a16">rprintfNum</a>(<span class="keywordtype">char</span> base, <span class="keywordtype">char</span> numDigits, <span class="keywordtype">char</span> isSigned, <span class="keywordtype">char</span> padchar, <span class="keywordtype">long</span> n);00079 00080 <span class="preprocessor">#ifdef RPRINTF_FLOAT</span>00081 <span class="preprocessor"></span><span class="comment"> //! floating-point print routine</span>00082 <span class="comment"></span> <span class="keywordtype">void</span> rprintfFloat(<span class="keywordtype">char</span> numDigits, <span class="keywordtype">double</span> x);00083 <span class="preprocessor">#endif</span>00084 <span class="preprocessor"></span>00085 <span class="comment">// NOTE: Below you'll see the function prototypes of rprintf1RamRom and </span>00086 <span class="comment">// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions</span>00087 <span class="comment">// of the regular C printf() command. However, they are modified to be able</span>00088 <span class="comment">// to read their text/format strings from RAM or ROM in the Atmel microprocessors.</span>00089 <span class="comment">// Unless you really intend to, do not use the "RamRom" versions of the functions</span>00090 <span class="comment">// directly. Instead use the #defined function versions:</span>00091 <span class="comment">//</span>00092 <span class="comment">// printfx("text/format",args) ...to keep your text/format string stored in RAM</span>00093 <span class="comment">// - or -</span>00094 <span class="comment">// printfxROM("text/format",args) ...to keep your text/format string stored in ROM</span>00095 <span class="comment">//</span>00096 <span class="comment">// where x is either 1 or 2 for the simple or more powerful version of printf()</span>00097 <span class="comment">//</span>00098 <span class="comment">// Since there is much more ROM than RAM available in the Atmel microprocessors,</span>00099 <span class="comment">// and nearly all text/format strings are constant (never change in the course</span>00100 <span class="comment">// of the program), you should try to use the ROM printf version exclusively.</span>00101 <span class="comment">// This will ensure you leave as much RAM as possible for program variables and</span>00102 <span class="comment">// data.</span>00103 00104 <span class="preprocessor">#ifdef RPRINTF_SIMPLE</span>00105 <span class="preprocessor"></span> <span class="comment">// a simple printf routine</span>00106 <span class="keywordtype">int</span> <a class="code" href="rprintf_8h.html#a17">rprintf1RamRom</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stringInRom, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...);00107 <span class="comment">// #defines for RAM or ROM operation</span>00108 <span class="preprocessor"> #define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>00109 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args)</span>00110 <span class="preprocessor"></span>00111 <span class="comment">// *** Default rprintf(...) ***</span>00112 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span>00113 <span class="preprocessor"> #define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>00114 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00115 <span class="preprocessor"></span>00116 <span class="preprocessor">#ifdef RPRINTF_COMPLEX</span>00117 <span class="preprocessor"></span> <span class="comment">// a more powerful printf routine</span>00118 <span class="keywordtype">int</span> rprintf2RamRom(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stringInRom, <span class="keyword">const</span> <span class="keywordtype">char</span> *sfmt, ...);00119 <span class="comment">// #defines for RAM or ROM operation</span>00120 <span class="preprocessor"> #define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args)</span>00121 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args)</span>00122 <span class="preprocessor"></span>00123 <span class="comment">// *** Default rprintf(...) ***</span>00124 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span>00125 <span class="preprocessor"> #define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>00126 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00127 <span class="preprocessor"></span>00128 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -