SAA1064 4 Digit Library
SAA1064 4 Digit Library for SMD IoTKit Shield
Revision 1:e6f764285b44, committed 2015-04-20
- Comitter:
- marcel1691
- Date:
- Mon Apr 20 07:36:41 2015 +0000
- Parent:
- 0:8b1f83a2ae0a
- Commit message:
- File location
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SAA1064.cpp Mon Apr 20 07:36:41 2015 +0000 @@ -0,0 +1,82 @@ +/* SAA1064 4 Digit Library + * Copyright (c) 2015 Marcel (mc-b) Bernet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbed.h" +#include "SAA1064.h" + +SAA1064::SAA1064( PinName sda, PinName scl, uint8_t deviceAddress ) +{ + i2c = new I2C( sda, scl ); + slaveAddress = deviceAddress; + init(); +} + + +SAA1064::SAA1064( I2C *i2c, uint8_t deviceAddress ) +{ + this->i2c = i2c; + slaveAddress = deviceAddress; + init(); +} + +/** Write digits +* +* @param digit1 LED segment pattern for digit1 (MSB) +* @param digit2 LED segment pattern for digit2 +* @param digit3 LED segment pattern for digit3 +* @param digit4 LED segment pattern for digit4 (LSB) +*/ +void SAA1064::write( uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4 ) +{ + digit1 = SAA1064_SEGM[digit1]; + digit2 = SAA1064_SEGM[digit2]; + digit3 = SAA1064_SEGM[digit3]; + digit4 = SAA1064_SEGM[digit4]; + + data[0] = 1; + data[1] = ((digit4<<4) & 0xF0) | (digit2 & 0x0F); + data[2] = ((digit3<<4) & 0xF0) | (digit1 & 0x0F); + data[3] = ((digit2>>4) & 0x0F) | (digit4 & 0xF0); + data[4] = ((digit1>>4) & 0x0F) | (digit3 & 0xF0); + i2c->write( slaveAddress, (char*) data, 5 ); +} + +/** Write Integer +* +* @param value integer value to display, valid range -999...9999 +*/ +void SAA1064::writeInt( int value ) +{ + write( value / 1000, (value % 1000) / 100, (value % 100) / 10, value % 10 ); +} + +/** Init I2C bus +*/ +void SAA1064::init( void ) +{ + // init + data[0] = 0x00; + data[1] = 0x47; + i2c->write( slaveAddress, (char*) data, 2 ); + + // blank display + data[0] = 1; + data[1] = 0; + data[2] = 0; + data[3] = 0; + data[4] = 0; + i2c->write( slaveAddress, (char*) data, 5 ); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SAA1064.h Mon Apr 20 07:36:41 2015 +0000 @@ -0,0 +1,83 @@ +/* SAA1064 4 Digit Library + * Copyright (c) 2015 Marcel (mc-b) Bernet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _SAA1064_H +#define _SAA1064_H + +//Address Defines for SAA1064 +#define SAA1064_SA0 0x70 +#define SAA1064_SA1 0x72 +#define SAA1064_SA2 0x74 +#define SAA1064_SA3 0x76 + +//Defines for Segments +const uint8_t SAA1064_SEGM[] = {0xE7, //0 + 0x84, //1 + 0xD3, //2 + 0xD6, //3 + 0xB4, //4 + 0x76, //5 + 0x77, //6 + 0xC4, //7 + 0xF7, //8 + 0xF6, //9 + 0xF5, //A + 0x37, //B + 0x13, //C + 0x97, //D + 0x73, //E + 0x71 + }; //F + +/** Create an SAA1064 object connected to the specified I2C bus and deviceAddress +*/ +class SAA1064 +{ +public: + + /** Create a SAA1064 LED displaydriver object using a specified I2C bus and slaveaddress + * + * @param sda Pin + * @param scl Pin + * @param char deviceAddress the address of the SAA1064 + */ + SAA1064( PinName sda = D14, PinName scl = D15, uint8_t deviceAddress = SAA1064_SA0 ); + + SAA1064( I2C* i2c, uint8_t deviceAddress = SAA1064_SA0 ); + + /** Write digits + * + * @param digit1 LED segment pattern for digit1 (MSB) + * @param digit2 LED segment pattern for digit2 + * @param digit3 LED segment pattern for digit3 + * @param digit4 LED segment pattern for digit4 (LSB) + */ + void write(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4); + + /** Write Integer + * + * @param value integer value to display, valid range -999...9999 + */ + void writeInt( int value ); + +protected: + void init( void ); + + I2C *i2c; //I2C bus reference + uint8_t slaveAddress; //I2C Slave address of device + uint8_t data[6]; +}; + +#endif \ No newline at end of file
--- a/SAA1064/SAA1064.cpp Mon Apr 20 07:34:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* SAA1064 4 Digit Library - * Copyright (c) 2015 Marcel (mc-b) Bernet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mbed.h" -#include "SAA1064.h" - -SAA1064::SAA1064( PinName sda, PinName scl, uint8_t deviceAddress ) -{ - i2c = new I2C( sda, scl ); - slaveAddress = deviceAddress; - init(); -} - - -SAA1064::SAA1064( I2C *i2c, uint8_t deviceAddress ) -{ - this->i2c = i2c; - slaveAddress = deviceAddress; - init(); -} - -/** Write digits -* -* @param digit1 LED segment pattern for digit1 (MSB) -* @param digit2 LED segment pattern for digit2 -* @param digit3 LED segment pattern for digit3 -* @param digit4 LED segment pattern for digit4 (LSB) -*/ -void SAA1064::write( uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4 ) -{ - digit1 = SAA1064_SEGM[digit1]; - digit2 = SAA1064_SEGM[digit2]; - digit3 = SAA1064_SEGM[digit3]; - digit4 = SAA1064_SEGM[digit4]; - - data[0] = 1; - data[1] = ((digit4<<4) & 0xF0) | (digit2 & 0x0F); - data[2] = ((digit3<<4) & 0xF0) | (digit1 & 0x0F); - data[3] = ((digit2>>4) & 0x0F) | (digit4 & 0xF0); - data[4] = ((digit1>>4) & 0x0F) | (digit3 & 0xF0); - i2c->write( slaveAddress, (char*) data, 5 ); -} - -/** Write Integer -* -* @param value integer value to display, valid range -999...9999 -*/ -void SAA1064::writeInt( int value ) -{ - write( value / 1000, (value % 1000) / 100, (value % 100) / 10, value % 10 ); -} - -/** Init I2C bus -*/ -void SAA1064::init( void ) -{ - // init - data[0] = 0x00; - data[1] = 0x47; - i2c->write( slaveAddress, (char*) data, 2 ); - - // blank display - data[0] = 1; - data[1] = 0; - data[2] = 0; - data[3] = 0; - data[4] = 0; - i2c->write( slaveAddress, (char*) data, 5 ); -} \ No newline at end of file
--- a/SAA1064/SAA1064.h Mon Apr 20 07:34:35 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* SAA1064 4 Digit Library - * Copyright (c) 2015 Marcel (mc-b) Bernet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef _SAA1064_H -#define _SAA1064_H - -//Address Defines for SAA1064 -#define SAA1064_SA0 0x70 -#define SAA1064_SA1 0x72 -#define SAA1064_SA2 0x74 -#define SAA1064_SA3 0x76 - -//Defines for Segments -const uint8_t SAA1064_SEGM[] = {0xE7, //0 - 0x84, //1 - 0xD3, //2 - 0xD6, //3 - 0xB4, //4 - 0x76, //5 - 0x77, //6 - 0xC4, //7 - 0xF7, //8 - 0xF6, //9 - 0xF5, //A - 0x37, //B - 0x13, //C - 0x97, //D - 0x73, //E - 0x71 - }; //F - -/** Create an SAA1064 object connected to the specified I2C bus and deviceAddress -*/ -class SAA1064 -{ -public: - - /** Create a SAA1064 LED displaydriver object using a specified I2C bus and slaveaddress - * - * @param sda Pin - * @param scl Pin - * @param char deviceAddress the address of the SAA1064 - */ - SAA1064( PinName sda = D14, PinName scl = D15, uint8_t deviceAddress = SAA1064_SA0 ); - - SAA1064( I2C* i2c, uint8_t deviceAddress = SAA1064_SA0 ); - - /** Write digits - * - * @param digit1 LED segment pattern for digit1 (MSB) - * @param digit2 LED segment pattern for digit2 - * @param digit3 LED segment pattern for digit3 - * @param digit4 LED segment pattern for digit4 (LSB) - */ - void write(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4); - - /** Write Integer - * - * @param value integer value to display, valid range -999...9999 - */ - void writeInt( int value ); - -protected: - void init( void ); - - I2C *i2c; //I2C bus reference - uint8_t slaveAddress; //I2C Slave address of device - uint8_t data[6]; -}; - -#endif \ No newline at end of file