-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnokia5110.c
309 lines (256 loc) · 7.45 KB
/
nokia5110.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
* nokia5110.c
*
* Functions for Nokia 5110 LCD
*/
#include <stdbool.h>
#include "nokia5110.h"
#include "font5x7.h"
#include "font3x5.h"
#include "delay.h"
// This switches between 3x5 font and 5x7 font
extern bool fontFlag;
// for lcdClearSome function and plotScreen function
enum pixMode { off, on, xor};
enum pixMode pMode = off;
//unsigned char pixMode = 0;
//static char lcdBuf[LCDROWMAX][LCDCOLMAX]; // need more ram!!!!
void LcdGotoXY(unsigned char x, unsigned char y)
{
LcdWrite(CMD ,(0x40 | (y & 0x07))); // Y row == 0100 0yyy
LcdWrite(CMD ,(0x80 | (x & 0x7F))); // X column == 1xxx xxxx
}
void LcdBmp(const unsigned char my_array[])
{
unsigned short index = 0;
for (index = 0; index < 504; index++) {
LcdWrite(DATA,my_array[index]);
}
}
void LcdCharacter(unsigned char character) {
if (fontFlag) {
unsigned int temp = 0;
temp = font3x5[character - 0x20];
LcdWrite(DATA, (temp & 0x1F));
LcdWrite(DATA, (temp >> 5) & 0x1F);
LcdWrite(DATA, (temp >> 10));
} else {
char index = 0;
for (index = 0; index < 5; index++) {
LcdWrite(DATA, font5x7[character - 0x20][index]);
}
}
LcdWrite(DATA, 0x00);
}
void LcdString(unsigned char *characters)
{
while (*characters){
LcdCharacter(*characters++);
}
}
void LcdClear(void) {
int i,j;
LcdWrite(CMD, 0x80);
LcdWrite(CMD, 0x40);
for (i = 0; i < 6; i++) // number of rows
for (j = 0; j < LCD_X; j++) // number of columns
LcdWrite(DATA, 0x00);
}
/*
* Name : clearSome
* Description : Clear part of the screen
* Argument(s) : xs, ys are x any y start points for top left corner of rectangle,
* xe, ye are end points for lower left corner of rectangle
* Return value : none
*/
void LcdClearSome(unsigned char xs, unsigned char ys, unsigned char xe, unsigned char ye) {
pMode = off;
drawFilledRectangle(xs,ys,xe,ye);
pMode = on;
}
void LcdInit(void)
{
P3OUT |= PIN_BLIGHT;
P3OUT |= PIN_VCC; // power to LCD
P3OUT |= PIN_RESET; // set RESET high
P3OUT &= ~PIN_RESET; // set RESET low
delay(35);
P3OUT |= PIN_RESET; // set RESET high
P2OUT |= PIN_SCE; // SCE pin high
LcdWrite(CMD , 0x21); // LCD Extended instruction set
LcdWrite(CMD , 0x9F); // Set LCD Vop (Contrast). //0xE0 - BF may have to play with
LcdWrite(CMD , 0x07); // Set Temp coefficient. //0x04 =t0 //0x05=t1 // 0x06=t2 // 0x07=t3
LcdWrite(CMD , 0x13); // LCD bias mode 1:100 0x10 //1:48 0x13
LcdWrite(CMD , 0x20); // LCD vertical addressing
LcdWrite(CMD , 0x08); // lcd blank
LcdWrite(CMD , 0x0C); // LCD 0x0C for black on white //0x0d for inverse
LcdClear();
}
void LcdWrite(char cmd, char data) {
P2OUT &= ~PIN_SCE; // SCE pin low
(cmd == CMD) ? (P3OUT &= ~PIN_DC) : (P3OUT |= PIN_DC); // check to see if we are writing a CMD or DATA
UCB0TXBUF = data; // load shift register with data to send
while (!(IFG2 & UCB0TXIFG));
delay(1);
P2OUT |= PIN_SCE; // SCE pin high
}
/*
* Name : printV
* Description : prints a word vertically
* Argument(s) : x , y , length of word (can't be longer than 6 letters)
* Return value : None
*/
/*
void printV(unsigned char x, unsigned char y, unsigned char length,
char *characters) {
for (length = 0; length <= 5; length++) {
LcdGotoXY(x, y);
y++;
LcdWrite(DATA, *characters++);
}
}
*/
/*
* Name : setPixel
* Description : Set a single pixel either on or off
* Argument(s) : x,y - position, x = 0-83, y = 0-6
*/
void setPixel(unsigned char x, unsigned char y) {
unsigned char row = 0;
unsigned char value = 0;
row = y / 8;
if (pMode == off) {
value &= ~(1 << (y % 8));
} else if (pMode == xor) { // need a buffer for this
value ^= (1 << (y % 8));
} else {
value |= (1 << (y % 8));
}
LcdGotoXY(x, row);
LcdWrite(DATA, value);
}
/*
* Name : drawLine
* Description : Draws a line between two points on the display.
* Argument(s) : x1, y1 - Absolute pixel coordinates for line origin.
* x2, y2 - Absolute pixel coordinates for line end.
*
* Return value : none
*/
void drawLine(unsigned char x1, unsigned char y1, unsigned char x2,
unsigned char y2) {
int dx, dy, stepx, stepy, fraction;
/* Calculate differential form */
/* dy y2 - y1 */
/* -- = ------- */
/* dx x2 - x1 */
/* Take differences */
dy = y2 - y1;
dx = x2 - x1;
/* dy is negative */
if (dy < 0) {
dy = -dy;
stepy = -1;
} else {
stepy = 1;
}
/* dx is negative */
if (dx < 0) {
dx = -dx;
stepx = -1;
} else {
stepx = 1;
}
dx <<= 1;
dy <<= 1;
/* Draw initial position */
setPixel(x1, y1);
/* Draw next positions until end */
if (dx > dy) {
/* Take fraction */
fraction = dy - (dx >> 1);
while (x1 != x2) {
if (fraction >= 0) {
y1 += stepy;
fraction -= dx;
}
x1 += stepx;
fraction += dy;
/* Draw calculated point */
setPixel(x1, y1);
}
} else {
/* Take fraction */
fraction = dx - (dy >> 1);
while (y1 != y2) {
if (fraction >= 0) {
x1 += stepx;
fraction -= dy;
}
y1 += stepy;
fraction += dx;
/* Draw calculated point */
setPixel(x1, y1);
}
}
}
/*
* Name : drawFilledRectangle
* Description : Draw a filled rectangle given the top left and bottom right points
* just simply draws horizontal lines where the rectangle would be
* Argument(s) : x1, y1 - Absolute pixel coordinates for top left corner
* x2, y2 - Absolute pixel coordinates for bottom right corner
*
* Return value : none
*/
void drawFilledRectangle(unsigned char x1, unsigned char y1, unsigned char x2,
unsigned char y2) {
unsigned char i;
for (i = y1; i <= y2; i++) {
drawLine(x1, i, x2, i);
}
}
/*
// mapping function taken from arduino
unsigned int map(unsigned int x, unsigned int in_min, unsigned int in_max, unsigned int out_min, unsigned int out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
*/
// mapping function taken from arduino
float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
//
//// for plotting the screen !!!!!Not enough RAM!!!!!
//void loadBuf(unsigned char x, unsigned char y) {
//
// unsigned char value, row = 0;
// row = y / 8;
// value = lcdBuf[row][x];
// value |= (1 << (y % 8));
// lcdBuf[row][x] = value;
//}
//
//// for writing the screen buffer to the screen
//void writeBuf(char *buf){
//
// unsigned int i, j;
// for (i = 0; i <= LCDROWMAX; i++){
// for (j = 0; j <= LCDCOLMAX; j++){
// LcdWrite(DATA, buf[i][j]);
// }
// }
//
//}
//for real time plot x = time, y = degrees
void plotScreen(unsigned int x, unsigned int y) {
unsigned int secCount, degrees = 0;
secCount = map(x,0,500,0,LCD_X); // hard coded time range 0-504, map to nokia x
degrees = map(y,0,300,0,LCD_Y - 8); // temp range 0 - 280'C , map to nokia y - 1 row
degrees = (LCD_Y - 8) - degrees; // flip the screen
pMode = on; // doesnt work without a buffer
setPixel(secCount,degrees);
pMode = off;
// loadBuf(secCount,degrees);
// writeBuf(lcdBuf);
}