Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file glcd.c \brief Graphic LCD API functions. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'glcd.c' |
||
5 | // Title : Graphic LCD API functions |
||
6 | // Author : Pascal Stang - Copyright (C) 2002 |
||
7 | // Date : 5/30/2002 |
||
8 | // Revised : 5/30/2002 |
||
9 | // Version : 0.5 |
||
10 | // Target MCU : Atmel AVR |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | // NOTE: This code is currently below version 1.0, and therefore is considered |
||
14 | // to be lacking in some functionality or documentation, or may not be fully |
||
15 | // tested. Nonetheless, you can expect most functions to work. |
||
16 | // |
||
17 | // This code is distributed under the GNU Public License |
||
18 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
19 | // |
||
20 | //***************************************************************************** |
||
21 | |||
22 | #ifndef WIN32 |
||
23 | // AVR specific includes |
||
24 | #include <avr/io.h> |
||
25 | #include <avr/pgmspace.h> |
||
26 | #endif |
||
27 | |||
28 | #include "glcd.h" |
||
29 | |||
30 | // include hardware support |
||
31 | #include "ks0108.h" |
||
32 | // include fonts |
||
33 | #include "font5x7.h" |
||
34 | #include "fontgr.h" |
||
35 | |||
36 | // graphic routines |
||
37 | |||
38 | // set dot |
||
39 | void glcdSetDot(u08 x, u08 y) |
||
40 | { |
||
41 | unsigned char temp; |
||
42 | |||
43 | glcdSetAddress(x, y/8); |
||
44 | temp = glcdDataRead(); // dummy read |
||
45 | temp = glcdDataRead(); // read back current value |
||
46 | glcdSetAddress(x, y/8); |
||
47 | glcdDataWrite(temp | (1 << (y % 8))); |
||
48 | |||
49 | glcdStartLine(0); |
||
50 | } |
||
51 | |||
52 | // clear dot |
||
53 | void glcdClearDot(u08 x, u08 y) |
||
54 | { |
||
55 | unsigned char temp; |
||
56 | |||
57 | glcdSetAddress(x, y/8); |
||
58 | temp = glcdDataRead(); // dummy read |
||
59 | temp = glcdDataRead(); // read back current value |
||
60 | glcdSetAddress(x, y/8); |
||
61 | glcdDataWrite(temp & ~(1 << (y % 8))); |
||
62 | |||
63 | glcdStartLine(0); |
||
64 | } |
||
65 | |||
66 | // draw line |
||
67 | void glcdLine(u08 x1, u08 y1, u08 x2, u08 y2) |
||
68 | { |
||
69 | }; |
||
70 | |||
71 | // draw rectangle |
||
72 | void glcdRectangle(u08 x, u08 y, u08 a, u08 b) |
||
73 | { |
||
74 | unsigned char j; |
||
75 | |||
76 | for (j = 0; j < a; j++) { |
||
77 | glcdSetDot(x, y + j); |
||
78 | glcdSetDot(x + b - 1, y + j); |
||
79 | } |
||
80 | for (j = 0; j < b; j++) { |
||
81 | glcdSetDot(x + j, y); |
||
82 | glcdSetDot(x + j, y + a - 1); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // draw circle |
||
87 | void glcdCircle(u08 xcenter, u08 ycenter, u08 radius) |
||
88 | { |
||
89 | int tswitch, y, x = 0; |
||
90 | unsigned char d; |
||
91 | |||
92 | d = ycenter - xcenter; |
||
93 | y = radius; |
||
94 | tswitch = 3 - 2 * radius; |
||
95 | while (x <= y) { |
||
96 | glcdSetDot(xcenter + x, ycenter + y); glcdSetDot(xcenter + x, ycenter - y); |
||
97 | glcdSetDot(xcenter - x, ycenter + y); glcdSetDot(xcenter - x, ycenter - y); |
||
98 | glcdSetDot(ycenter + y - d, ycenter + x); glcdSetDot(ycenter + y - d, ycenter - x); |
||
99 | glcdSetDot(ycenter - y - d, ycenter + x); glcdSetDot(ycenter - y - d, ycenter - x); |
||
100 | |||
101 | if (tswitch < 0) tswitch += (4 * x + 6); |
||
102 | else { |
||
103 | tswitch += (4 * (x - y) + 10); |
||
104 | y--; |
||
105 | } |
||
106 | x++; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | // text routines |
||
111 | |||
112 | // write a character at the current position |
||
113 | void glcdWriteChar(unsigned char c) |
||
114 | { |
||
115 | u08 i = 0; |
||
116 | |||
117 | for(i=0; i<5; i++) |
||
118 | { |
||
119 | glcdDataWrite(pgm_read_byte(&Font5x7[((c - 0x20) * 5) + i])); |
||
120 | } |
||
121 | |||
122 | // write a spacer line |
||
123 | glcdDataWrite(0x00); |
||
124 | // unless we're at the end of the display |
||
125 | //if(xx == 128) |
||
126 | // xx = 0; |
||
127 | //else |
||
128 | // glcdWriteData(0x00); |
||
129 | |||
130 | //cbi(GLCD_Control, GLCD_CS1); |
||
131 | //cbi(GLCD_Control, GLCD_CS2); |
||
132 | glcdStartLine(0); |
||
133 | } |
||
134 | |||
135 | void glcdWriteCharGr(u08 grCharIdx) |
||
136 | { |
||
137 | u08 idx; |
||
138 | u08 grLength; |
||
139 | u08 grStartIdx = 0; |
||
140 | |||
141 | // get starting index of graphic bitmap |
||
142 | for(idx=0; idx<grCharIdx; idx++) |
||
143 | { |
||
144 | // add this graphic's length to the startIdx |
||
145 | // to get the startIdx of the next one |
||
146 | grStartIdx += pgm_read_byte(FontGr+grStartIdx); |
||
147 | } |
||
148 | grLength = pgm_read_byte(FontGr+grStartIdx); |
||
149 | |||
150 | // write the lines of the desired graphic to the display |
||
151 | for(idx=0; idx<grLength; idx++) |
||
152 | { |
||
153 | // write the line |
||
154 | glcdDataWrite(pgm_read_byte(FontGr+(grStartIdx+1)+idx)); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | void glcdPutStr(unsigned char *data) |
||
159 | { |
||
160 | while (*data) { |
||
161 | glcdWriteChar(*data); |
||
162 | data++; |
||
163 | } |
||
164 | } |
Powered by WebSVN v2.8.3