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 /******************************************************************************* 00003 Nombre del Proyecto: SENSOR TEMPERATURA 00004 Se lee un sensor de temperatura LM61CIZ a travès deun canal analógico del ADC 00005 (A0/PTB0) y el resultado se muestra en la terminal serial y en un LCD 16x12. 00006 Autor: Christian G.S.L. 00007 Fecha: 16-05-2019 00008 Software: MBED 00009 Hardware: LCD16x2, LM61ciz 00010 Diagrama: 00011 Tarjeta KL25Z 00012 -------------------- 00013 /|\| | 00014 | | | 00015 --|RST | 00016 | | 00017 LM61cizVout--->|PTB0 |----<LCD 16x2> 00018 00019 Diagrama de conexión al LCD. 00020 =============================================================================== 00021 LCD pin Connect to 00022 ------------------------------------------------------------------------------- 00023 01 - GND GND, pot 00024 02 - VCC +5V, pot 00025 03 - Contrast Pot wiper 00026 04 - RS PTE20 00027 05 - R/W GND 00028 06 - EN PTE21 00029 07 - DB0 GND 00030 08 - DB1 GND 00031 09 - DB2 GND 00032 10 - DB3 GND 00033 11 - DB4 PTE22 00034 12 - DB5 PTE23 00035 13 - DB6 PTE29 00036 14 - DB7 PTE30 00037 15 - BL- GND 00038 16 - BL+ +5V 00039 *******************************************************************************/ 00040 //ARCHIVOS DE CABECERA. 00041 #include "mbed.h" 00042 #include "TextLCD.h" 00043 //****************************************************************************** 00044 //DECLARACION DE FUNCIONES. 00045 00046 //****************************************************************************** 00047 //INICIALIZACION. 00048 Serial pc(USBTX, USBRX); // tx, rx inicialización del puerto serial emulado. 00049 Serial uart1(PTE0, PTE1);// inicialización del puerto serial uart1 TX=PTE0, RX=PTE1 00050 00051 //inicialización de pines para control de LCD 00052 TextLCD lcd(PTE20, PTE21, PTE22, PTE23, PTE29, PTE30, TextLCD::LCD16x2); // rs, e, d4-d7, LCDType 00053 00054 AnalogIn Sensor(PTB0); //inicialización de un canal del ADC 00055 00056 unsigned short int lectura_ADC; 00057 float Vent; 00058 float temperatura; 00059 00060 //PROGRAMA PRINCIPAL. 00061 //****************************************************************************** 00062 int main() 00063 { 00064 pc.baud(9600);//Velocidad bps (Taza de transmisión) 00065 pc.format(8,Serial::None,1);//8 bits de datos,sin paridad,1 bit de paro 00066 uart1.baud(9600);//Velocidad bps (Taza de transmisión) 00067 uart1.format(8,Serial::None,1);//8 bits de datos,sin paridad,1 bit de paro 00068 00069 lcd.locate(0,0); 00070 lcd.printf("Temperatura "); 00071 00072 while(1) //Bucle infinito 00073 { 00074 lectura_ADC = Sensor.read_u16();//Read the input voltage, represented as an unsigned short in the range [0x0000, 0xFFFF]. 00075 pc.printf("%d \n", lectura_ADC); 00076 Vent = (2.30*lectura_ADC)/65535.0; 00077 pc.printf("%f \n", Vent); 00078 temperatura = (Vent-0.6)/0.01; 00079 lcd.locate(0,1);//(col,row) 00080 lcd.printf("%.2f",temperatura); 00081 lcd.putc(223); //imprime símbolo º 00082 lcd.printf("C "); //imprime C 00083 00084 pc.printf("%f \n", temperatura); 00085 wait(0.5);//1/2 segundo para refrescar lectura del ADC wait_ms(250);wait_ms(250); 00086 } 00087 } 00088 //******************************************************************************
Generated on Sun Jul 17 2022 07:49:29 by
1.7.2