git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@477
4a8a32a2-be11-0410-ad9d-
d568d2c75423
CC = sdcc
MFLAGS = -mds390 --model-flat24 --stack-10bit
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
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
i2c390.hex: i2c390.ihx
packihx i2c390.ihx >i2c390.hex
$(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS)
%.rel: %.c
$(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS)
%.rel: %.c
+ $(CC) -c $(MFLAGS) -I../float390 $<
#include "i2clole.h"
#include "ds1621.h"
#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()) {
int id=DS1621_ID + (address<<1);
while (!I2CReset()) {
if (I2CSendReceive(id, 1, 1)) return -999;
} while ((i2cReceiveBuffer[0]&0x80)==0); // wait for conversion done
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
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
if (I2CSendReceive(id, 1, 1)) return -999;
temperature=i2cReceiveBuffer[0];
i2cTransmitBuffer[0]=0xa8; // read counter command
i2cTransmitBuffer[0]=0xa9; // read slope command
if (I2CSendReceive(id, 1, 1)) return -999;
slope=i2cReceiveBuffer[0];
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;
((float)slope-(float)counter)/(float)slope;
- return temperature;
-#endif
-}
-
-// 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);
void main (void) {
while(1) {
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),
ReadDS1621(2),
ReadPCF8591(0,0),
ReadPCF8591(0,1),
#include "i2clole.h"
#include "pcf8591.h"
#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 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");
}
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))
// read 2 bytes, since the first one is the old value
if (I2CSendReceive(id, 1, 2))