Beispiel #1
0
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_read_time(void)  
{ 

	time_buf[1]=ds1302_read_byte(ds1302_year_add);		//年 
	time_buf[2]=ds1302_read_byte(ds1302_month_add);		//月 
	time_buf[3]=ds1302_read_byte(ds1302_date_add);		//日 
	time_buf[4]=ds1302_read_byte(ds1302_hr_add);		//时 
	time_buf[5]=ds1302_read_byte(ds1302_min_add);		//分 
	time_buf[6]=(ds1302_read_byte(ds1302_sec_add))&0x7F;//秒 
	time_buf[7]=ds1302_read_byte(ds1302_day_add);		//周 
}