Cuando me compré la placa MMB for PIC32 de Mikroelektronica, de la cual hablé aquí, algo que eché en falta es una interfaz visual que fuera sencilla de utilizar, tipo un LCD de 16x2, para, por ejemplo, mostrar una temperatura, o que nos indique que todo está funcionando bien, al igual que encontramos en la placa EXPLORER16 de Microchip. Esta placa, como la comenté, monta un TFT de 320x240 puntos, lo cual es un periférico muy potente, y por tanto, algo tedioso de manipular, hasta que trabajé con la librería LCDTerminal.h.
La librería en cuestión, nos facilita mucho la labor de mostrar cadenas de texto en la pantalla TFT como si de un terminal se tratara. Esta librería viene en el CD que traen las placas MMB, aunque también la podéis encontrar en la página de Mikroe, y vale para muchos tipos de pantallas TFT con diferentes controladores. Para crear nuestro proyecto, a parte de añadir los archivos LCDTerminal.h, y LCDTerminal.c, hay que añadir las librerias referentes al control de pantallas que encontramos en las Microchip Aplication Libraries/ Graphics, como son graphics.h, Primitive.h y DisplayDriver.h, a parte de sus correspondientes archivos .c.
Como en el caso del STACK TCPIP, disponemos también de un archivo de configuración llamado GraphicsConfig.h, en el cual le decimos que elementos queremos tener disponibles y cuales no, de forma que ahorremos espacio en el micro. Para el caso de utilizar solo la pantalla como terminal, la configuración es la siguiente, que como veréis, es la más sencilla posible.
1: #ifndef _GRAPHICSCONFIG_H
2: #define _GRAPHICSCONFIG_H
3:
4: //////////////////// COMPILE OPTIONS AND DEFAULTS ////////////////////
5:
6: /*********************************************************************
7: * Overview: Blocking and Non-Blocking configuration selection. To
8: * enable non-blocking configuration USE_NONBLOCKING_CONFIG
9: * must be defined. If this is not defined, blocking
10: * configuration is assumed.
11: *
12: ********************************************************************/
13: //#define USE_NONBLOCKING_CONFIG // Comment this line to use blocking configuration
14:
15: /*********************************************************************
16: * Overview: Keyboard control on some objects can be used by enabling
17: * the GOL Focus (USE_FOCUS)support.
18: *
19: *********************************************************************/
20: //#define USE_FOCUS
21:
22: /*********************************************************************
23: * Overview: Input devices used defines the messages that Objects will
24: * process. The following definitions indicate the usage of
25: * the different input device:
26: * - USE_TOUCHSCREEN - enables the touch screen support.
27: * - USE_KEYBOARD - enables the key board support.
28: *
29: *********************************************************************/
30: //#define USE_TOUCHSCREEN // Enable touch screen support.
31: //#define USE_KEYBOARD // Enable key board support.
32:
33: /*********************************************************************
34: * Overview: To save program memory, unused Widgets or Objects can be
35: * removed at compile time.
36: *
37: *********************************************************************/
38: //#define USE_GOL // Enable Graphics Object Layer.
39: //#define USE_BUTTON // Enable Button Object.
40: // USE_WINDOW // Enable Window Object.
41: //#define USE_CHECKBOX // Enable Checkbox Object.
42: //#define USE_RADIOBUTTON // Enable Radio Button Object.
43: //#define USE_EDITBOX // Enable Edit Box Object.
44: //#define USE_LISTBOX // Enable List Box Object.
45: //#define USE_SLIDER // Enable Slider or Scroll Bar Object.
46: //#define USE_PROGRESSBAR // Enable Progress Bar Object.
47: //#define USE_STATICTEXT // Enable Static Text Object.
48: //#define USE_PICTURE // Enable Picture Object.
49: //#define USE_GROUPBOX // Enable Group Box Object.
50: //#define USE_ROUNDDIAL // Enable Dial Object.
51: //#define USE_METER // Enable Meter Object.
52: //#define USE_CUSTOM // Enable Custom Control Object (an example to create customized Object).
53:
54: /*********************************************************************
55: * Overview: To enable support for unicode fonts, USE_MULTIBYTECHAR
56: * must be defined. This changes XCHAR definition. See XCHAR
57: * for details.
58: *
59: *********************************************************************/
60: //#define USE_MULTIBYTECHAR
61:
62: /*********************************************************************
63: * Overview: Font data can be placed in two locations. One is in
64: * FLASH memory and the other is from external memory.
65: * Definining one or both enables the support for fonts located
66: * in internal flash and external memory.
67: * - USE_FONT_FLASH - Font in internal flash memory support.
68: * - USE_FONT_EXTERNAL - Font in external memory support.
69: *
70: *********************************************************************/
71: #define USE_FONT_FLASH // Support for fonts located in internal flash
72: //#define USE_FONT_EXTERNAL // Support for fonts located in external memory
73:
74: /*********************************************************************
75: * Overview: Similar to Font data bitmaps can also be placed in
76: * two locations. One is in FLASH memory and the other is
77: * from external memory.
78: * Definining one or both enables the support for bitmaps located
79: * in internal flash and external memory.
80: * - USE_BITMAP_FLASH - Font in internal flash memory support.
81: * - USE_BITMAP_EXTERNAL - Font in external memory support.
82: *
83: *********************************************************************/
84: #define USE_BITMAP_FLASH // Support for bitmaps located in internal flash
85: //#define USE_BITMAP_EXTERNAL // Support for bitmaps located in external memory
86:
87: /*********************************************************************
88: * Overview:
89: * Graphics on the MMB Board
90: *
91: ********************************************************************/
92: #define LCD_WRAP
93: #define LCD_SCROLL
94: //#defin LCD_OVERLAY
95: #define LCD_BACK BLACK
96: #define LCD_FORE WHITE
97:
98: #endif // _GRAPHICSCONFIG_H
Las funciones básicas que encontramos en la libreria LCDTerminal son las siguientes :
- LCDCenterString( n, cadena): Muestra un texto centrado horizontamente en la pantalla. El valor n, es el numero de lineas por encima o por debajo de la linea central horizontal donde aparecerá nuestro texto.
- LCDPutString( cadena): Muestra un texto con alineación a la izquierda.
- SetColor( color): Establece el color del texto siguiente.
- LCDSetXY( x, y): Mueve el cursor hasta la posición X, Y seleccionada.
- LCDClear(): Borra el contenido de la pantalla y lleva el cursr a la posición X = 0, Y = 0.
- LCDHome(): Lleva el cursor a la posición X = 0, Y = 0.
- LCDLineHome(): Mueve el cursor al valor X = 0, el valor Y lo deja como está.
1:
2: #include "MMB.h"
3: #include "LCDTerminal.h"
4: #include "Graphics\Graphics.h"
5: //#include "MDD File System\FSIO.h"
6: //#include "SerialFLash.h"
7:
8: // Configuration bits
9: #pragma config POSCMOD = XT, FNOSC = PRIPLL, FSOSCEN = ON
10: #pragma config FPLLIDIV = DIV_2, FPLLMUL = MUL_20, FPLLODIV = DIV_1, FPBDIV = DIV_1
11: #pragma config OSCIOFNC = ON, CP = OFF, BWP = OFF, PWP = OFF
12:
13: // fonts
14: extern const FONT_FLASH TerminalFont;
15:
16: int main( void)
17: {
18: char opc = 0, sel = 0;
19: int i = 0;
20: char dir = 0;
21:
22: MMBInit(); // Inicialización de la placa MMB
23: LCDInit(); // Inicialización de la libreria gráfica.
24:
25: //---- TEXTO DE LA PANTALLA INICIAL.
26:
27: SetColor( LIGHTBLUE);
28:
29: LCDCenterString( -5, "EJEMPLO MENU LCD");
30: LCDCenterString( -3, "P.Trujillo");
31: LCDCenterString( -2, "MIPS AND CHIPS");
32: SetColor( BRIGHTYELLOW);
33: LCDCenterString( 0, "www.mipsandchips.blogspot.com.es");
34: SetColor( WHITE);
35: LCDCenterString( 2, "(Mueva el joystick ");
36: LCDCenterString( 3, "para continuar) ");
37: MMBFadeIn( 250);
38: MMBGetKey(); //esperamos a que se pulse un botón.
39: LCDClear();
40:
41: LCDSetXY(3,2);
42: LCDPutString("Selecciona una opcion:\n");
43: LCDSetXY(0,5);
44: LCDPutString(" > Encender LEDs.\n Detener LEDs.");
45: while( 1)
46: {
47: LCDSetXY(0,5);
48:
49: switch(MMBGetKey()){
50:
51: case JOY_UP:
52: LCDPutString(" > Encender LEDs.\n Detener LEDs.");
53: opc = 1;
54: break;
55: case JOY_DOWN:
56: LCDPutString(" Encender LEDs.\n > Detener LEDs.");
57: opc = 2;
58: break;
59: case JOY_SELECT:
60: sel = opc;
61: break;
62:
63: }
64: if (sel == 1)
65: LATA = 0x0;
66: else
67: LATA = 0xf;
68:
69: }
70: }
Y a continuación un video demostrativo.
Haré más proyectos con esta librería ya que resulta muy sencillo hacer un proyecto que, a simple vista, parecen muy complejos.
No hay comentarios:
Publicar un comentario