-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds1307.c
52 lines (49 loc) · 972 Bytes
/
ds1307.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* ds1307.c
*
* Created: 01-10-2018 00:13:52
* Author: soham
*/
#include <avr/io.h>
#include "ds1307.h"
#include "i2c.h"
void rtc_set(data *a)
{
i2c_init();
i2c_start();
i2c_write(0xd0); //address of slave
i2c_write(0x00); //int address of sec (starting)
i2c_write(a->sec);
i2c_write(a->min);
i2c_write(a->hr);
i2c_write(a->day);
i2c_write(a->date);
i2c_write(a->month);
i2c_write(a->yr);
i2c_stop();
}
void rtc_get(data *b)
{
i2c_init();
i2c_start();
i2c_write(0xd0); //address of master (actually slave)
i2c_write(0x00); //int address starting
i2c_start();
i2c_write(0xd1); //adress of master with read byte 1
b->sec=i2c_read(1);
b->min=i2c_read(1);
b->hr=i2c_read(1);
b->day=i2c_read(1);
b->date=i2c_read(1);
b->month=i2c_read(1);
b->yr=i2c_read(0);
i2c_stop();
}
unsigned char conv(unsigned char dat)
{
unsigned char a,b;
a=dat&0x0f;
b=a;
a=dat&0x70;
b=(10*a)+b;
}