![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sistema de monitoramento de controle e temperatura - GEPOC
Dependencies: DHT MODSERIAL ModbusSlave mbed
Fork of FRDM_RGBLED by
Diff: main.cpp
- Revision:
- 3:dd9b3bcbd36a
- Parent:
- 2:03e5c29343d1
- Child:
- 4:7bdab599ad88
--- a/main.cpp Tue Oct 23 09:33:36 2012 +0000 +++ b/main.cpp Mon Nov 09 18:59:28 2015 +0000 @@ -1,21 +1,102 @@ #include "mbed.h" +#include <string.h> +#include <stdio.h> + +#include "ModbusSlave.h" + +#include "MODSERIAL.h" + +MODSERIAL Modbus(USBTX,USBRX); + +SPI myspi(PTD2, PTD3, PTD1); // mosi, miso, sclk + +//////////////// TERMOCOUPLERS ////////////////////////////// + +DigitalOut T1(PTC9); +DigitalOut T2(PTA13); +DigitalOut T3(PTD0); +DigitalOut T4(PTB3); + +DigitalOut ENABLE(PTC1); + +//DigitalOut LED(LED_RED); -PwmOut r (LED_RED); -PwmOut g (LED_GREEN); -PwmOut b (LED_BLUE); +float temp1 = 0; +float temp2 = 0; +float temp3 = 0; +float temp4 = 0; + -int main() { - r.period(0.001); - g.period(0.001); - b.period(0.001); +//////////////// MODBUS Registers (Slave) /////////////////// +enum +{ + // just add or remove registers and your good to go... + // The first register starts at address 0 + TERM_1, // Pot analog read + TERM_2, // Temp analog read + TERM_3, // Light analog read + TERM_4, // Moisture analog read + HOLDING_REGS_SIZE + // total number of registers for function 3 and 16 share the same register array +}; + +unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array + +//////////////////////////////////////////////////////////// + + - while (true) { - for (float i = 0.0; i < 1.0 ; i += 0.001) { - float p = 3 * i; - r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); - g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); - b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); - wait (0.0025); - } - } -} \ No newline at end of file +uint16_t thermoparRead(void) +{ + uint16_t high = 0; + uint16_t low = 0; + + bool scToVcc; + bool scToGnd; + bool opened; + bool fail; + + high = ((myspi.write(0)<<8)&0xff00) + (myspi.write(0)&0x00ff); + low = ((myspi.write(0)<<8)&0xff00) + (myspi.write(0)&0x00ff); + + // Get errors from data + scToVcc = low & 0x0004; + scToGnd = low & 0x0002; + opened = low & 0x0001; + fail = high & 0x0001; + + if(opened) return 2; + if(fail) return 1; + return high&0xfffc; +} + + +int main() +{ + //CONFIGURE MODBUS + modbus_configure(&Modbus, 9600, 1, 2, &ENABLE, HOLDING_REGS_SIZE, holdingRegs); + + while (true) + { + modbus_update(); + + T1 = 0; + holdingRegs[TERM_1] = thermoparRead(); + T1 = 1; + + T2 = 0; + holdingRegs[TERM_2] = thermoparRead(); + T2 = 1; + + T3 = 0; + holdingRegs[TERM_3] = thermoparRead(); + T3 = 1; + + T4 = 0; + holdingRegs[TERM_4] = thermoparRead(); + T4 = 1; + } +} + + +