00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIN32
00023
00024 #include <avr/io.h>
00025 #include <avr/pgmspace.h>
00026 #endif
00027
00028 #include "glcd.h"
00029
00030
00031 #include "ks0108.h"
00032
00033 #include "font5x7.h"
00034 #include "fontgr.h"
00035
00036
00037
00038
00039 void glcdSetDot(u08 x, u08 y)
00040 {
00041 unsigned char temp;
00042
00043 glcdSetAddress(x, y/8);
00044 temp = glcdDataRead();
00045 temp = glcdDataRead();
00046 glcdSetAddress(x, y/8);
00047 glcdDataWrite(temp | (1 << (y % 8)));
00048
00049 glcdStartLine(0);
00050 }
00051
00052
00053 void glcdClearDot(u08 x, u08 y)
00054 {
00055 unsigned char temp;
00056
00057 glcdSetAddress(x, y/8);
00058 temp = glcdDataRead();
00059 temp = glcdDataRead();
00060 glcdSetAddress(x, y/8);
00061 glcdDataWrite(temp & ~(1 << (y % 8)));
00062
00063 glcdStartLine(0);
00064 }
00065
00066
00067 void glcdLine(u08 x1, u08 y1, u08 x2, u08 y2)
00068 {
00069 };
00070
00071
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
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
00111
00112
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
00123 glcdDataWrite(0x00);
00124
00125
00126
00127
00128
00129
00130
00131
00132 glcdStartLine(0);
00133 }
00134
00135 void glcdWriteCharGr(u08 grCharIdx)
00136 {
00137 u08 idx;
00138 u08 grLength;
00139 u08 grStartIdx = 0;
00140
00141
00142 for(idx=0; idx<grCharIdx; idx++)
00143 {
00144
00145
00146 grStartIdx += pgm_read_byte(FontGr+grStartIdx);
00147 }
00148 grLength = pgm_read_byte(FontGr+grStartIdx);
00149
00150
00151 for(idx=0; idx<grLength; idx++)
00152 {
00153
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 }