-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2c_byte_frames_rtc.c
83 lines (71 loc) · 1.12 KB
/
i2c_byte_frames_rtc.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//i2c byte frame
#include"header.h"
#include<reg51.h>
void i2c_byte_write_frame(u8 sa,u8 ma,u8 d)
{
//bit res;
i2c_start();
i2c_write(sa);//sa(7bit) with write(1bit) option
//res=
i2c_ack();
/* if(res==1)
{
//uart_string("sa+w error in write\n");
goto out;
}*/
i2c_write(ma);//write 8 bit ma
//res=
i2c_ack();
/*if(res==1)
{
//uart_string("ma+w error in write\n");
goto out;
}*/
i2c_write(d);//write 8 bit data
//res=
i2c_ack();
/*if(res==1)
{
//uart_string("d+w error in write\n");
goto out;
}
out:*/
i2c_stop();
}
u8 i2c_byte_read_frame(u8 sa,u8 ma)
{
//bit res;
u8 temp;
i2c_start();
i2c_write(sa);//sa with write option
//res=
i2c_ack();
/*if(res==1)
{
//uart_string("sa+w write error in read\n");
goto out;
}*/
i2c_write(ma);//ma with write option
//res=
i2c_ack();
/*if(res==1)
{
//uart_string("ma+w write error in read\n");
goto out;
}*/
//i2c_restart();
i2c_start();
i2c_write(sa|1);
//res=
i2c_ack();
/*if(res==1)
{
//uart_string("sa+r write error in read\n");
goto out;
}*/
temp=i2c_read();
i2c_no_ack();
//out:
i2c_stop();
return temp;
}