From: johanknol Date: Thu, 19 Oct 2000 21:00:42 +0000 (+0000) Subject: upgrade ds1621 to report fp temp's X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=991022f035ead55981e141b6e39f84d6318cdaa9;p=fw%2Fsdcc upgrade ds1621 to report fp temp's git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@477 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/device/examples/ds390/i2c390/Makefile b/device/examples/ds390/i2c390/Makefile index 7e408d54..957e890d 100644 --- a/device/examples/ds390/i2c390/Makefile +++ b/device/examples/ds390/i2c390/Makefile @@ -1,15 +1,15 @@ CC = sdcc MFLAGS = -mds390 --model-flat24 --stack-10bit -LFLAGS = --xram-loc 0x180000 --code-loc 0x10000 -Wl-r - -OBJECTS = i2c390.rel i2clole.rel ds1621.rel pcf8591.rel +LFLAGS = --xram-loc 0x100080 --code-loc 0x10000 -Wl-r all: i2c390.hex clean: rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk +OBJECTS = i2c390.rel i2clole.rel ds1621.rel pcf8591.rel + i2c390.hex: i2c390.ihx packihx i2c390.ihx >i2c390.hex @@ -17,4 +17,4 @@ i2c390.ihx: $(OBJECTS) $(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS) %.rel: %.c - $(CC) -c $(MFLAGS) $< + $(CC) -c $(MFLAGS) -I../float390 $< diff --git a/device/examples/ds390/i2c390/ds1621.c b/device/examples/ds390/i2c390/ds1621.c index fd99ef7b..f91ac5ff 100644 --- a/device/examples/ds390/i2c390/ds1621.c +++ b/device/examples/ds390/i2c390/ds1621.c @@ -1,17 +1,12 @@ #include "i2clole.h" #include "ds1621.h" -#if USE_FLOAT // defined in ds1621.h -static float temperature -signed char counter, slope; -float -#else -#include -static char temperature[10]; -char * -#endif -ReadDS1621(char address) { + +float ReadDS1621(char address) { + float temperature; + signed char counter, slope; + int id=DS1621_ID + (address<<1); while (!I2CReset()) { @@ -30,18 +25,8 @@ ReadDS1621(char address) { if (I2CSendReceive(id, 1, 1)) return -999; } while ((i2cReceiveBuffer[0]&0x80)==0); // wait for conversion done - - // if we did not do this, sdcc thinks i2cReceiveBuffer[0] is still in r3 - i2cReceiveBuffer[0]=0; - i2cTransmitBuffer[0]=0xaa; // read temperature command -#if !USE_FLOAT - if (I2CSendReceive(id, 1, 2)) return -999; - sprintf (temperature, "% 3bd.%c", i2cReceiveBuffer[0], - i2cReceiveBuffer[1]?'5':'0'); - return temperature; -#else if (I2CSendReceive(id, 1, 1)) return -999; temperature=i2cReceiveBuffer[0]; i2cTransmitBuffer[0]=0xa8; // read counter command @@ -51,10 +36,8 @@ ReadDS1621(char address) { i2cTransmitBuffer[0]=0xa9; // read slope command if (I2CSendReceive(id, 1, 1)) return -999; slope=i2cReceiveBuffer[0]; - - temperature=(int)temperature - 0.25 + + + temperature=temperature - 0.25 + ((float)slope-(float)counter)/(float)slope; - return temperature; -#endif -} - + return temperature; +} diff --git a/device/examples/ds390/i2c390/ds1621.h b/device/examples/ds390/i2c390/ds1621.h index 9f782c03..2114c65d 100644 --- a/device/examples/ds390/i2c390/ds1621.h +++ b/device/examples/ds390/i2c390/ds1621.h @@ -1,12 +1,3 @@ #define DS1621_ID 0x90 -// we have no decent float support in sdcc yet -#define USE_FLOAT 0 - -#if USE_FLOAT -extern float -#else -extern char * -#endif - -ReadDS1621(char address); +extern float ReadDS1621(char address); diff --git a/device/examples/ds390/i2c390/i2c390.c b/device/examples/ds390/i2c390/i2c390.c index 0b6de2d6..c034a6e7 100644 --- a/device/examples/ds390/i2c390/i2c390.c +++ b/device/examples/ds390/i2c390/i2c390.c @@ -24,7 +24,7 @@ void main (void) { while(1) { - printf ("%s %03bu %03bu %03bu %03bu\n\r", + printf ("% 5.2f %03bu %03bu %03bu %03bu\n\r", ReadDS1621(2), ReadPCF8591(0,0), ReadPCF8591(0,1), diff --git a/device/examples/ds390/i2c390/pcf8591.c b/device/examples/ds390/i2c390/pcf8591.c index 7b1352cf..4d86e8e7 100644 --- a/device/examples/ds390/i2c390/pcf8591.c +++ b/device/examples/ds390/i2c390/pcf8591.c @@ -1,16 +1,21 @@ #include "i2clole.h" #include "pcf8591.h" +#if 0 || FIND_OPERATOR_PRECEDING_INCONSISTANCY +#undef PCF8591_ID +#define PCF8591_ID 0x90; +#endif + unsigned char ReadPCF8591(char address, char channel) { - unsigned char id=PCF8591_ID + address<<1; + unsigned char id=PCF8591_ID+address<<1; while (!I2CReset()) { //fprintf (stderr, "I2C bus busy, retrying.\n"); } - i2cTransmitBuffer[0]=channel&0x03 + 0x40; //output enable, not autoincrement - //i2cTransmitBuffer[1]=0; // dac output + // set output enable, no autoincrement + i2cTransmitBuffer[0]=channel&0x03+0x40; // read 2 bytes, since the first one is the old value if (I2CSendReceive(id, 1, 2))