![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ESTE MODULO FUNCIONA EN FRDM-KL25Z CON DISPLAY LCD 16X2
Dependencies: MAX31855 TextLCD USBDevice mbed
Fork of LCD_FRDM_KL25Z by
main.cpp@1:ac09ff440ce1, 2014-08-26 (annotated)
- Committer:
- EDCHEN
- Date:
- Tue Aug 26 02:54:05 2014 +0000
- Revision:
- 1:ac09ff440ce1
- Parent:
- 0:a6771cc1a056
this program Reads data from thermocouple with max31855 and displays it on LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:a6771cc1a056 | 1 | #include "mbed.h" |
tony63 | 0:a6771cc1a056 | 2 | #include "TextLCD.h" |
EDCHEN | 1:ac09ff440ce1 | 3 | #include "USBSerial.h" |
EDCHEN | 1:ac09ff440ce1 | 4 | #include "max31855.h" |
tony63 | 0:a6771cc1a056 | 5 | |
EDCHEN | 1:ac09ff440ce1 | 6 | |
EDCHEN | 1:ac09ff440ce1 | 7 | TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9); // rs, e, d4-d7 |
EDCHEN | 1:ac09ff440ce1 | 8 | DigitalOut myled(LED1); |
EDCHEN | 1:ac09ff440ce1 | 9 | |
EDCHEN | 1:ac09ff440ce1 | 10 | |
EDCHEN | 1:ac09ff440ce1 | 11 | //---------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 12 | //SPI Interfaces |
EDCHEN | 1:ac09ff440ce1 | 13 | SPI testSPI(PTD2,PTD3,PTD1); |
EDCHEN | 1:ac09ff440ce1 | 14 | //---------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 15 | // USBSerial serial; |
EDCHEN | 1:ac09ff440ce1 | 16 | |
EDCHEN | 1:ac09ff440ce1 | 17 | //---------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 18 | //Thermocouples |
EDCHEN | 1:ac09ff440ce1 | 19 | max31855 max1(testSPI, PTB18); |
EDCHEN | 1:ac09ff440ce1 | 20 | //---------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 21 | |
tony63 | 0:a6771cc1a056 | 22 | |
tony63 | 0:a6771cc1a056 | 23 | int main() { |
EDCHEN | 1:ac09ff440ce1 | 24 | //Initialise chip (starts internal timer) |
EDCHEN | 1:ac09ff440ce1 | 25 | max1.initialise(); |
EDCHEN | 1:ac09ff440ce1 | 26 | |
EDCHEN | 1:ac09ff440ce1 | 27 | //Float value to hold temperature returned |
EDCHEN | 1:ac09ff440ce1 | 28 | float fvalue = 0; |
EDCHEN | 1:ac09ff440ce1 | 29 | //----------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 30 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 31 | lcd.printf("Welcome\n"); |
EDCHEN | 1:ac09ff440ce1 | 32 | myled = 0; |
EDCHEN | 1:ac09ff440ce1 | 33 | wait(2); |
EDCHEN | 1:ac09ff440ce1 | 34 | |
EDCHEN | 1:ac09ff440ce1 | 35 | |
EDCHEN | 1:ac09ff440ce1 | 36 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 37 | lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 38 | lcd.printf("Set temperaure\n"); |
EDCHEN | 1:ac09ff440ce1 | 39 | // lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 40 | // lcd.printf("Current temp"); |
EDCHEN | 1:ac09ff440ce1 | 41 | myled =!myled; |
EDCHEN | 1:ac09ff440ce1 | 42 | wait(2); |
EDCHEN | 1:ac09ff440ce1 | 43 | |
EDCHEN | 1:ac09ff440ce1 | 44 | //--------------------------------------------------------------- |
EDCHEN | 1:ac09ff440ce1 | 45 | while(1) |
EDCHEN | 1:ac09ff440ce1 | 46 | { |
EDCHEN | 1:ac09ff440ce1 | 47 | //Check if the chip is ready for a reading to be taken |
EDCHEN | 1:ac09ff440ce1 | 48 | if (max1.ready()==1) |
EDCHEN | 1:ac09ff440ce1 | 49 | { |
EDCHEN | 1:ac09ff440ce1 | 50 | //Get the reading |
EDCHEN | 1:ac09ff440ce1 | 51 | fvalue = max1.read_temp(); |
EDCHEN | 1:ac09ff440ce1 | 52 | |
EDCHEN | 1:ac09ff440ce1 | 53 | if (fvalue > 2000){ |
EDCHEN | 1:ac09ff440ce1 | 54 | if(fvalue==2001){ |
EDCHEN | 1:ac09ff440ce1 | 55 | //printf("No TC"); |
EDCHEN | 1:ac09ff440ce1 | 56 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 57 | lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 58 | |
EDCHEN | 1:ac09ff440ce1 | 59 | lcd.printf("NO tc"); |
EDCHEN | 1:ac09ff440ce1 | 60 | } |
EDCHEN | 1:ac09ff440ce1 | 61 | else if(fvalue==2002){ |
EDCHEN | 1:ac09ff440ce1 | 62 | // printf("Short to GND"); |
EDCHEN | 1:ac09ff440ce1 | 63 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 64 | lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 65 | |
EDCHEN | 1:ac09ff440ce1 | 66 | lcd.printf("short to GND"); |
EDCHEN | 1:ac09ff440ce1 | 67 | } |
EDCHEN | 1:ac09ff440ce1 | 68 | else if(fvalue==2004){ |
EDCHEN | 1:ac09ff440ce1 | 69 | // printf("Short to VCC"); |
EDCHEN | 1:ac09ff440ce1 | 70 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 71 | lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 72 | |
EDCHEN | 1:ac09ff440ce1 | 73 | lcd.printf("short to VCC"); |
EDCHEN | 1:ac09ff440ce1 | 74 | } |
EDCHEN | 1:ac09ff440ce1 | 75 | } |
EDCHEN | 1:ac09ff440ce1 | 76 | else{ |
EDCHEN | 1:ac09ff440ce1 | 77 | // printf("Temperature is: %f\n\r", fvalue); |
EDCHEN | 1:ac09ff440ce1 | 78 | //lcd.locate(6,0); |
EDCHEN | 1:ac09ff440ce1 | 79 | // lcd.printf((char*)fvalue); |
EDCHEN | 1:ac09ff440ce1 | 80 | lcd.cls(); |
EDCHEN | 1:ac09ff440ce1 | 81 | lcd.locate(0,0); |
EDCHEN | 1:ac09ff440ce1 | 82 | lcd.printf("Current temp"); |
EDCHEN | 1:ac09ff440ce1 | 83 | lcd.locate(0,1); |
EDCHEN | 1:ac09ff440ce1 | 84 | |
EDCHEN | 1:ac09ff440ce1 | 85 | lcd.printf("T=%2.1fC",fvalue); |
EDCHEN | 1:ac09ff440ce1 | 86 | |
EDCHEN | 1:ac09ff440ce1 | 87 | // lcd.printf("T=%f\n\r",fvalue); |
EDCHEN | 1:ac09ff440ce1 | 88 | |
EDCHEN | 1:ac09ff440ce1 | 89 | |
EDCHEN | 1:ac09ff440ce1 | 90 | } |
EDCHEN | 1:ac09ff440ce1 | 91 | } |
EDCHEN | 1:ac09ff440ce1 | 92 | |
EDCHEN | 1:ac09ff440ce1 | 93 | //Heartbeat signal (not necessary) |
EDCHEN | 1:ac09ff440ce1 | 94 | myled = !myled; |
EDCHEN | 1:ac09ff440ce1 | 95 | |
EDCHEN | 1:ac09ff440ce1 | 96 | //Delay is not required, here simply for test program |
EDCHEN | 1:ac09ff440ce1 | 97 | wait(0.25); |
EDCHEN | 1:ac09ff440ce1 | 98 | } |
EDCHEN | 1:ac09ff440ce1 | 99 | |
EDCHEN | 1:ac09ff440ce1 | 100 | } |