hatanet
Joined: 08 Sep 2003 Posts: 9 Location: South Africa
|
DS1629.C |
Posted: Mon Oct 06, 2003 7:24 am |
|
|
This is a baseline program I used to initialize, set & get DateTime & Alarms for the Dallas 1629 chip. The Date & Time are hard coded for demonstration purposes....
Goodluck still... after so long.
typedef struct {
int year;
int month; // 1-12 months
int date; // 1-31 day
int weekday; // 1=Sunday, 7=Saturday
int hours; // 24 hour mode
int minutes; // 0-59 mins
int seconds; // 0-59 secs
} DATE_TIME;
// I2C constants for selecting this device
#define I2C_SELECT_DS1629_READ 0x9F // 1001 1111
#define I2C_SELECT_DS1629_WRITE 0x9E // 1001 1110
void init_ds1629(void) {
output_high(I2C_SDA);
output_high(I2C_SCL);
// Set configuration register
i2c_start();
i2c_write(I2C_SELECT_DS1629_WRITE); // Select the ACCESS CONFIG register
i2c_write(0xAC); // continuous conversion mode, alarms off,
i2c_write(0x00); // disable oscillator output
i2c_stop();
// Start conversions
i2c_start();
i2c_write(I2C_SELECT_DS1629_WRITE);
i2c_write(0xEE);
i2c_stop();
}
// range -55'C to 125'C
float read_temp(void) {
signed int datah;
int datal;
float data;
i2c_start();
i2c_write(I2C_SELECT_DS1629_WRITE);
i2c_write(0xAA); // Read temperature
i2c_start();
i2c_write(I2C_SELECT_DS1629_READ);
datah = i2c_read(); // Receive and ACK
datal = i2c_read(0); // Receive and NACK
i2c_stop();
data = (float) datah;
if((datal&0x80)!=0) {
data += 0.5;
}
return(data);
}
// DS1629 Time & Temperature settings
void DS1629_set_dt(void)
{
// Time
i2c_start(); // initiate master start condition.
i2c_write(I2C_SELECT_DS1629_WRITE); // sends DS1629 address.
i2c_write(0xC0); // sends access clock potocol.
i2c_write(0x00); // sends access clock protocol.
i2c_write(0); // sets seconds & enables clock.
i2c_write(30); // sets clock minutes.
i2c_write(0x51); // sets clock hours and AM/PM clock mode.
i2c_write(2); // sets day of the week.
i2c_write(12); // sets date of the month.
i2c_write(11); // sets month of the year.
i2c_write(02); // sets the year.
// Temperature
i2c_start(); // initiate master start condition.
i2c_write(I2C_SELECT_DS1629_WRITE); // sends DS1629 address.
i2c_write(0xA1); // sends access TH protocol
i2c_write(0x32); // writes MSB of TH protocol (50 degrees C)
i2c_write(0x00); // writes LSB of TH protocol (50 degrees C)
i2c_stop(); // initiate master stop condition.
} |
|