Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* ########################################################################### 00002 ** Archivo : main.c 00003 ** Proyecto : FRDM-KL46Z_LCD_Test 00004 ** Procesador : MKL46Z256VLL4 00005 ** Herramienta : Mbed 00006 ** Version : Driver 01.01 00007 ** Compilador : GNU C Compiler 00008 ** Fecha/Hora : 14-07-2015, 11:48, # CodeGen: 0 00009 ** Descripción : 00010 ** Este proyecto prueba todas las configuraciones para operar un 00011 ** display LCD alfanumérico en modo de 4 bits 00012 ** - Utilizando los GPIO's 00013 ** - Utilizando el SPI y el C.I. SN74HC595 o CD4094 00014 ** - Utilizando el I2C y el Modulo PCF8574 y PCF8574A 00015 ** soporta las siguintes pantallas LCD alfanuméricas: 00016 ** 1x8, 1x16, 2x16, 2x20, 4x16, 4x20 00017 ** Componentes : GPIO, Timer, SPI, I2C, TextLCD. 00018 ** Configuraciones : TextLCD, TextLCD_SPI, TextLCD_I2C 00019 ** Autores : 00020 ** ATEAM Development Group: 00021 ** - Antulio Morgado Valle 00022 ** 00023 ** Versión : Beta 00024 ** Revisión : A 00025 ** Release : 0 00026 ** Date : 20/10/2019 00027 ** Bugs & Fixes : 00028 ** Added support for Led_RGB 00029 ** 22/09/2018 00030 ** Added LCD Menu, Beta version (with bugs) 00031 ** 00032 ** El permiso se otorga por este medio, sin cargo, a cualquier persona que 00033 ** obtenga una copia de este software y los archivos de documentación asociados 00034 ** (el "Software"), para operar en el Software sin restricciones, incluidos, 00035 ** entre otros, los derechos de uso, copia, modificación, fusión, publicación, 00036 ** distribución, sublicencia y/o venta de copias de el Software, y para permitir 00037 ** que las personas a quienes se suministra el Software lo hagan, sujeto a las 00038 ** siguientes condiciones: 00039 ** 00040 ** El aviso de copyright anterior y este aviso de permiso se incluirán en todas 00041 ** las copias o partes sustanciales del Software. 00042 ** 00043 ** EL SOFTWARE SE PROPORCIONA "TAL CUAL", SIN GARANTÍA DE NINGÚN TIPO, EXPRESO 00044 ** O IMPLÍCITO, INCLUYENDO PERO NO LIMITADO A LAS GARANTÍAS DE COMERCIABILIDAD, 00045 ** APTITUD PARA UN PROPÓSITO PARTICULAR Y NO INCUMPLIMIENTO. EN NINGÚN CASO, 00046 ** LOS AUTORES O TITULARES DE DERECHOS DE AUTOR SERÁN RESPONSABLES POR CUALQUIER 00047 ** RECLAMACIÓN, DAÑOS U OTRAS RESPONSABILIDADES, YA QUE SEA RESPONSABLE DE UN 00048 ** CONTRATO, CORTE U OTRA MANERA, DERIVADOS DE, FUERA O EN CONEXIÓN CON 00049 ** EL SOFTWARE O EL USO O OTRAS REPARACIONES EN EL SOFTWARE. 00050 ** ###########################################################################*/ 00051 /* 00052 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 00053 : Includes 00054 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 00055 */ 00056 #include "mbed.h" 00057 #include "TextLCD.h" 00058 #include "I2C.h" 00059 #include "SPI.h" 00060 #include "Serial.h" 00061 #include "stdio.h" 00062 /* 00063 :............................................................................... 00064 : Definiciones 00065 :............................................................................... 00066 */ 00067 #define ON 0 // Estado para boton presionado 00068 #define OFF 1 // Estado para boton sin presionar 00069 #define HOLD 2 // Estado para boton mantenido 00070 #define RELEASE 3 // Estado para boton liberado 00071 #define REPEAT 4 // Estado para boton repetido 00072 #define FALSE 0 // Estado FALSO 00073 #define TRUE 1 // Estado VERDADERO 00074 #define HIGH 1 // Estado ALTO 00075 #define LOW 0 // Estado BAJO 00076 #define BUZZ_ON 0 // Estado para Buzzer Encendido 00077 #define BUZZ_OFF 1 // Estado para Buzzer Apagado 00078 #define LCD_INTERFACE 1 // Tipo Interfaz del LCD: 0=Normal, 1=I2C, 2=SPI 00079 #define I2C_ADDRESS 0x7E // Dirección I2C para Interfaz al LCD: 0x7E, 0x4E 00080 #define TICKER_RATE 1000 // Periodo de Interrupción (us) 00081 #define BAUD_RATE 115200 // Velocidad de Transmisión (Bauds)) 00082 // 300, 600, 1200, 2400, 4800, 9600, 00083 // 14400, 19600, 28800, 38400, 57600 00084 // 115200, 230400 00085 /* 00086 +------------------------------------------------------------------------------- 00087 | Configuración de Puertos 00088 +------------------------------------------------------------------------------- 00089 */ 00090 Ticker TimerInt; // Inicializa la Interrupción por Timer 00091 DigitalOut led_monitor(LED2); // Inicializa el LED Monitor 00092 PwmOut buzzer (PTE31); // Inicializa el PWM para el Buzzer 00093 PwmOut backlight(PTA13); // Inicializa el LED Backlight del LCD (Externo) 00094 AnalogIn light (PTB0); // Inicializa Canal Analógico para BackLight 00095 /* 00096 ** ------------------------------------------------------------------- 00097 ** Inicialización de los Pines de Funciones Especiales. 00098 ** ------------------------------------------------------------------- 00099 */ 00100 00101 /************************************************* 00102 * Host PC Communication channels 00103 **************************************************/ 00104 Serial terminal(USBTX, USBRX); // Inicializa la Comunicación Serial a la PC 00105 //Serial terminal(PTA2,PTA1); // Terminal Serial 00106 //Serial terminal(PTE0, PTE1); // Tx, Rx Using MAX3232 or BlueTooth 00107 00108 /************************************************* 00109 * Bluetooth Communication support 00110 ************************************************** 00111 * Initialize the library with the numbers of the interface pins 00112 * Board Freedom FRDM-KL46Z 00113 * IDE Mbed On Line Compiler 00114 ***************************************************/ 00115 Serial bluetooth(PTE0, PTE1); // Tx, Rx 00116 00117 /************************************************** 00118 * Instantiation for creating a TextLCD interface 00119 * for using control and functions over selected port 00120 ***************************************************/ 00121 // LCD instantiation 00122 #if LCD_INTERFACE == 0 00123 /************************************************* 00124 * GPIO Pin Port 00125 ************************************************** 00126 * Initialize the library with the numbers of the interface pins 00127 * Board Freedom FRDM-KL46Z 00128 * IDE Mbed On Line Compiler 00129 * LCD GPIO 00130 * Pin Board 00131 * VSS 5V 00132 * VDD GND 00133 * VO POT 1K 00134 * RS PTC6 00135 * RW GND 00136 * E PTC7 00137 * D4 PTC8 00138 * D5 PTC9 00139 * D6 PTC10 00140 * D7 PTC11 00141 * BL+ PTA13 00142 * BL- GND 00143 ***************************************************/ 00144 TextLCD lcd(PTC6,PTC7, PTC8, PTC9, PTC10, PTC11, TextLCD::LCD16x2); // 4bit bus: rs, e, d4-d7 (lsb -> msb) 00145 DigitalOut LE (PTC4); // Pin para Latch Enable (SN74HC573) 00146 #endif 00147 #if LCD_INTERFACE == 1 00148 /************************************************* 00149 * I2C Communication 00150 ************************************************** 00151 * Initialize the library with the numbers of the interface pins 00152 * Board Freedom FRDM-KL46Z 00153 * IDE Mbed On Line Compiler 00154 * LCD I2C PCF8574A 00155 * Pin Board LCD 00156 * I2C_SCL SCL (white) + resistance pull-up 4.7k 00157 * I2C_SDA SDA (blue) + resistance pull-up 4.7k 00158 * 5V 5V (red) 00159 * GND GND (black) 00160 ***************************************************/ 00161 I2C i2c_lcd(PTC2,PTC1); // SDA, SCL 00162 TextLCD_I2C lcd(&i2c_lcd, I2C_ADDRESS, TextLCD::LCD20x4); // Address 0x4E or 0x7E I2C bus, PCF8574A Arduino Shield, LCD Type 00163 #endif 00164 #if LCD_INTERFACE == 2 00165 /************************************************* 00166 * SPI Communication 00167 ************************************************** 00168 * Initialize the library with the numbers of the interface pins 00169 * Board Freedom FRDM-KL46Z 00170 * IDE Mbed On Line Compiler 00171 * LCD SPI SN74HC595 00172 * Pin Board LCD 00173 * SPI_MOSI SER (white) 00174 * SPI_MISO none (blue) 00175 * SPI_CLK SRCLK 00176 * SPI_PCS RCLK 00177 * 5V 5V (red) 00178 * GND GND (black) 00179 ***************************************************/ 00180 SPI spi_lcd(PTD6,PTD7,PTD5,PTD4); // MOSI, MISO, SCLK, SSEL 00181 DigitalOut SSel(PTD4); // Inicializa el Pin de Seleccion de Esclavo SPI 00182 TextLCD_SPI lcd(&spi_lcd, PTD4, TextLCD::LCD20x4, TextLCD::HD44780); // SPI bus, SN74595 expander, CS pin, LCD Type 00183 #endif 00184 00185 /* 00186 ** =================================================================== 00187 ** Variables Globales del Programa 00188 ** =================================================================== 00189 */ 00190 uint16_t Rate=TICKER_RATE/2; // Velocidad de barrido (500us = 0.5ms) 00191 uint16_t counter=250; // Cuenta inicial de 250us 00192 uint16_t heartbeat; // Contador de Overrunig 00193 /* 00194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00195 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción 00196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00197 */ 00198 void Setup(void); // Rutina de Inicialización para el Hardware 00199 void Caratula(void); // Carátula de Bienvenida 00200 void Ticker_OnInterrupt(void); // Rutina de Atención para el Ticker 00201 void Buzzer_Beep(void); // Pitidos del Buzzer 00202 void I2C_Scanner(void); // Busca dispositivos conectados al bus I2C 00203 void Test_LCD(void); // Prueba la operación del LCD 00204 void Blinking_Led(void); // Rutina de Parpadeo del Led monitor 00205 /* END definitions */ 00206 /* 00207 #=============================================================================== 00208 | 00209 | P R O G R A M A P R I N C I P A L 00210 | 00211 #=============================================================================== 00212 */ 00213 int main() 00214 { 00215 //=================== Secuencia Principal ===================================== 00216 Setup(); // Inicializa el Hardware 00217 Caratula(); // Carátula de Bienvenida 00218 lcd.cls(); // Limpia la Pantalla LCD 00219 //=================== Lazo Principal =========================================== 00220 while (true) // El Lazo del Programa principal está aquí !!! 00221 { 00222 lcd.cls(); 00223 lcd.locate(0,0); 00224 lcd.printf("Bienvenidos Sean"); // El LCD saluda al Mundo 00225 lcd.printf(" a la \n"); // y a la 00226 lcd.setInvert(ON); 00227 lcd.printf("Gloriosa ESIME !\n"); // Gloriosa ESIME ! 00228 lcd.setInvert(OFF); 00229 lcd.locate(0,4); 00230 lcd.printf("Flashings: %d",heartbeat); // Led Flasings Transcurridos 00231 wait(0.5); 00232 // Blinking_Led(); // Parapadeo del LED por Software 00233 } 00234 } 00235 /* END main */ 00236 00237 /* 00238 ................................................................................ 00239 : Rutinas de los Vectores de Interrupción 00240 ................................................................................ 00241 */ 00242 /* 00243 ** =================================================================== 00244 ** Vector : Ticker_OnInterrupt() 00245 */ 00246 /*! 00247 ** @brief 00248 ** Called after Ticker is done, [Interrupt service/event] 00249 ** and it is enabled: 00250 ** TimerInt.attach_us(&Ticker_OnInterrupt, TICKER_RATE); 00251 ** the event is enabled and will be executed every [TICKER_RATE] 00252 ** @param 00253 ** UserDataPtr - Pointer to the user or 00254 ** RTOS specific data. The pointer is passed 00255 ** as the parameter of Init method. 00256 */ 00257 /* ===================================================================*/ 00258 void Ticker_OnInterrupt() // Rutina de Atención al Ticker 00259 { 00260 counter--; // Aquí va la Rutina de Servicio ! 00261 if (!counter) 00262 { 00263 led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (Toggle the LED) 00264 if(led_monitor==0) terminal.printf("Led Toggled %d Times!\r",heartbeat); 00265 heartbeat++; // Incrementa el contador de Pulsaciones 00266 counter = Rate; // Restablece el contador 00267 } 00268 } 00269 /* END Events */ 00270 /* 00271 ________________________________________________________________________________ 00272 | 00273 | Funciones Prototipo 00274 |_______________________________________________________________________________ 00275 */ 00276 // Las Funciones Prototipo van aquí ! 00277 /* 00278 |------------------------------------------------------------------------------- 00279 | Función : Caratula() 00280 | 00281 | Descripción : Rutina que muestra la Carátula de Bienvenida en la 00282 | Terminal Serial 00283 | 00284 | Parámetros : Ninguno 00285 | 00286 | Retorna : Nada 00287 |------------------------------------------------------------------------------- 00288 */ 00289 void Caratula() // Carátula de Bienvenida 00290 { terminal.printf ("\t\e[1;37;41mInstituto Politecnico Nacional\e[0m\n\r"); 00291 terminal.printf ("\e[1;37;42mESCUELA SUPERIOR DE INGENIERIA MECANICA Y ELECTRICA\e[0m\n\r\v"); 00292 terminal.printf ("\t\e[1;31;40mPrueba \e[1;35;40mde \e[1;33;40mla \e[1;34;40mPantalla \e[1;32;40mLCD \e[0m\n\r\v\v\e[0m"); 00293 } 00294 /* 00295 |------------------------------------------------------------------------------- 00296 | Función : Setup() 00297 | 00298 | Descripción : Rutina para inicialización de los puertos y funciones 00299 | de la Bluepill 00300 | 00301 | Parámetros : Ninguno 00302 | 00303 | Retorna : Nada 00304 |------------------------------------------------------------------------------- 00305 */ 00306 void Setup() // Inicialización del Hardware del Sistema 00307 { 00308 /* Inicia la comunicación la Terminal */ /* 115200 Bauds, 8 bits, 1 stop, N parity */ 00309 terminal.baud(115200); // Se inicia la comunicación serial. 00310 terminal.printf("Beginig Start Up, Please wait...\n\r"); 00311 /* Prueba del Buzzer */ 00312 terminal.printf("Testing Buzzer... \n\r"); 00313 Buzzer_Beep(); 00314 /* Inicialización del Bluetooth */ 00315 bluetooth.baud(115200); // Se inicia la comunicación Bluetooth. 00316 // bluetooth.scanf("%s", buf); //Lee un carácter desde el Bluetooth 00317 // bluetooth.printf("recv: %s", buf); //Hace eco al Bluetooth 00318 // terminal.printf("recv: %s\r\n", buf); //Imprime en la Terminal el caracter recibido 00319 bluetooth.printf("Bluetooth Starting OK! ... \n\r"); 00320 terminal.printf("Bluetooth Starting OK! ... \n\r"); 00321 /* Configufración del Display LCD */ /* Mucho OjO !!! */ 00322 #if LCD_INTERFACE == 1 00323 /* LCD Utilizando el I2C */ 00324 i2c_lcd.frequency(100000); // Frecuencia de operación para el I2C 00325 i2c_lcd.start(); // Inicio de operación para el I2C 00326 I2C_Scanner(); // Busca Dispositivos I2C conectados al Bus 00327 terminal.printf("I2C Initialzed...\n\r"); 00328 #endif 00329 #if LCD_INTERFACE == 2 00330 /* LCD Utilizando el Puerto SPI */ 00331 spi_lcd.frequency(1000000); // Frecuencia de operación para el SPI = 1MHz 00332 spi_lcd.format(8,0); // Número de Bits y Modo de Operación para el SPI 00333 // SPI1 -> SPIx_C1 |= 0x01; // Formato de la Trama (LSBFE): 0 = MSB (default), 1= LSB 00334 SSel=FALSE; // Desactiva el Latch del SN74HC595 00335 terminal.printf("SPI Initialzed...\n\r"); 00336 #endif 00337 /* Prueba de operación de la Interfaz al LCD */ 00338 #if LCD_INTERFACE == 1 00339 terminal.printf("LCD on I2C interface Address: 0x%X, \n\r",I2C_ADDRESS); 00340 #endif 00341 #if LCD_INTERFACE == 2 00342 terminal.printf("LCD on SPI interface \n\r"); 00343 if ((SPI1 -> SPIx_C1 & 0x01) > 0) terminal.printf ("SPI LSB First \n\r"); 00344 else terminal.printf ("SPI MSB First \n\r"); 00345 #endif 00346 /* Prueba de operación del LCD */ 00347 terminal.printf("LCD Test, please wait...\n\r"); 00348 Test_LCD(); // Rutina de prueba del LCD 00349 terminal.printf("LCD Initialized Succesfuly...\n\r"); 00350 /* Arranque de la interrupción por el Ticker */ 00351 terminal.printf("Ticker Starting Now...\n\r"); 00352 TimerInt.attach_us(&Ticker_OnInterrupt, TICKER_RATE); // Le asigna el periodo de interrupción de 1ms (TICKER_RATE=1000) 00353 } // end of Setup 00354 /* 00355 |------------------------------------------------------------------------------- 00356 | Función : Test_LCD() 00357 | 00358 | Descripción : Rutina para inicialización del LCD y funciones 00359 | de la Bluepill 00360 | 00361 | Parámetros : Ninguno 00362 | 00363 | Retorna : Nada 00364 |------------------------------------------------------------------------------- 00365 */ 00366 void Test_LCD() 00367 { 00368 // lcd.init(TextLCD::LCDDatalength, 4 ); // Configura el LCD en Modo 4 Bits (Modo GPIO) 00369 lcd.setBacklight(TextLCD::LightOn); // Enciende la Iluminación de Fondo 00370 lcd.setCursor(TextLCD::CurOff_BlkOff); // Apaga el Cursor y Apaga el Parpadeo 00371 lcd.cls(); // Limpia la Pantalla LCD 00372 lcd.locate(0,0); // Ubica cursor en Col, Ren 00373 lcd.printf("Hello World!\n"); // El LCD saluda al Mundo! 00374 lcd.setInvert(ON); 00375 lcd.printf("Hola Mundo!\n"); // El LCD saluda al Mundo! 00376 lcd.setInvert(OFF); 00377 lcd.printf("Ciao Mondo!\n"); // El LCD saluda al Mundo! 00378 lcd.setInvert(ON); 00379 lcd.printf("Bonjour le Monde"); // El LCD saluda al Mundo! 00380 wait(5); 00381 lcd.cls(); // Limpia el Display LCD 00382 lcd.setCursor(TextLCD::CurOn_BlkOn); // Cursor Encendido, Parpadeo Encendido 00383 terminal.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); 00384 Timer Elpased_Time; // Inicializa el Tiempo a Transcurrir 00385 Elpased_Time.start(); // Comienza a contar el tiempo transcurrido 00386 for (int row=0; row<lcd.rows(); row++)// Prueba toda la Pantalla 00387 { 00388 int col=0; 00389 terminal.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); 00390 lcd.putc('0' + row); // Enumera los renglones 00391 for (col=1; col<lcd.columns()-1; col++) 00392 { 00393 lcd.putc('*'); // Llena la linea con el carácter "*" 00394 } 00395 terminal.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); 00396 lcd.putc('+'); // Al final de la línea agrega el "+" 00397 } 00398 Elpased_Time.stop(); // Detiene el Contador de Ticks 00399 terminal.printf("All my hard work took %f sec\r\n", Elpased_Time.read()); // Calcula el tiempo transcurrido 00400 wait(1); // Espera por 1 segundo 00401 terminal.printf("LCD Display and TextLCD Enhanced Test Completed.\n\r"); 00402 wait(1); // Espera 1 segundo 00403 lcd.cls(); // Limpia la Pantalla 00404 // lcd.setBacklight(TextLCD::LightOff); // Apaga la Iluminación de Fondo 00405 lcd.setCursor(TextLCD::CurOff_BlkOn); // Apaga el Cursor y Enciende el Parpadeo 00406 // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780. 00407 // They are defined by a 5x7 bitpattern. 00408 lcd.setUDC(0, (char *) udc_0); // Selecciona el caracter para el cursor |> 00409 lcd.putc(0); // Lo imprime en la Pantalla LCD 00410 lcd.printf(" LCD Ready... "); // El LCD está listo para usarse 00411 wait(2); // Espera 2 segundos 00412 lcd.setCursor(TextLCD::CurOff_BlkOff); // Apaga el Cursor y Apaga el Parpadeo 00413 terminal.printf("LCD Starting OK! ... \n\r"); 00414 } // end of Test_LCD 00415 00416 /* 00417 |------------------------------------------------------------------------------- 00418 | Función : Buzzer_Beep() 00419 | 00420 | Descripción : Rutina para prueba del Buzzer 00421 | 00422 | Parámetros : Ninguno 00423 | 00424 | Retorna : Nada 00425 |------------------------------------------------------------------------------- 00426 */ 00427 void Buzzer_Beep() // Software routine for Buzzer Beep 00428 { 00429 // terminal.printf("Testing Buzzer... \n\r"); 00430 buzzer = BUZZ_ON; 00431 wait_ms(750); 00432 buzzer = BUZZ_OFF; 00433 wait_ms(125); 00434 buzzer = BUZZ_ON; 00435 wait_ms(250); 00436 buzzer = BUZZ_OFF; 00437 wait_ms(125); 00438 buzzer = BUZZ_ON; 00439 wait_ms(500); 00440 buzzer = BUZZ_OFF; 00441 // terminal.printf("Buzzer OK ! \n\r"); 00442 } 00443 /* 00444 |------------------------------------------------------------------------------- 00445 | Función : Blinking_Led() 00446 | 00447 | Descripción : Rutina de parpadeo del Led por software 00448 | 00449 | Parámetros : Ninguno 00450 | 00451 | Retorna : Nada 00452 |------------------------------------------------------------------------------- 00453 */ 00454 void Blinking_Led() // Software Blinking routine for LED 00455 { 00456 // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 00457 // So to turn the LED on or off we have to set it to 0 or 1 respectively 00458 led_monitor = 0; // turn the LED on 00459 wait_ms(200); // 200 millisecond 00460 led_monitor = 1; // turn the LED off 00461 wait_ms(1000); // 1000 millisecond 00462 } 00463 /* 00464 |------------------------------------------------------------------------------- 00465 | Función : I2C_Scanner() 00466 | 00467 | Descripción : Rutina de parpadeo del Led por software 00468 | 00469 | Parámetros : Ninguno 00470 | 00471 | Retorna : Nada 00472 |------------------------------------------------------------------------------- 00473 */ 00474 void I2C_Scanner() 00475 { 00476 #if LCD_INTERFACE == 1 00477 terminal.printf ("I2C scanner. Scanning ..."); 00478 uint8_t count = 0; 00479 char test[] = { 0b00000000, 0b00000000, // RS=0, EN=1,0, LED+=1, NC, DB4=DB5=DB6=DB7=0 en datos 00480 0b01101100, 0b00101100, // RS=0, EN=1,0, LED+=1, NC, DB4=DB5=1 en datos, 00481 0b01101100, 0b00101100, // RS=0, EN=1,0, LED+=1, NC, DB4=DB5=1 en datos, 00482 0b01101100, 0b00101100, // RS=0, EN=1,0, LED+=1, NC, DB4=DB5=1 en datos, 00483 0b01100100, 0b00100100, // RS=0, EN=1,0, LED+=1, NC, DB5=1 en datos, 00484 0b01100100, 0b00100100, // RS=0, EN=1,0, LED+=1, NC, DB5=1 en datos, 00485 0b01100110, 0b00100001, // RS=0, EN=1,0, LED+=1, NC, DB7=N=1 2 líneas, DB6=F=0 5x7puntos, 00486 0b01100000, 0b00100000, // => Display ON/OFF Control. 00487 0b01100001, 0b00100001, // RS=0, EN=1,0, LED+=1, NC, DB7=1 (Display off, cursor off, blink off) 00488 0b01100000, 0b00100000, // => Display Clear. 00489 0b01101000, 0b00101000};// RS=0, EN=1,0, LED+=1, NC, DB4=1 en datos, (Cursor Home}; // Patrón de Prueba 00490 00491 // char test[] = {0x55,0xAA,0x0F,0xF0,0xFF,0x00};// Patrón de Prueba 00492 i2c_lcd.frequency(100000); // Frecuencia de operación para el I2C (100KHz) 00493 i2c_lcd.start(); // Inicio de operación para el I2C 00494 for (int i = 8; i < 128; i++) 00495 { 00496 uint8_t acknoledge = i2c_lcd.write (i,test,22,1); //(dirección, ap_datos, N°_datos, repetición) 00497 if (acknoledge == 0) 00498 { 00499 terminal.printf ("\n\rFound address: "); 00500 terminal.printf ("%u DEC",i); // Valor de la dirección en Decimal 00501 terminal.printf (" (0x%x HEX)\n\r",i);// Valor de la dirección en Hexadecimal 00502 char data = i2c_lcd.read (i); // Lee el dato en la dirección 00503 terminal.printf ("Data: (0x%hd HEX)\n\r",data); // Valor del último dato en la dirección en Hexadecimal 00504 count++; 00505 00506 wait (1); // maybe unneeded? 00507 } // end of good response 00508 led_monitor = !led_monitor; // Parapadeo del LED 00509 } // end of for loop 00510 led_monitor = 1; // Apaga el LED 00511 i2c_lcd.stop(); // Fin de operación para el I2C 00512 terminal.printf ("\n\rDone.\n\r"); 00513 terminal.printf ("Found %d Device(s)\n\r",count); 00514 #endif 00515 } // end of I2C_Scanner 00516 00517 /* END Program */ 00518 00519 /*+----------------------------------------------------------------------------- 00520 *+ Direccinamiento de la RAM del Display: 00521 *+ 00522 *+ Los módulos de 8x1 (obsoletos) están arreglados como una líneas de 00523 *+ 8 caracteres de lada a lado. 00524 *+ "Linea 1" Las direcciones comienzan en 80h a 87h 00525 *+ 00526 *+ Los módulos de 16x1 están arreglados como dos líneas de 8 caracteres de lada a lado. 00527 *+ "Linea 1" Las direcciones comienzan en 80h a 87h (primera parte de la línea) 00528 *+ "Linea 1" Las direcciones comienzan en C0h a C7h (segunda parte de la línea) 00529 *+ de manera que al escribir caracteres al módulo, el cursor se incrementará automaticamente 00530 *+ hasta alcanzar el 9° caracter entonces tendrá que mover el cursor a la dirección C0h antes 00531 *+ de escribir el 9° caracter en el módulo de 1x16. 00532 *+ 00533 *+ Módulo de 16x2 es dos líneas por 16 caracteres 00534 *+ "Linea 1" Las direcciones comienzan en 80h a 8Fh 00535 *+ "Linea 2" Las direcciones comienzan en C0h a CFh 00536 *+ 00537 *+ Módulo de 16x4 00538 *+ "Linea 1" Las direcciones comienzan en 80h a 8Fh 00539 *+ "Linea 2" Las direcciones comienzan en C0h a CFh 00540 *+ "Linea 3" Las direcciones comienzan en 90h a 9Fh 00541 *+ "Linea 4" Las direcciones comienzan en D0h a DFh 00542 *+ 00543 *+ Módulo de 20x1 00544 *+ "Linea 1" Las direcciones comienzan en 80h a 93h 00545 *+ 00546 *+ Módulo de 20x2 00547 *+ "Linea 1" Las direcciones comienzan en 80h a 93h 00548 *+ "Linea 2" Las direcciones comienzan en C0h a D3h 00549 *+ 00550 *+ Módulo de 20x4 00551 *+ "Linea 1" Las direcciones comienzan en 80h a 93h 00552 *+ "Linea 2" Las direcciones comienzan en C0h a D3h 00553 *+ "Linea 3" Las direcciones comienzan en 94h a A7h 00554 *+ "Linea 4" Las direcciones comienzan en D4h a E7h 00555 *+ 00556 *+ Módulo de 24x2 00557 *+ "Linea 1" Las direcciones comienzan en 80h a 98h 00558 *+ "Linea 2" Las direcciones comienzan en C0h a D8h 00559 *+ 00560 *+ Módulo de 32x2 00561 *+ "Linea 1" Las direcciones comienzan en 80h a A0h 00562 *+ "Linea 2" Las direcciones comienzan en C0h a E0h 00563 *+ 00564 *+ Módulo de 40x2 00565 *+ "Linea 1" Las direcciones comienzan en 80h a A7h 00566 *+ "Linea 2" Las direcciones comienzna en C0h a E7h 00567 *+ 00568 *+ 00569 *+--------------------------------------------------------------------------- */ 00570 00571 /*+----------------------------------------------------------------------------- 00572 *+ Inicializaci¢n del Display de Cristal Líquido Alfanumérico en modo de 4 bits 00573 *+ 00574 *+ Definici¢n de pines: 00575 *+ __ Vdd GND 00576 *+ MOSI MISO SCK SS | | 00577 *+ | | | | 10K | 00578 *+ | | | | | | 00579 *+ CD 4094 DATA NC CLOCK STROBE NC OE QS ---> DATA en la siguiente etapa 00580 *+ 74HC 595 SER NC SCLK RCLK SCLR G QH' ---> SER en la siguiente etapa 00581 *+ 00582 *+ CD 4094 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 00583 *+ 74HC 595 QA QB QC QD QE QF QG QH 00584 *+ | | | | | | | | 00585 *+ | | | | | | | | 00586 *+ HD44780 R/S RW E BL DB4 DB5 DB6 DB7 00587 *+ 00588 *+ Notas: El pin RW del LCD debe estar estar siempre en "L" o conectado a GND. 00589 *+ El pin E2 es usado solo para el LCD40x4 (segundo controlador) 00590 *+ La señal BL = LED+ y debe ser usado para control del Backlight 00591 *+ Para enviar cualquier dato o instrucci¢n hay que hacer una _ 00592 *+ transici¢n de bajo a alto en el pin de E (Enable) del LCD. _| |_ 00593 *+ 00594 *+------------------------------------------------------------------------------ 00595 *+ 00596 *+ Ubicaciónn de pines: 00597 *+ --------------------------------------------------------------------- 00598 *+ | _______________________________________________________________ | 00599 *+ | | | | 00600 *+ | | | | 00601 *+ | | | | 00602 *+ | | | | 00603 *+ | | | | 00604 *+ | | | | 00605 *+ | |_______________________________________________________________| | 00606 *+ | | 00607 *+ --------------------------------------------------------------------- 00608 *+ | | | | | | | | | | | | | | | | 00609 *+ | | | | | | | | | | | | | | | | 00610 *+ 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 00611 *+ 00612 *+ 1 Vss - GND 00613 *+ 2 Vdd - Vcc 00614 *+ 3 Vee - Ajuste de contraste 00615 *+ 4 RS - (Register/String) 0=Entrada de Instrucción, 1=Entrada de Dato 00616 *+ 5 RW - Lectura/Escritura 0=Escribe al LCD, 1=Lee del LCD 00617 *+ 6 E - Señal de Habilitación "101" 00618 *+ 7 DB0 - Línea 0 del bus de datos 00619 *+ 8 DB1 - Línea 1 del bus de datos 00620 *+ 9 DB2 - Línea 2 del bus de datos 00621 *+ 10 DB3 - Línea 3 del bus de datos _ 00622 *+ 11 DB4 - Línea 4 del bus de datos | 00623 *+ 12 DB5 - Línea 5 del bus de datos \ Operación en 4 bits 00624 *+ 13 DB6 - Línea 6 del bus de datos / 00625 *+ 14 DB7 - Línea 7 del bus de datos _| 00626 *+ 15 LED+ Ánodo Backlight 00627 *+ 16 LED- Cátodo Backlight 00628 *+ 00629 *+------------------------------------------------------------------------------ 00630 *+ 00631 *+ +5V ------------*----------- Vcc PTE19 PTE18 PTE20 PTE21 PTE22 PTE23 00632 *+ | RS E D4 D5 D6 D7 00633 *+ / 00634 *+ 10k to <---------- Vee R/W ---> GND 00635 *+ 20k pot / A ---> PWM1 o R=330 ---> Vcc 00636 *+ \ K ---> GND 00637 *+ | 00638 *+ GND ------------*----------- Vss 00639 *+ 00640 *+------------------------------------------------------------------------------ 00641 *+ 00642 *+ Definici¢n de bits: 00643 *+ 00644 *+ I/D=1: (Increment/Decrement) Incremento (+) del Cursor 00645 *+ I/D=0: (Increment/Decrement) Decremento (-) del Cursor 00646 *+ D=0: (Display) Apaga el Display 00647 *+ D=1: (Display) Enciende el Display 00648 *+ C=0: (Cursor) Apaga el Cursor 00649 *+ C=1: (Cursor) Enciende el Cursor 00650 *+ B=0: (Blinking) Apaga el parpadeo del Cursor 00651 *+ B=1: (Blinking) Enciende el parpadeo del Cursor 00652 *+ S=0: (Shift) Sin corrimiento del Display 00653 *+ S=1: (Shift) Con corrimiento del Display 00654 *+ S/C=1: (Shift/Cursor) Con corrimiento del Display 00655 *+ S/C=0: (Shift/Cursor) Con Movimiento del Cursor 00656 *+ R/L=1: (Right/Left) Corrimiento a la Derecha 00657 *+ R/L=0: (Right/Left) Corrimiento a la Izquierda 00658 *+ DL=1: (Data Lenght) 8 Bits de datos 00659 *+ DL=0: (Data Lenght) 4 Bits de datos 00660 *+ N=1: (Number Lines) Modo de 2 Líneas de despliege 00661 *+ N=0: (Number Lines) Modo de 1 Línea de despliege 00662 *+ F=1: (Font) 5X10 Puntos por caracter 00663 *+ F=0: (Font) 5X7 Puntos por caracter 00664 *+ BF=1: (Busy Flag) Operación interna en proceso 00665 *+ BF=0: (Busy Flag) Listo para aceptar instrucciones/datos 00666 *+ DDRAM: (Display Data Ram) 00667 *+ CGRAM: (Character Generator RAM) 00668 *+ ACC: Address of CGRAM 00669 *+ ADD: Address of DDRAM These correspond to curser addresses. 00670 *+ AC: Address counter used for both DDRAM and CGRAM 00671 *+ 00672 *+ RS RW MSB LSB 00673 *+ Clear Display 0 0 0 0 0 0 0 0 0 1 00674 *+ Cursor at Home 0 0 0 0 0 0 0 0 1 0 00675 *+ Entry Mode Set 0 0 0 0 0 0 0 1 I/D S 00676 *+ Display ON/OFF control 0 0 0 0 0 0 1 D C B 00677 *+ Cursor/Display Shift 0 0 0 0 0 1 S/C R/L x x 00678 *+ Function Set 0 0 0 0 1 DL N F x x 00679 *+ CGRAM 0 0 0 1 -------- ACC -------- 00680 *+ DDRAM 0 0 1 ---------- ADD ---------- 00681 *+ Busy Flag/Address Read 0 1 1 -----------AC------------ 00682 *+ CGRAM/CDDRAM Data Write 1 0 Write Data 00683 *+ CGRAM/CDDRAM Data Read 1 1 Read Data 00684 *+ 00685 *+ 00686 *+ Tiempos de Ejecución: 00687 *+ Dependiendo del Oscilador Interno del LCD los tiempos de ejecución de las 00688 *+ instrucciones pueden variar. 00689 *+ Fosc 00690 *+ INSTRUCCION 160Khz 250Khz 270Khz 00691 *+ Clear Display 120us~4.9ms 82us~1.6ms 40us~1.5ms 00692 *+ Cursor Home 120us 40~1.6ms 37us~1.5ms 00693 *+ Todas las demás 120us 40us 37us 00694 *+ Lectura/Escritura 120us 40us 37us 00695 *+ Lectura de Busy Flag 1us 1us 1us 00696 00697 *+ El controlador podría estar en modo de 8 bits (reinicio de encendido) 00698 *+ o en modo de 4 bits (reinicio en caliente) en este punto. 00699 *+ Siga este procedimiento para asegurarse de que el controlador entre en el 00700 *+ estado correcto. 00701 *+ 00702 *+****************************************************************************** 00703 *+// Patrón de Configuración del LCD en modo de 4 bits (LSN first) 00704 *+****************************************************************************** 00705 *+ char init_LCD[] = {0b00000000, 0b00000000, // Datos en DB7=DB6=DB5=DB4=0, LED+=0, EN=0,RW=0,RS=0 00706 *+ 0b00111110, 0b00111010, // Datos en DB5=DB4=1, LED+=1, EN=1,0,RW=1,RS=0 00707 *+ 0b00111110, 0b00111010, // Datos en DB5=DB4=1, LED+=1, EN=1,0,RW=1,RS=0 00708 *+ 0b00111110, 0b00111010, // Datos en DB5=DB4=1, LED+=1, EN=1,0,RW=1,RS=0 00709 *+ 0b00101110, 0b00100010, // Datos en DB5=1, LED+=1, EN=1,0,RW=1,RS=0 00710 *+ 0b00101110, 0b00100010, // => Function Set Control: DB5=1, LED+=1, EN=1,0,RW=1,RS=0 00711 *+ 0b10001110, 0b10001110, // => Function Set Control: DB7=N=1 2 líneas, DB6=F=0 5x7puntos, LED+=1, EN=1,0,RW=1,RS=0 00712 *+ 0b00001110, 0b00000010, // => Display ON/OFF Control: DB7=DB6=DB5=DB4=0, LED+=1, EN=1,0,RW=1,RS=0 00713 *+ 0b00101110, 0b00100010, // => Display ON/OFF Control: DB7=1 (Display off, cursor off, blink off),LED+=1, EN=1,0,RW=1,RS=0 00714 *+ 0b00001110, 0b00000010, // => Display Clear: DB7=DB6=DB5=DB4=0, LED+=1, EN=1,0,RW=1,RS=0 00715 *+ 0b00011110, 0b00010010, // => Display Clear: D4=1, LED+=1, EN=1,0,RW=1,RS=0 00716 *+ 0b00001110, 0b00000010, // => Cursor Home: DB7=DB6=DB5=DB4=0, LED+=1, EN=1,0,RW=1,RS=0 00717 *+ 0b00101110, 0b00100010, // => Cursor Home: DB5=1, LED+=1, EN=1,0,RW=1,RS=0 , (Cursor Home}; 00718 *+ 0b01001111, 0b00001011, // => Text 0x48: DB5=1, LED+=1, EN=1,0,RW=1,RS=1 00719 *+ 0b10001111, 0b00101011, // => Text "H" : DB7=1, LED+=1, EN=1,0,RW=1,RS=1 , (ASCII "H"} 00720 *+ 0b01101111, 0b01101011, // => Text 0x6F: DB5=1, LED+=1, EN=1,0,RW=1,RS=1 00721 *+ 0b11111111, 0b11111011, // => Text "o" : DB7=DB6=DB5=DB4=1, LED+=1, EN=1,0,RW=1,RS=1 , (ASCII "o"} 00722 *+ 0b01101111, 0b01101011, // => Text 0x6C: DB6=DB5=1, LED+=1, EN=1,0,RW=1,RS=1 00723 *+ 0b11001111, 0b11001011, // => Text "l" : DB7=DB6=1, LED+=1, EN=1,0,RW=1,RS=1 , (ASCII "l"} 00724 *+ 0b01101111, 0b01101011, // => Text 0x61: DB6=DB5=1, LED+=1, EN=1,0,RW=1,RS=1 00725 *+ 0b00011111, 0b00011011, // => Text "a" : DB4=1, LED+=1, EN=1,0,RW=1,RS=1 , (ASCII "a"} 00726 *+ 0b00101111, 0b00101011, // => Text 0x21: DB5=1, LED+=1, EN=1,0,RW=1,RS=1 00727 *+ 0b00011111, 0b00011011};// => Text "!" : DB4=1, LED+=1, EN=1,0,RW=1,RS=1 , (ASCII "!"} 00728 *+ 00729 *+ La interfaz de hardware entre el MCU y la LCD en modo de 8 bits solo puede 00730 *+ recibir los 4 bits más significativos (Nibble más significativo, MSN) 00731 *+ como instrucción para cambier a modo 4. 00732 *+ En el modo de 4 bits, la pantalla LCD espera el MSN primero, seguido del LSN. 00733 *+----------------------------------------------------------------------------* 00734 *+ 00735 *+ Powered by 00736 *+ 00737 *+ T H E A N T U L I U ' S T E A M R&D Unltd 00738 *+ 00739 *+ Research, Development, Systems, Equipment, Support & Spare Parts. 00740 *+ (C) Copyright 1989-2019, All Rights Reserved 00741 *+ 00742 *+ Welcome to The Beaners Proyect Community! 00743 *+----------------------------------------------------------------------------*/ 00744 00745 /* END Mbed */
Generated on Thu Sep 22 2022 05:22:26 by
1.7.2