Echelon Mini FX User Manual
Page 95

82 Developing
Device
Applications
//
when(timer_expires(buttonTimer)) {
static boolean previousButton = TRUE;
boolean currentButton;
currentButton = GetButton();
if (currentButton && !previousButton) {
OnButtonPressed();
}
previousButton = currentButton;
}
#else
#ifdef USE_5000EVB
IO_9 input bit ioSwitch1;
//
// when(io_changes…) executes whenever the switch
//
when(io_changes(ioSwitch1) to 0)
{
OnButtonPressed();
}
#endif // 5000 evb
#endif // mini gizmo
//
// Driver to support a 1-Wire Dallas DS18S20 digital thermometer device.
// This implementation uses a simplified protocol, skipping the
// search ROM step, because the boards provide only one 1-Wire device.
// The same code works for both FT 5000 EVB and Mini Gizmo I/O boards.
//
// 1-Wire is a registered trademark of Dallas Semiconductor.
// You can find out more about this device on www.maxim-ic.com
//
IO_7 touch ioTemperatureSensor;
#define DS18S20_SKIP_ROM 0xCCu
#define DS18S20_CONVERT 0x44u
#define DS18S20_READ 0xBEu
SNVT_temp_p GetTemperature(void)
{
union {
SNVT_temp_p value;
unsigned raw[2];
} current;
current.value = 32767l;
if (touch_reset(ioTemperatureSensor)) {
(void)touch_byte(ioTemperatureSensor, DS18S20_SKIP_ROM);
(void)touch_byte(ioTemperatureSensor, DS18S20_READ);
// read data into big-endian variable
current.raw[1] = (unsigned)touch_byte(ioTemperatureSensor, 0xFFu);
current.raw[0] = (unsigned)touch_byte(ioTemperatureSensor, 0xFFu);
if (touch_reset(ioTemperatureSensor)) {
// The value currently held in 'current' is the raw DS18S20
// data, in Celsius, at a resolution of 0.5 degrees.
// SNVT_temp_p, however, provides a resolution of 0.01 in
// a fixed-point implementation.
// Correct the raw reading by factor 50 thus:
current.value *= 50ul;
// Start the next conversion cycle:
(void) touch_byte(ioTemperatureSensor, DS18S20_SKIP_ROM);
(void) touch_byte(ioTemperatureSensor, DS18S20_CONVERT);