ATHANASIOS POLITIS / TmpLM74
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TmpLM74.h Source File

TmpLM74.h

00001 /* mbed tmpLM74 Library, for a LM74 based digital thermometer
00002  * Copyright (c) 2011, atpolitis, http://mbed.org
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 #ifndef MBED_TMPLM74_H
00024 #define MBED_TMPLM74_H
00025 
00026 #include "mbed.h"
00027 
00028 #define INVALID_LM74_TEMP   0X961
00029 #define MAX_LM74_TEMP       (INVALID_LM74_TEMP-1)*0.0625
00030 
00031 /** An LM74 based digital thermometer
00032  *
00033  * Currently supports SPI peripheral interface
00034  *
00035  * @code
00036  * #include "mbed.h"
00037  * #include "tmpLM74.h"
00038  * 
00039  * Serial pc(USBTX, USBRX); // tx, rx
00040  * DigitalOut myled(LED1);
00041  *
00042  * TmpLM74 Temp74(p5, p6, p7, p8);
00043  *
00044  * //   mbed connections:
00045  * //                       mosi(p5) to LM74 pin 1, through 10k
00046  * //                       miso(p6) to LM74 pin 1
00047  * //                       sclk(p7) to LM74 pin 2
00048  * //                       miso(p8) to LM74 pin 7
00049  *
00050  * //TmpLM74.startLM74();       // CAN be used, but NOT necessary (invoked within readTemp(), if needed)
00051  *
00052  * int main() {
00053  *
00054  *      float TempC;
00055  *
00056  *      pc.printf("HELLO!,  testing LM74 temperature sensor ...\n\r");
00057  *
00058  *      for (int i = 0; i < 10; i++){
00059  *          wait(2);
00060  *          TempC = Temp74.readTemp();
00061  *          pc.printf("Temperature = ");
00062  *          if(TempC > MAX_LM74_TEMP) {         // check whether temp is valid
00063  *              pc.printf(" ? *C\n", TempC);
00064  *          } else {
00065  *              pc.printf("%3.1f *C\n", TempC);
00066  *          }
00067  *          myled = !myled;
00068  *      }
00069  *      Temp74.shutLM74down();
00070  *      while(1){
00071  *          wait(1);
00072  *          myled = !myled;
00073  *      }
00074  * }
00075  * @endcode
00076  */
00077 //  ********************************************************************
00078 //      in this version, class TmpLM74 is derived from class SPI
00079 //      and inherits its members
00080 //
00081 //  ********************************************************************
00082 
00083 class TmpLM74: public SPI {
00084 
00085     public:
00086     
00087         TmpLM74(PinName mosi, PinName miso, PinName sclk, PinName csLM74);
00088         
00089         float readTemp(void);
00090         void startLM74(void);
00091         void shutLM74down(void);
00092         
00093     protected:
00094         DigitalOut _csLM74;
00095 };
00096 
00097 #endif