Aguijón Software Libraries
1.0
Documentation for the included Libraries
Main Page
Files
File List
Globals
All
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
LCD.c
Go to the documentation of this file.
1
/********************************************************************
2
FileName: LCD.c
3
Dependencies: See INCLUDES section
4
Hardware: Aguijón rev3.0
5
Complier: Microchip XC16(for PIC24), C30(for PIC24)
6
Company: Vinagrón Digital
7
8
Software License Agreement:
9
10
blah blah blah
11
12
********************************************************************
13
File Description:
14
Includes LCD control functions.
15
16
17
Change History:
18
Rev Description
19
---- -----------------------------------------
20
1.0 Initial release
21
********************************************************************/
22
23
#include <p24FJ128GB106.h>
24
#include "i2c.h"
25
#include "
init.h
"
26
#include "
definitions.h
"
27
#include "
LCD.h
"
28
29
30
/*caracteres especiales que se guardan en la CGRAM del display
31
hay 8 direcciones de memoria disponibles para guardar, con
32
la funcion load_custom_character, los siguientes arreglos de
33
variables son caracteres modificados para desplegar el logo
34
de Vinagron Digital.
35
*/
36
37
const
unsigned
char
vina1
[] = {
//<! Custom LCD char #1
38
0x04,
39
0x0C,
40
0x1C,
41
0x14,
42
0x1C,
43
0x0C,
44
0x0E,
45
0x0F,
46
};
47
48
const
unsigned
char
vina2
[] = {
//<! Custom LCD char #2
49
0x00,
50
0x00,
51
0x00,
52
0x08,
53
0x0C,
54
0x0C,
55
0x14,
56
0x18,
57
};
58
59
const
unsigned
char
vina3
[] = {
//<! Custom LCD char #3
60
0x1F,
61
0x0F,
62
0x1E,
63
0x0F,
64
0x1C,
65
0x0E,
66
0x18,
67
0x18,
68
};
69
70
const
unsigned
char
di
[] = {
//<! Custom LCD char #4
71
0x19,
72
0x15,
73
0x15,
74
0x15,
75
0x19,
76
0x00,
77
0x00,
78
0x00,
79
};
80
81
const
unsigned
char
gi
[] = {
//<! Custom LCD char #5
82
0x0D,
83
0x11,
84
0x15,
85
0x15,
86
0x19,
87
0x00,
88
0x00,
89
0x00,
90
};
91
92
const
unsigned
char
t
[] = {
//<! Custom LCD char #6
93
0x1F,
94
0x04,
95
0x04,
96
0x04,
97
0x04,
98
0x00,
99
0x00,
100
0x00,
101
};
102
103
const
unsigned
char
al
[] = {
//<! Custom LCD char #7
104
0x09,
105
0x15,
106
0x1D,
107
0x15,
108
0x15,
109
0x00,
110
0x00,
111
0x00,
112
};
113
//fin de los caracteres modificados
114
115
127
static
char
*i2a(
unsigned
i,
char
*a,
unsigned
r)
128
{
129
if
(i/r > 0) a = i2a(i/r,a,r);
130
*a =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
[i%r];
131
return
a+1;
132
}
133
145
char
*
itoa1
(
int
i,
unsigned
char
*a,
int
r)
//convierte integer a ASCII
146
{
147
if
((r < 2) || (r > 36)) r = 10;
148
if
(i<0) {
149
*a =
'-'
;
150
*i2a(-(
unsigned
)i,a+1,r) = 0;
151
}
else
*i2a(i,a,r) = 0;
152
153
return
a;
154
}
155
167
void
ClearDisplay
(
void
)
168
{
169
I2C_Start
();
170
I2CsendByte
(0x78);
//ADDRESS
171
I2CsendByte
(0x00);
//comando
172
I2CsendByte
(0x01);
//LUGAR
173
I2C_Stop
();
174
}
175
187
void
setCursor
(
unsigned
char
position)
188
{
189
I2C_Start
();
190
I2CsendByte
(0x78);
//ADDRESS
191
I2CsendByte
(0x00);
//comando
192
I2CsendByte
(0x80 + position);
//LUGAR
193
I2C_Stop
();
194
}
195
207
void
goto_xy
(
int
x,
int
y)
208
{
209
switch
(x){
210
case
1:
setCursor
(0x00 + y);
break
;
211
case
2:
setCursor
(0x40 + y);
break
;
212
}
213
}
214
226
void
BlinkOn
(
void
)
227
{
228
I2C_Start
();
229
I2CsendByte
(0x78);
//ADDRESS
230
I2CsendByte
(0x00);
//comando
231
I2CsendByte
(0x0F);
232
I2C_Stop
();
233
}
234
246
void
BlinkOff
(
void
)
247
{
248
I2C_Start
();
249
I2CsendByte
(0x78);
//ADDRESS
250
I2CsendByte
(0x00);
//comando
251
I2CsendByte
(0x0C);
252
I2C_Stop
();
253
}
254
266
void
LCDwrite
(
char
text)
//send sttring of ASCII data to LCD
267
{
268
I2C_Start
();
269
I2CsendByte
(0x78);
//Slave, LCD address=0x78
270
I2CsendByte
(0x40);
//Datasend=0x40
271
I2CsendByte
(text);
//string
272
I2C_Stop
();
273
}
274
286
void
DisplayString
(
unsigned
char
x,
unsigned
char
y,
unsigned
char
*m,
unsigned
char
clear)
287
{
288
if
(clear){
289
ClearDisplay
();
290
delayms
(1);
291
}
292
delayms
(1);
293
294
switch
(x){
295
case
1:
setCursor
(0x00 + y);
break
;
296
case
2:
setCursor
(0x40 + y);
break
;
297
}
298
delayms
(1);
299
300
while
(*m){
301
LCDwrite
(*m);
302
*m++;
303
}
304
}
305
317
void
LCDIntro
(
void
)
318
{
319
unsigned
char
i;
//01234567890123456789
320
unsigned
char
let1[] = {
"Aguij\xE2n"
};
//el \xE2 le asigna la "ó"
321
unsigned
char
let2[] = {
" 3.0 "
};
322
unsigned
char
let3[] = {
"inagr\xE2n"
};
323
324
325
load_custom_character
(
vina1
, 0);
//|
326
load_custom_character
(
vina2
, 1);
//|----el vinagron
327
load_custom_character
(
vina3
, 2);
//|
328
load_custom_character
(
di
,3);
//|
329
load_custom_character
(
gi
,4);
//|----DIGITAL
330
load_custom_character
(
t
, 5);
//|
331
load_custom_character
(
al
,6);
//|
332
333
delayms
(1);
334
335
goto_xy
(1,0);
336
LCDwrite
(0);
337
goto_xy
(1,1);
338
LCDwrite
(1);
339
goto_xy
(2,0);
340
LCDwrite
(2);
341
342
DisplayString
(1,2,let3,
FALSE
);
343
344
345
for
(i=3 ; i<7 ; i++){
//escribir el logo de Vinagrón Digital
346
goto_xy
(2,(i+2));
347
LCDwrite
(i);
348
}
349
350
351
for
(i=20 ; i!=12 ; i--){
352
DisplayString
(1,i,let1,
FALSE
);
353
DisplayString
(2,i,let2,
FALSE
);
354
delayms
(100);
355
}
356
357
delayms
(2000);
358
ClearDisplay
();
359
}
360
372
void
LCD_SendCommand
(
unsigned
char
command)
373
{
374
I2C_Start
();
375
I2CsendByte
(0x78);
//ADDRESS
376
I2CsendByte
(0x00);
//
377
I2CsendByte
(command);
378
I2C_Stop
();
379
}
380
392
void
load_custom_character
(
unsigned
char
*rows,
unsigned
char
char_num)
//cargar un caracter custom en CGRAM
393
{
394
int
i;
395
396
if
(char_num>=8)
return
;
//we only have 8 spaces at CGRAM
397
398
delayms
(10);
399
400
// Set up the display to write into CGRAM - configure LCD to use func table 0
401
I2C_Start
();
402
I2CsendByte
(0x78);
//address
403
I2CsendByte
(0x00);
//command
404
I2CsendByte
(0x38);
//set to func table 0
405
delayms
(10);
406
// Set CGRAM position to write
407
I2CsendByte
( 0x40 + (char_num*8));
408
I2C_Stop
();
409
410
411
I2C_Start
();
412
I2CsendByte
(0x78);
413
I2CsendByte
(0x40);
//RS=1 (write data to ram)
414
415
//send the 8 rows of the character
416
for
(i=0;i<8;i++)
417
{
418
I2CsendByte
(*rows);
// write the current pointed row to CGRAM
419
rows++;
//increment the pointer
420
}
421
422
I2C_Stop
();
423
delayms
(10);
424
425
// Leave the LCD as it was - function table 1 DDRAM and set the cursor
426
LCD_SendCommand
(0x39);
427
428
delayms
(10);
429
}
Aguijon
Documented Software
Aguijon 3.0
LCD.c
Generated on Sat Nov 17 2012 19:00:33 for Aguijón Software Libraries by
1.8.2