?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{FILE START}

library

?curdirlinks? - Rev 6

?prevdifflink? - Blame - ?getfile?

<!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: glcd.c Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>glcd.c</h1><a href="glcd_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file glcd.c \brief Graphic LCD API functions. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name    : 'glcd.c'</span>
00005 <span class="comment">// Title        : Graphic LCD API functions</span>
00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002</span>
00007 <span class="comment">// Date         : 5/30/2002</span>
00008 <span class="comment">// Revised      : 5/30/2002</span>
00009 <span class="comment">// Version      : 0.5</span>
00010 <span class="comment">// Target MCU   : Atmel AVR</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 WIN32</span>
00023 <span class="preprocessor"></span><span class="comment">// AVR specific includes</span>
00024 <span class="preprocessor">    #include &lt;avr/io.h&gt;</span>
00025 <span class="preprocessor">    #include &lt;avr/pgmspace.h&gt;</span>
00026 <span class="preprocessor">#endif</span>
00027 <span class="preprocessor"></span>
00028 <span class="preprocessor">#include "<a class="code" href="glcd_8h.html">glcd.h</a>"</span>
00029 
00030 <span class="comment">// include hardware support</span>
00031 <span class="preprocessor">#include "<a class="code" href="ks0108_8h.html">ks0108.h</a>"</span>
00032 <span class="comment">// include fonts</span>
00033 <span class="preprocessor">#include "<a class="code" href="font5x7_8h.html">font5x7.h</a>"</span>
00034 <span class="preprocessor">#include "<a class="code" href="fontgr_8h.html">fontgr.h</a>"</span>
00035 
00036 <span class="comment">// graphic routines</span>
00037 
00038 <span class="comment">// set dot</span>
<a name="l00039"></a><a class="code" href="glcd_8h.html#a10">00039</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(u08 x, u08 y)
00040 {
00041     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
00042 
00043     <a class="code" href="ks0108_8c.html#a15">glcdSetAddress</a>(x, y/8);
00044     temp = glcdDataRead();  <span class="comment">// dummy read</span>
00045     temp = glcdDataRead();  <span class="comment">// read back current value</span>
00046     <a class="code" href="ks0108_8c.html#a15">glcdSetAddress</a>(x, y/8);
00047     glcdDataWrite(temp | (1 &lt;&lt; (y % 8)));
00048 
00049     <a class="code" href="ks0108_8c.html#a14">glcdStartLine</a>(0);
00050 }
00051 
00052 <span class="comment">// clear dot</span>
<a name="l00053"></a><a class="code" href="glcd_8h.html#a11">00053</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a1">glcdClearDot</a>(u08 x, u08 y)
00054 {
00055     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp;
00056 
00057     <a class="code" href="ks0108_8c.html#a15">glcdSetAddress</a>(x, y/8);
00058     temp = glcdDataRead();  <span class="comment">// dummy read</span>
00059     temp = glcdDataRead();  <span class="comment">// read back current value</span>
00060     <a class="code" href="ks0108_8c.html#a15">glcdSetAddress</a>(x, y/8);
00061     glcdDataWrite(temp &amp; ~(1 &lt;&lt; (y % 8)));
00062 
00063     <a class="code" href="ks0108_8c.html#a14">glcdStartLine</a>(0);
00064 }
00065 
00066 <span class="comment">// draw line</span>
<a name="l00067"></a><a class="code" href="glcd_8h.html#a12">00067</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a2">glcdLine</a>(u08 x1, u08 y1, u08 x2, u08 y2)
00068 {
00069 };
00070 
00071 <span class="comment">// draw rectangle</span>
<a name="l00072"></a><a class="code" href="glcd_8h.html#a13">00072</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a3">glcdRectangle</a>(u08 x, u08 y, u08 a, u08 b)
00073 {
00074   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> j;
00075 
00076   <span class="keywordflow">for</span> (j = 0; j &lt; a; j++) {
00077         <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(x, y + j);
00078         <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(x + b - 1, y + j);
00079     }
00080   <span class="keywordflow">for</span> (j = 0; j &lt; b; j++)   {
00081         <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(x + j, y);
00082         <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(x + j, y + a - 1);
00083     }
00084 }
00085 
00086 <span class="comment">// draw circle</span>
<a name="l00087"></a><a class="code" href="glcd_8h.html#a14">00087</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a4">glcdCircle</a>(u08 xcenter, u08 ycenter, u08 radius)
00088 {
00089   <span class="keywordtype">int</span> tswitch, y, x = 0;
00090   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> d;
00091 
00092   d = ycenter - xcenter;
00093   y = radius;
00094   tswitch = 3 - 2 * radius;
00095   <span class="keywordflow">while</span> (x &lt;= y) {
00096     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(xcenter + x, ycenter + y);     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(xcenter + x, ycenter - y);
00097     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(xcenter - x, ycenter + y);     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(xcenter - x, ycenter - y);
00098     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(ycenter + y - d, ycenter + x); <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(ycenter + y - d, ycenter - x);
00099     <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(ycenter - y - d, ycenter + x); <a class="code" href="glcd_8c.html#a0">glcdSetDot</a>(ycenter - y - d, ycenter - x);
00100 
00101     <span class="keywordflow">if</span> (tswitch &lt; 0) tswitch += (4 * x + 6);
00102     <span class="keywordflow">else</span> {
00103       tswitch += (4 * (x - y) + 10);
00104       y--;
00105     }
00106     x++;
00107   }
00108 }
00109 
00110 <span class="comment">// text routines</span>
00111 
00112 <span class="comment">// write a character at the current position</span>
<a name="l00113"></a><a class="code" href="glcd_8h.html#a15">00113</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a5">glcdWriteChar</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c)
00114 {
00115     u08 i = 0;
00116 
00117     <span class="keywordflow">for</span>(i=0; i&lt;5; i++)
00118     {
00119         glcdDataWrite(pgm_read_byte(&amp;Font5x7[((c - 0x20) * 5) + i]));
00120     }
00121 
00122     <span class="comment">// write a spacer line</span>
00123     glcdDataWrite(0x00);
00124     <span class="comment">// unless we're at the end of the display</span>
00125     <span class="comment">//if(xx == 128)</span>
00126     <span class="comment">//  xx = 0;</span>
00127     <span class="comment">//else </span>
00128     <span class="comment">//  glcdWriteData(0x00);</span>
00129 
00130     <span class="comment">//cbi(GLCD_Control, GLCD_CS1);</span>
00131     <span class="comment">//cbi(GLCD_Control, GLCD_CS2);</span>
00132     <a class="code" href="ks0108_8c.html#a14">glcdStartLine</a>(0);
00133 }
00134 
<a name="l00135"></a><a class="code" href="glcd_8h.html#a16">00135</a> <span class="keywordtype">void</span> <a class="code" href="glcd_8c.html#a6">glcdWriteCharGr</a>(u08 grCharIdx)
00136 {
00137     u08 idx;
00138     u08 grLength;
00139     u08 grStartIdx = 0;
00140 
00141     <span class="comment">// get starting index of graphic bitmap</span>
00142     <span class="keywordflow">for</span>(idx=0; idx&lt;grCharIdx; idx++)
00143     {
00144         <span class="comment">// add this graphic's length to the startIdx</span>
00145         <span class="comment">// to get the startIdx of the next one</span>
00146         grStartIdx += pgm_read_byte(FontGr+grStartIdx);
00147     }
00148     grLength = pgm_read_byte(FontGr+grStartIdx);
00149 
00150     <span class="comment">// write the lines of the desired graphic to the display</span>
00151     <span class="keywordflow">for</span>(idx=0; idx&lt;grLength; idx++)
00152     {
00153         <span class="comment">// write the line</span>
00154         glcdDataWrite(pgm_read_byte(FontGr+(grStartIdx+1)+idx));
00155     }
00156 }
00157 
00158 <span class="keywordtype">void</span> glcdPutStr(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *data)
00159 {
00160   <span class="keywordflow">while</span> (*data) {
00161     <a class="code" href="glcd_8c.html#a5">glcdWriteChar</a>(*data);
00162     data++;
00163   }
00164 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
{FILE END}
{FOOTER START}

Powered by WebSVN v2.8.3