-
Notifications
You must be signed in to change notification settings - Fork 0
/
PR_lcd.c
195 lines (142 loc) · 7.86 KB
/
PR_lcd.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
/***********************************************************************************************************************************
*** INCLUDES
**********************************************************************************************************************************/
#include "PR_lcd.h"
#include "DR_lcd.h"
#include "PR_Timers.h"
/***********************************************************************************************************************************
*** DEFINES PRIVADOS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** MACROS PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** TIPOS DE DATOS PRIVADOS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** TABLAS PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** VARIABLES GLOBALES PUBLICAS
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** VARIABLES GLOBALES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** PROTOTIPO DE FUNCIONES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** FUNCIONES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** FUNCIONES GLOBALES AL MODULO
**********************************************************************************************************************************/
/******************************************************************************************************************
* @fn void lcd_tipo_cursor( int8_t cursor, int8_t despl, int8_t parpadeo )
* @brief Selecciona el tipo de cursor
* @param: cursor: ON=1 - OFF=0
* @param: parpadeo: ON=1 - OFF=0
* @return: void
*****************************************************************************************************************/
void lcd_tipo_cursor( int8_t cursor, int8_t parpadeo )
{
if( cursor == OFF && parpadeo == OFF )
PushLCD( 0x0C , LCD_CONTROL ); // 0000 1100->D=1(Display ON)-C=0(Cursor OFF)-B=0(Sin parpadeo)
if( cursor == ON && parpadeo == OFF )
PushLCD( 0x0E , LCD_CONTROL ); // 0000 1110->D=1(Display ON)-C=1(Cursor ON )-B=0(Sin parpadeo)
if( cursor == OFF && parpadeo == ON )
PushLCD( 0x0D , LCD_CONTROL ); // 0000 1101->D=1(Display ON)-C=0(Cursor OFF)-B=1(Con parpadeo)
if( cursor == ON && parpadeo == ON )
PushLCD( 0x0F , LCD_CONTROL ); // 0000 1111->D=1(Display ON)-C=1(Cursor ON )-B=1(Con parpadeo)
}
/******************************************************************************************************************
* @fn uint8_t PushLCD( uint8_t dato , uint8_t control , uint8_t medio_byte )
* @brief Funcion para poner un dato en el buffer del LCD
* @param dato: Dato a poner en el buffer del LCD
* @param control: Indica si es un dato de status o de control
* @param medio_byte: Indica si se envia un HALF_BYTE O FULL_BYTE
* @return Devuelve -1 en caso de error, o 0 en caso contrario
*****************************************************************************************************************/
int16_t PushLCD( uint8_t dato , uint8_t control ) // manda el dato
{
int32_t posicion; // Lugar del buffer del LCD donde se pondra el dato
if( cantidad_cola_lcd >= ( TAMANO_BUFFER_LCD - 2 ) )
return -1;
posicion = inicio_buffer_lcd + cantidad_cola_lcd;
posicion %= TAMANO_BUFFER_LCD;
Buffer_LCD[ posicion ] = ( dato >> 4 ) & 0x0F; //primero el nibble mas significativo
if( control == LCD_CONTROL )
Buffer_LCD[ posicion] |= 0x80; // El 0x80 es para acceder a la memoria DD RAM
cantidad_cola_lcd++;
posicion = inicio_buffer_lcd + cantidad_cola_lcd;
posicion %= TAMANO_BUFFER_LCD;
Buffer_LCD[ posicion ] = dato & 0x0F;
if( control == LCD_CONTROL )
Buffer_LCD[ posicion ] |= 0x80; // Agrega un 1 en el bit LCD_D7 para acceder a DD RAM
cantidad_cola_lcd ++;
return 0;
}
void lcd_mostrar_buffer_editable(){
lcdprintf(MOSTRAR_BUFFER_EDITABLE);
}
/*********************************************************************************************
* @fn void lcdprintf( int8_t *msg , int8_t linea , int8_t pos )
* @brief Funcion para escribir un mensaje en el LCD
* @param msg: Strings del mensaje a escribir (primera y segunda linea). Poner NULL para mostrar buffer(zona editable).
********************************************************************************************/
void lcdprintf( char *linea1 , char *linea2 )
{
#define SIMBOLO_ENTER 0x7F
uint8_t i, lcd_borrado=0;
if ( linea1==NULL && linea2==NULL ) { //se desea mostrar el buffer
BorrarLCD();
lcd_tipo_cursor(ON,ON);
TimerStop(14);
} else {
if (linea1!=NULL && linea2!=NULL) {
BorrarLCD();
lcd_borrado=1;
}
//se desea mostrar un mensaje (se lo mantiene 3 segundos)
lcd_tipo_cursor(OFF,OFF);
TimerStart(14,3,SEG,lcd_mostrar_buffer_editable); //luego de mostrar msj por 3 seg, volver a mostrar buffer.
if ( linea1!=NULL ) {
PushLCD( 0x80 , LCD_CONTROL ); // 1er Renglon
for (i=0;linea1[i] != '\0';i++) {
PushLCD (linea1 [i] , LCD_DATA);
}
if (lcd_borrado==0){
for (;i<16;i++) { //borrar resto de la linea
PushLCD (' ' , LCD_DATA);
}
}
}
if ( linea2!=NULL ) {
PushLCD( 0xc0 , LCD_CONTROL ); // 2do Renglon
for (i=0;linea2[i] != '\0';i++) {
PushLCD (linea2 [i] , LCD_DATA);
}
if (lcd_borrado==0){
for (;i<16;i++) { //borrar resto de la linea
PushLCD (' ' , LCD_DATA);
}
}
}
}
}
/*********************************************************************************************
* @fn void GuardarMensajeLCD( char *mensaje, char *lugar )
* @brief Funcion que rellena el mensaje a enviar con espacios vacios asi se 'borran' los anteriores lugares del LCD
* @param mensaje: Puntero al mensaje a escribir
* @param lugar: Puntero al lugar donde se quiere guardar el mensaje pasado
* @return void
********************************************************************************************/
void GuardarMensajeLCD( char *mensaje, char *lugar )
{
uint8_t i;
for( i = 0; mensaje[i] != 0; i++ )
lugar[i] = mensaje[i];
for( ; i < 16; i++ )
lugar[i] = ' ';
lugar[17] = 0;
}