diff --git a/libraries/ModbusSerial/ModbusSerial.h b/libraries/ModbusSerial/ModbusSerial.h index 5843817..e63fa95 100644 --- a/libraries/ModbusSerial/ModbusSerial.h +++ b/libraries/ModbusSerial/ModbusSerial.h @@ -1,6 +1,6 @@ /* ModbusSerial.h - Header for ModbusSerial Library - Copyright (C) 2014 André Sarmento Barbosa + Copyright (C) 2014 André Sarmento Barbosa */ #include #include @@ -9,11 +9,17 @@ #define MODBUSSERIAL_H //#define USE_SOFTWARE_SERIAL +#define USE_FLASH_PROGMEM + #ifdef USE_SOFTWARE_SERIAL #include #endif +#ifdef USE_FLASH_PROGMEM +#include +#endif + class ModbusSerial : public Modbus { private: Stream* _port; @@ -41,8 +47,14 @@ class ModbusSerial : public Modbus { bool send(byte* frame); }; -/* Table of CRC values for high–order byte */ -const byte _auchCRCHi[] = { +/* Table of CRC values for high–order byte */ +#ifndef USE_FLASH_PROGMEM + const byte _auchCRCHi[] = { +#endif + +#ifdef USE_FLASH_PROGMEM + const byte _auchCRCHi[] PROGMEM = { +#endif 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, @@ -62,8 +74,14 @@ const byte _auchCRCHi[] = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40}; -/* Table of CRC values for low–order byte */ -const byte _auchCRCLo[] = { +/* Table of CRC values for low–order byte */ +#ifndef USE_FLASH_PROGMEM + const byte _auchCRCLo[] = { +#endif + +#ifdef USE_FLASH_PROGMEM + const byte _auchCRCLo[] PROGMEM = { +#endif 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, @@ -83,4 +101,3 @@ const byte _auchCRCLo[] = { 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40}; -#endif //MODBUSSERIAL_H