upgrade ds1621 to report fp temp's
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 19 Oct 2000 21:00:42 +0000 (21:00 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 19 Oct 2000 21:00:42 +0000 (21:00 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@477 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/examples/ds390/i2c390/Makefile
device/examples/ds390/i2c390/ds1621.c
device/examples/ds390/i2c390/ds1621.h
device/examples/ds390/i2c390/i2c390.c
device/examples/ds390/i2c390/pcf8591.c

index 7e408d54ddb7bcc2c67cbc9b3ea1e9414aa910de..957e890dfdfbd16dafca461229b96a5d39fe738f 100644 (file)
@@ -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 $<
index fd99ef7b1ee1f4ee445755aec554046a9d904623..f91ac5ffc54fb6f690535bdae3ece5d722bb0c7f 100644 (file)
@@ -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 <stdio.h>
-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;
+}  
index 9f782c03c93332d810afc2df6663753dd81019b0..2114c65d0d8f283332a30251539e40d04be85156 100644 (file)
@@ -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);
index 0b6de2d69d19f59162e21387e23b8ab972775c4a..c034a6e7d145ae2119c73dbcb4acebad802e0e36 100644 (file)
@@ -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), 
index 7b1352cfa5099a1bfbd2060f10197fc94434efe6..4d86e8e7cb63ffc37da034628b665af59a43d51c 100644 (file)
@@ -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))