From 835bc100b5f20c80c542660d2ab57fea19aa4dd6 Mon Sep 17 00:00:00 2001 From: mlalondesvn Date: Thu, 18 Oct 2007 01:02:04 +0000 Subject: [PATCH] DS1803: MODIF - Address definition to easily allow choosing the 3 address bit MODIF - DPOT_* definitions to DS1803_* twiLCD: MODIF - Address definition to easily allow choosing the 3 address bit git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@6 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b --- ds1803/ds1803.cpp | 8 ++++---- ds1803/ds1803.h | 27 ++++++++++++++++++--------- twiLCD/twiLCD.h | 11 ++++++++++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ds1803/ds1803.cpp b/ds1803/ds1803.cpp index a09c5ef..6e51d9e 100644 --- a/ds1803/ds1803.cpp +++ b/ds1803/ds1803.cpp @@ -21,9 +21,9 @@ DS1803 DPOT = DS1803(); void DS1803::setWiper(uint8_t value, uint8_t wiperAddr) { - if (!Wire.checkAddress(DPOT_WADDR)) return; + if (!Wire.checkAddress(DS1803_WADDR)) return; - Wire.beginTransmission(DPOT_WADDR); + Wire.beginTransmission(DS1803_WADDR); Wire.send(wiperAddr); // Send the wiper address Wire.send(value); @@ -33,9 +33,9 @@ void DS1803::setWiper(uint8_t value, uint8_t wiperAddr) /* uint8_t DS1803::getValue() { - if (!Wire.checkAddress(DPOT_WADDR)) return; + if (!Wire.checkAddress(DS1803_WADDR)) return; - Wire.requestFrom(DPOT_RADDR, 2); + Wire.requestFrom(DS1803_RADDR, 2); while (Wire.available()) { Serial.println((uint8_t)Wire.receive(), DEC); diff --git a/ds1803/ds1803.h b/ds1803/ds1803.h index e0856dd..e15c791 100644 --- a/ds1803/ds1803.h +++ b/ds1803/ds1803.h @@ -3,27 +3,36 @@ #include -#define DPOT_WADDR 0x28 -#define DPOT_RADDR DPOT_WADDR | 0x01 +/** + * Address byte selection + * Select 0 for low and 1 for high +**/ +#define DS1803_A0 0 +#define DS1803_A1 0 +#define DS1803_A2 0 + +#define DS1803_BASE_ADDR B00101000 +#define DS1803_WADDR DS1803_BASE_ADDR | (DS1803_A0 * B00000001) | (DS1803_A1 * B00000010) | (DS1803_A2 * B00000100) +#define DS1803_RADDR DS1803_WADDR | 0x01 /** * The number of available potentiometer wipers **/ -#define DPOT_NBR_WIPERS 0x02 +#define DS1803_NBR_WIPERS 0x02 /** * Digital pot selection commands **/ -#define DPOT_WIPERS B10101111 -#define DPOT_WIPER_0 B10101001 -#define DPOT_WIPER_1 B10101010 +#define DS1803_WIPERS B10101111 +#define DS1803_WIPER_0 B10101001 +#define DS1803_WIPER_1 B10101010 /** * Macros **/ -#define setWiper1(value) setWiper(value, DPOT_WIPER_0) -#define setWiper2(value) setWiper(value, DPOT_WIPER_1) -#define setWipers(value) setWiper(value, DPOT_WIPERS) +#define setWiper1(value) setWiper(value, DS1803_WIPER_0) +#define setWiper2(value) setWiper(value, DS1803_WIPER_1) +#define setWipers(value) setWiper(value, DS1803_WIPERS) /** * DS1803 I2C Dual Digital Pot. diff --git a/twiLCD/twiLCD.h b/twiLCD/twiLCD.h index 7300ade..51990d4 100644 --- a/twiLCD/twiLCD.h +++ b/twiLCD/twiLCD.h @@ -5,7 +5,16 @@ #include "../configs/LCD/lcd.h" #include "twiLCDConfig.h" - #define PCF8574_WADDR 0x20 + /** + * Address byte selection + * Select 0 for low and 1 for high + **/ + #define PCF8574_A0 0 + #define PCF8574_A1 0 + #define PCF8574_A2 0 + + #define PCF8574_BASE_ADDR B00100000 + #define PCF8574_WADDR PCF8574_BASE_ADDR | (PCF8574_A0 * B00000001) | (PCF8574_A1 * B00000010) | (PCF8574_A2 * B00000100) #define PCF8574_RADDR PCF8574_WADDR | 0x01 #define TWI_LCD_RS 0 /* RS pin */