///////////////////////////////////////////////////////////////////////////
//// Library for a Dallas 1624 Temperature and memory chip ////
//// ////
//// init_ds1624() Call before any other functions are called ////
//// ////
//// init_temp(); Call before the read temp function is used////
//// ////
//// f = read_temp(); Read the temerature in ºC ////
//// ////
//// write_ds1624_eeprom(int address,int val) writes val to eeprom ////
//// ////
//// dat=read_ds1624_eeprom(int address) reads from the address ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#ifndef DAL_SCL
#define DAL_SCL PIN_C3
#define DAL_SDA PIN_C4
#endif
#use i2c(master, sda=DAL_SDA, scl=DAL_SCL)
void temp_config()
{
i2c_start();
i2c_write(0x90);
i2c_write(0xac);
i2c_write(0x01);
i2c_stop();
}
void init_ds1624()
{
output_high(DAL_SDA);
output_high(DAL_SCL);
}
void init_temp() {
temp_config();
delay_ms(50);
i2c_start();
i2c_write(0x90);
i2c_write(0xee);
i2c_stop();
}
float read_temp() ////// Returns in ºC
{
int datah,datal;
float dval;
i2c_start();
i2c_write(0x90);
i2c_write(0xaa);
i2c_start();
i2c_write(0x91);
datah=i2c_read();
datal=i2c_read(0);
i2c_stop();
dval=datah + .03125*(datal>>3);
return(dval);
}
int read_ds1624_eeprom(int address)
{
int data;
i2c_start();
i2c_write(0x90);
i2c_write(0x17);
i2c_write(address);
i2c_start();
i2c_write(0x91);
data=i2c_read();
i2c_stop();
return data;
}
void write_ds1624_eeprom(int address, int data)
{
i2c_start();
i2c_write(0x90);
i2c_write(0x17);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(50);
}