Dheeraj Etta
/
Temp_sensor
IR temp sensor
Diff: main.cpp
- Revision:
- 1:c5f7996b1035
- Parent:
- 0:f84245f91a5a
--- a/main.cpp Fri May 14 21:19:39 2010 +0000 +++ b/main.cpp Thu Aug 06 20:32:47 2020 +0000 @@ -1,48 +1,59 @@ -// test for 20X4 LCD displaying RAM address by locate() -// ym1784 2010/05/14 -// -// e.g. -// 01234567890123456789 -// +--------------------+ -// 0|80 TextLCD 93|(0,0) .. (19,0) -// 1|C0 D3|(0,1) .. (19,1) -// 2|94 20X4 A7|(0,2) .. (19,2) -// 3|D4 E7|(0,3) .. (19,3) -// +--------------------+ +#include "mbed.h" +#include "SPI.h" +Serial pc (USBTX, USBRX); +SPI spi_temp(PB_15, PB_14, PB_13); // mosi, miso, sclk +DigitalOut spi_cs(PB_12); // chip select -#include "mbed.h" -#include "TextLCD_20X4.h" - -TextLCD_20X4 lcd(p21, p22, p26, p25, p24, p23); // rs, e, d0, d1, d2, d3 - -int main() { - lcd.locate(0,0); - lcd.printf("80"); - - lcd.locate(18,0); - lcd.printf("93"); +void temp_read () +{ + spi_cs=0; + wait(1); + float data0[9], data1[9]; + float temp[9]; + spi_temp.write(0xA0); // Sensor Temperature + wait_us(200); + data0[0] = spi_temp.write(0xFF); // Higher Byte +// if (data0[0] < 128) // Inside temp range + wait_us(200); + data1[0] = spi_temp.write(0xFF); // Lower Byte + temp[0] = (256*data0[0] + data1[0]) / 10; + +// else // Overshooting temp range +// data1[0] = 0; +// temp[0] = 85.0; } + printf("Sensor %0.2f\n",temp[0]); // Maximum Limit reached + wait_us(200); + for (int i = 1; i<=8; i++) // For rest 8-pixels + { + uint8_t p = 0xA0 + i ; - lcd.locate(0,1); - lcd.printf("C0"); - - lcd.locate(18,1); - lcd.printf("D3"); - - lcd.locate(0,2); - lcd.printf("94"); - - lcd.locate(18,2); - lcd.printf("A7"); + spi_temp.write(p); // Deciding from 1st - 8th pixel + wait_us(200); + data0[i] = spi_temp.write(0xFF); // Higher Byte + +// if (data0[i] < 128) // Inside temp range +// { + wait_us(200); + data1[i] = spi_temp.write(0xFF); // Lower Byte + temp[i] = (256*data0[i] + data1[i]) / 10; +// } +// else // Overshooting temp. range +// { data1[i] = 0; +// temp[i] = 120.0; } + printf("Pixel %d %0.2f\n",i,temp[i]); // Maximum limit reached + } + spi_cs=1; +} - lcd.locate(0,3); - lcd.printf("D4"); - - lcd.locate(18,3); - lcd.printf("E7"); +void spi_initialise() +{ spi_temp.format(8, 1); //8-bits, Mode 1 + spi_temp.frequency(100000); // 100 KHz frequency of SCLK + spi_cs=1; +} - lcd.locate(6,0); - lcd.printf("TextLCD"); - - lcd.locate(8,2); - lcd.printf("20X4"); -} +int main() +{ + printf("Temp Check\n"); + spi_initialise(); + temp_read(); +} \ No newline at end of file