static int16 ds1302_read_temp(void) { uint8 temp_data[2]; // ¶Á³öζÈÔÝ·Å int16 temp; ds1302_reset(); ds1302_write_byte(0xCC); // Skip ROM cmd ds1302_write_byte(0xBE); // read temp_data[0] = ds1302_read_byte(); // low 8 bits temp_data[1] = ds1302_read_byte(); // high 8 bits temp = temp_data[1]; temp <<= 8; temp |= temp_data[0]; temp >>= 4; return temp; }
void ds1302_write_time(void) { ds1302_write_byte(ds1302_control_add,0x00); //关闭写保护 ds1302_write_byte(ds1302_sec_add,0x80); //暂停 //ds1302_write_byte(ds1302_charger_add,0xa9); //涓流充电 ds1302_write_byte(ds1302_year_add,time_buf[1]); //年 ds1302_write_byte(ds1302_month_add,time_buf[2]); //月 ds1302_write_byte(ds1302_date_add,time_buf[3]); //日 ds1302_write_byte(ds1302_day_add,time_buf[7]); //周 ds1302_write_byte(ds1302_hr_add,time_buf[4]); //时 ds1302_write_byte(ds1302_min_add,time_buf[5]); //分 ds1302_write_byte(ds1302_sec_add,time_buf[6]); //秒 ds1302_write_byte(ds1302_day_add,time_buf[7]); //周 ds1302_write_byte(ds1302_control_add,0x80); //打开写保护 }
static void ds1302_start(void) { ds1302_reset(); ds1302_write_byte(0xCC); // Skip ROM cmd ds1302_write_byte(0x44); // convert cmd }