Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

glcd.c

Go to the documentation of this file.
00001 /*! \file glcd.c \brief Graphic LCD API functions. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'glcd.c'
00005 // Title        : Graphic LCD API functions
00006 // Author       : Pascal Stang - Copyright (C) 2002
00007 // Date         : 5/30/2002
00008 // Revised      : 5/30/2002
00009 // Version      : 0.5
00010 // Target MCU   : Atmel AVR
00011 // Editor Tabs  : 4
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 WIN32
00023 // AVR specific includes
00024     #include <avr/io.h>
00025     #include <avr/pgmspace.h>
00026 #endif
00027 
00028 #include "glcd.h"
00029 
00030 // include hardware support
00031 #include "ks0108.h"
00032 // include fonts
00033 #include "font5x7.h"
00034 #include "fontgr.h"
00035 
00036 // graphic routines
00037 
00038 // set dot
00039 void glcdSetDot(u08 x, u08 y)
00040 {
00041     unsigned char temp;
00042 
00043     glcdSetAddress(x, y/8);
00044     temp = glcdDataRead();  // dummy read
00045     temp = glcdDataRead();  // read back current value
00046     glcdSetAddress(x, y/8);
00047     glcdDataWrite(temp | (1 << (y % 8)));
00048 
00049     glcdStartLine(0);
00050 }
00051 
00052 // clear dot
00053 void glcdClearDot(u08 x, u08 y)
00054 {
00055     unsigned char temp;
00056 
00057     glcdSetAddress(x, y/8);
00058     temp = glcdDataRead();  // dummy read
00059     temp = glcdDataRead();  // read back current value
00060     glcdSetAddress(x, y/8);
00061     glcdDataWrite(temp & ~(1 << (y % 8)));
00062 
00063     glcdStartLine(0);
00064 }
00065 
00066 // draw line
00067 void glcdLine(u08 x1, u08 y1, u08 x2, u08 y2)
00068 {
00069 };
00070 
00071 // draw rectangle
00072 void glcdRectangle(u08 x, u08 y, u08 a, u08 b)
00073 {
00074   unsigned char j;
00075 
00076   for (j = 0; j < a; j++) {
00077         glcdSetDot(x, y + j);
00078         glcdSetDot(x + b - 1, y + j);
00079     }
00080   for (j = 0; j < b; j++)   {
00081         glcdSetDot(x + j, y);
00082         glcdSetDot(x + j, y + a - 1);
00083     }
00084 }
00085 
00086 // draw circle
00087 void glcdCircle(u08 xcenter, u08 ycenter, u08 radius)
00088 {
00089   int tswitch, y, x = 0;
00090   unsigned char d;
00091 
00092   d = ycenter - xcenter;
00093   y = radius;
00094   tswitch = 3 - 2 * radius;
00095   while (x <= y) {
00096     glcdSetDot(xcenter + x, ycenter + y);     glcdSetDot(xcenter + x, ycenter - y);
00097     glcdSetDot(xcenter - x, ycenter + y);     glcdSetDot(xcenter - x, ycenter - y);
00098     glcdSetDot(ycenter + y - d, ycenter + x); glcdSetDot(ycenter + y - d, ycenter - x);
00099     glcdSetDot(ycenter - y - d, ycenter + x); glcdSetDot(ycenter - y - d, ycenter - x);
00100 
00101     if (tswitch < 0) tswitch += (4 * x + 6);
00102     else {
00103       tswitch += (4 * (x - y) + 10);
00104       y--;
00105     }
00106     x++;
00107   }
00108 }
00109 
00110 // text routines
00111 
00112 // write a character at the current position
00113 void glcdWriteChar(unsigned char c)
00114 {
00115     u08 i = 0;
00116 
00117     for(i=0; i<5; i++)
00118     {
00119         glcdDataWrite(pgm_read_byte(&Font5x7[((c - 0x20) * 5) + i]));
00120     }
00121 
00122     // write a spacer line
00123     glcdDataWrite(0x00);
00124     // unless we're at the end of the display
00125     //if(xx == 128)
00126     //  xx = 0;
00127     //else 
00128     //  glcdWriteData(0x00);
00129 
00130     //cbi(GLCD_Control, GLCD_CS1);
00131     //cbi(GLCD_Control, GLCD_CS2);
00132     glcdStartLine(0);
00133 }
00134 
00135 void glcdWriteCharGr(u08 grCharIdx)
00136 {
00137     u08 idx;
00138     u08 grLength;
00139     u08 grStartIdx = 0;
00140 
00141     // get starting index of graphic bitmap
00142     for(idx=0; idx<grCharIdx; idx++)
00143     {
00144         // add this graphic's length to the startIdx
00145         // to get the startIdx of the next one
00146         grStartIdx += pgm_read_byte(FontGr+grStartIdx);
00147     }
00148     grLength = pgm_read_byte(FontGr+grStartIdx);
00149 
00150     // write the lines of the desired graphic to the display
00151     for(idx=0; idx<grLength; idx++)
00152     {
00153         // write the line
00154         glcdDataWrite(pgm_read_byte(FontGr+(grStartIdx+1)+idx));
00155     }
00156 }
00157 
00158 void glcdPutStr(unsigned char *data)
00159 {
00160   while (*data) {
00161     glcdWriteChar(*data);
00162     data++;
00163   }
00164 }

Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by  doxygen 1.4.2