Echelon Mini EVK User Manual

Page 52

Advertising
background image


#pragma enable_io_pullups
#pragma num_alias_table_entries 2
#pragma run_unconfigured

// Configure the I/O pins
IO_7 touch ioThermometer;
IO_10 output serial baud (4800) ioSerialOut;

#define DS18S20_SKIP_ROM 0xCCu
#define DS18S20_CONVERT 0x44u
#define DS18S20_READ 0xBEu

// Get a temperature reading from the Touch temperature sensor
SNVT_temp_p GetTemperature(void) {
union {
SNVT_temp_p snvtTempP;
unsigned Bytes[2];
} CurrentTemperature;
CurrentTemperature.snvtTempP = 32767l;

if (touch_reset(ioThermometer)) {
(void) touch_byte(ioThermometer, DS18S20_SKIP_ROM);
(void) touch_byte(ioThermometer, DS18S20_READ);

CurrentTemperature.Bytes[1]
= touch_byte(ioThermometer, 0xFFu);
CurrentTemperature.Bytes[0]
= touch_byte(ioThermometer, 0xFFu);

if (touch_reset(ioThermometer)) {
// Scale the raw reading
CurrentTemperature.snvtTempP *= 50l;

// start the next conversion cycle:
(void) touch_byte(ioThermometer, DS18S20_SKIP_ROM);
(void) touch_byte(ioThermometer, DS18S20_CONVERT);
} else {
CurrentTemperature.snvtTempP = 32767l;
}
}
return CurrentTemperature.snvtTempP;
}

// Send a string to the serial port
const char errorString[] = "String too long.";

void PrintConsole(const char *message) {
if (strlen(message) <= 100) {
io_out(ioSerialOut, message, (unsigned) strlen(message));
} else {
io_out(ioSerialOut, errorString, (unsigned)
strlen(errorString));
}
}

// Repeat every second
mtimer repeating readTimer = 1000;

// Read the temperature when the timer expires
when(timer_expires(readTimer)) {
s32_type s32_temperature;
SNVT_temp_p temperature;

46

Mini EVK User’s Guide

Advertising