コード例 #1
0
void mcp79410_set(struct mcp79410_time_t *time) {
	// see the note in section 5.3 about how to set the timekeeping registers without rollover issues
	uint8_t data[7];

	// disable the crystal input (ST = 0)
	data[0] = 0x00;								// seconds register
	data[1] = 0x00;								// ST = 0
	twi_write_to(0x6f, data, 2, TWI_BLOCK, TWI_STOP);

	// wait for the oscilator to stop (OSCRUN == 0)
	data[0] = 0x03;
	data[1] = 0x20;
	while (data[1] & 0x20) {
		twi_read_from(0x6f, data, 2, TWI_STOP);
	}
	
	// set the time fields
	data[0] = 0x01;								// minutes register
	data[1] = hex2bcd(time->minute);
	data[2] = hex2bcd(time->hour);
	data[3] = hex2bcd(time->wday) | 0x08,		// enable battery (VBATEN = 1) 
	data[4] = hex2bcd(time->mday),
	data[5] = hex2bcd(time->month),				// bit 5 is LPYR
	data[6] = hex2bcd(time->year - 2000);
	twi_write_to(0x6f, data, 7, TWI_BLOCK, TWI_STOP);
	
	// set the seconds field and enable the crystal input (ST = 1)
	data[0] = 0x00;								// seconds register
	data[1] = hex2bcd(time->second) | 0x80;
	twi_write_to(0x6f, data, 2, TWI_BLOCK, TWI_STOP);
}
コード例 #2
0
void ds1307_set(struct ds1307_time_t *time) {
	uint8_t data[8] = { 
		0x00,
		hex2bcd(time->second),
		hex2bcd(time->minute),
		hex2bcd(time->hour),
		hex2bcd(time->wday),
		hex2bcd(time->mday),
		hex2bcd(time->month),
		hex2bcd(time->year - 2000)
	};
	twi_write_to(0x68, data, 8, TWI_BLOCK, TWI_STOP);
}
コード例 #3
0
ファイル: main.c プロジェクト: pe1jpd/23cm
void displayFrequency(long int f)
{
	int i;
	char c;

	hex2bcd(f);

	lcdCursor(4,0);

	for (i=1; i<8; i++) {
		c = str[i];
		if (i==5) {
			lcdChar('.');
		}
		lcdChar(c);
	}
}
コード例 #4
0
ファイル: 23nbfm21.c プロジェクト: realrolfje/23CM-TRX
void display(long int f)
{
	int i;
	char c;

	hex2bcd(f);

	lcdCmd(0x80 + 4);
	_delay_us(200);

	for (i=1; i<8; i++) {
		c = str[i];
		if (i==5) {
			lcdData('.');
		}
		lcdData(c);
	}
}
コード例 #5
0
ファイル: smu.c プロジェクト: Dronevery/JetsonTK1-kernel
static inline void smu_fill_set_rtc_cmd(struct smu_cmd_buf *cmd_buf,
					struct rtc_time *time)
{
	cmd_buf->cmd = 0x8e;
	cmd_buf->length = 8;
	cmd_buf->data[0] = 0x80;
	cmd_buf->data[1] = hex2bcd(time->tm_sec);
	cmd_buf->data[2] = hex2bcd(time->tm_min);
	cmd_buf->data[3] = hex2bcd(time->tm_hour);
	cmd_buf->data[4] = time->tm_wday;
	cmd_buf->data[5] = hex2bcd(time->tm_mday);
	cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
	cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
}