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

Dependencies:   Hotboards_SpiLcd Hotboards_temp mbed

Committer:
AlejandroZamudio
Date:
Thu Jun 16 18:41:30 2016 +0000
Revision:
0:145a79fbba51
Version1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AlejandroZamudio 0:145a79fbba51 1 /*
AlejandroZamudio 0:145a79fbba51 2 Hotboards_SpiLcd Library - Hello World
AlejandroZamudio 0:145a79fbba51 3
AlejandroZamudio 0:145a79fbba51 4 Demonstrates the use a 16x2 LCD display. The Hotboards_SpiLcd
AlejandroZamudio 0:145a79fbba51 5 library works with all LCD displays that are compatible with the
AlejandroZamudio 0:145a79fbba51 6 SP7032 driver presented on Spi Lcd board (http://www.hotboards.org).
AlejandroZamudio 0:145a79fbba51 7
AlejandroZamudio 0:145a79fbba51 8 This sketch prints "Hello World!" to the LCD
AlejandroZamudio 0:145a79fbba51 9 and shows the time.
AlejandroZamudio 0:145a79fbba51 10
AlejandroZamudio 0:145a79fbba51 11 The circuit:
AlejandroZamudio 0:145a79fbba51 12 * BKL --> GND
AlejandroZamudio 0:145a79fbba51 13 * VDD --> 3.3v
AlejandroZamudio 0:145a79fbba51 14 * GND --> GND
AlejandroZamudio 0:145a79fbba51 15 * SCLK --> PB_3
AlejandroZamudio 0:145a79fbba51 16 * SI --> PB_5
AlejandroZamudio 0:145a79fbba51 17 * CS --> PC_0
AlejandroZamudio 0:145a79fbba51 18 * RS --> PC_1
AlejandroZamudio 0:145a79fbba51 19 * RST --> PC_2
AlejandroZamudio 0:145a79fbba51 20
AlejandroZamudio 0:145a79fbba51 21 Library and example ported by Diego from Hotboards and originally cretaed by
AlejandroZamudio 0:145a79fbba51 22 by David A. Mellis
AlejandroZamudio 0:145a79fbba51 23 library modified 5 Jul 2009
AlejandroZamudio 0:145a79fbba51 24 by Limor Fried (http://www.ladyada.net)
AlejandroZamudio 0:145a79fbba51 25 example added 9 Jul 2009
AlejandroZamudio 0:145a79fbba51 26 by Tom Igoe
AlejandroZamudio 0:145a79fbba51 27 modified 22 Nov 2010
AlejandroZamudio 0:145a79fbba51 28 by Tom Igoe
AlejandroZamudio 0:145a79fbba51 29 This example code is in the public domain.
AlejandroZamudio 0:145a79fbba51 30 */
AlejandroZamudio 0:145a79fbba51 31
AlejandroZamudio 0:145a79fbba51 32 #include "mbed.h"
AlejandroZamudio 0:145a79fbba51 33 #include "Hotboards_SpiLcd.h"
AlejandroZamudio 0:145a79fbba51 34 #include "Hotboards_temp.h"
AlejandroZamudio 0:145a79fbba51 35
AlejandroZamudio 0:145a79fbba51 36 // new instance of serial port
AlejandroZamudio 0:145a79fbba51 37 Serial pc(USBTX, USBRX);
AlejandroZamudio 0:145a79fbba51 38 //I2C instance for the library
AlejandroZamudio 0:145a79fbba51 39 I2C device1( I2C_SDA, I2C_SCL );
AlejandroZamudio 0:145a79fbba51 40 // instance a sensor with address number 7 (none of the jumpers on the board is short circuted)
AlejandroZamudio 0:145a79fbba51 41 // and also 0.5 celsius degrees resolution
AlejandroZamudio 0:145a79fbba51 42 Hotboards_temp sensor( device1, Sensor_7);
AlejandroZamudio 0:145a79fbba51 43
AlejandroZamudio 0:145a79fbba51 44
AlejandroZamudio 0:145a79fbba51 45 // initialize the spi peripherals, setting the spi pins
AlejandroZamudio 0:145a79fbba51 46 SPI device( PB_5, NC, PB_3 ); // mosi, miso, sclk
AlejandroZamudio 0:145a79fbba51 47 // initialize the library with the numbers of the interface pins
AlejandroZamudio 0:145a79fbba51 48 Hotboards_SpiLcd display( device, PC_0, PC_1, PC_2 ); //spi, cs, rs, rst
AlejandroZamudio 0:145a79fbba51 49
AlejandroZamudio 0:145a79fbba51 50 int main( void )
AlejandroZamudio 0:145a79fbba51 51 {
AlejandroZamudio 0:145a79fbba51 52 // sensor init
AlejandroZamudio 0:145a79fbba51 53 sensor.init();
AlejandroZamudio 0:145a79fbba51 54 sensor.setResolution(_0p0625C);
AlejandroZamudio 0:145a79fbba51 55
AlejandroZamudio 0:145a79fbba51 56 uint8_t milis = 0;
AlejandroZamudio 0:145a79fbba51 57 // set the spi frequency to 5MHz
AlejandroZamudio 0:145a79fbba51 58 device.frequency(5000000);
AlejandroZamudio 0:145a79fbba51 59 // initialize internal lcd controller:
AlejandroZamudio 0:145a79fbba51 60 display.init();
AlejandroZamudio 0:145a79fbba51 61 // Print a message to the LCD.
AlejandroZamudio 0:145a79fbba51 62 display.printf( "Temperatura" );
AlejandroZamudio 0:145a79fbba51 63
AlejandroZamudio 0:145a79fbba51 64 while(1)
AlejandroZamudio 0:145a79fbba51 65
AlejandroZamudio 0:145a79fbba51 66 {
AlejandroZamudio 0:145a79fbba51 67 // read temperature in celcius degrees
AlejandroZamudio 0:145a79fbba51 68 float temp = sensor.read();
AlejandroZamudio 0:145a79fbba51 69 // set the cursor to column 0, line 1
AlejandroZamudio 0:145a79fbba51 70 // (note: line 1 is the second row, since counting begins with 0):
AlejandroZamudio 0:145a79fbba51 71 display.setCursor( 0, 1 );
AlejandroZamudio 0:145a79fbba51 72 wait( 1 );
AlejandroZamudio 0:145a79fbba51 73 milis++;
AlejandroZamudio 0:145a79fbba51 74 // print the number of seconds since reset:
AlejandroZamudio 0:145a79fbba51 75 display.printf( "Grados: %3.3f C", temp);
AlejandroZamudio 0:145a79fbba51 76 }
AlejandroZamudio 0:145a79fbba51 77 }
AlejandroZamudio 0:145a79fbba51 78