Este programa lee la temperatura de un sensor y la despliega en un display

Dependencies:   Hotboards_SpiLcd Hotboards_temp mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002   Hotboards_SpiLcd Library - Hello World
00003   
00004   Demonstrates the use a 16x2 LCD display.  The Hotboards_SpiLcd
00005   library works with all LCD displays that are compatible with the
00006   SP7032 driver presented on Spi Lcd board (http://www.hotboards.org).
00007   
00008   This sketch prints "Hello World!" to the LCD
00009   and shows the time.
00010   
00011   The circuit:
00012   *  BKL   -->  GND
00013   *  VDD   -->  3.3v
00014   *  GND   -->  GND
00015   *  SCLK  -->  PB_3
00016   *  SI    -->  PB_5
00017   *  CS    -->  PC_0
00018   *  RS    -->  PC_1
00019   *  RST   -->  PC_2
00020  
00021   Library and example ported by Diego from Hotboards and originally cretaed by
00022   by David A. Mellis
00023   library modified 5 Jul 2009
00024   by Limor Fried (http://www.ladyada.net)
00025   example added 9 Jul 2009
00026   by Tom Igoe
00027   modified 22 Nov 2010
00028   by Tom Igoe
00029   This example code is in the public domain.
00030  */
00031  
00032 #include "mbed.h"
00033 #include "Hotboards_SpiLcd.h"
00034 #include "Hotboards_temp.h"
00035  
00036 // new instance of serial port
00037 Serial pc(USBTX, USBRX);
00038 //I2C instance for the library
00039 I2C device1( I2C_SDA, I2C_SCL ); 
00040 // instance a sensor with address number 7 (none of the jumpers on the board is short circuted)
00041 // and also 0.5 celsius degrees resolution
00042 Hotboards_temp sensor( device1, Sensor_7);
00043  
00044  
00045 // initialize the spi peripherals, setting the spi pins 
00046 SPI device( PB_5, NC, PB_3 ); // mosi, miso, sclk
00047 // initialize the library with the numbers of the interface pins
00048 Hotboards_SpiLcd display( device, PC_0, PC_1, PC_2 ); //spi, cs, rs, rst
00049  
00050 int main( void ) 
00051 {
00052     // sensor init
00053   sensor.init();
00054   sensor.setResolution(_0p0625C);
00055  
00056     uint8_t milis = 0;
00057     // set the spi frequency to 5MHz
00058     device.frequency(5000000);
00059     // initialize internal lcd controller:
00060     display.init();
00061     // Print a message to the LCD.
00062     display.printf( "Temperatura" );
00063     
00064     while(1)
00065     
00066     {
00067           // read temperature in celcius degrees
00068          float temp = sensor.read();
00069         // set the cursor to column 0, line 1
00070         // (note: line 1 is the second row, since counting begins with 0):
00071         display.setCursor( 0, 1 );
00072         wait( 1 );
00073         milis++;
00074         // print the number of seconds since reset:
00075         display.printf( "Grados: %3.3f C", temp);
00076     }
00077 }
00078