📄 i2c.lst
字号:
C51 COMPILER V7.07 I2C 08/22/2008 23:25:43 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN i2c.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE i2c.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //i2c.c
2
3 #include "i2c.h"
4 #include <reg52.h>
5 #include <intrins.h>
6 #include "global.h"
7
8 /*
9 unsigned char i2c_EP_ok(void)
10 {
11 unsigned char tmp;
12 i2c_EP_start();
13 i2c_EP_send(EEPROM_rd);
14 tmp = i2c_EP_receive_Ack();
15 i2c_EP_end();
16 return tmp;
17 }
18 */
19 void i2c_EP_start(void)
20 {
21 1 i2c_EP_SCL_1;
22 1 delay_us(10);
23 1 i2c_EP_DA_1;
24 1 delay_us(10);
25 1 i2c_EP_DA_0;
26 1 delay_us(10);
27 1 i2c_EP_SCL_0;
28 1 delay_us(10);
29 1 }
30
31 unsigned char i2c_EP_receive_Ack(void)
32 {
33 1 unsigned char tmp;
34 1
35 1 i2c_EP_SCL_1;
36 1 tmp = 0;
37 1 _nop_();
38 1 while ((i2c_EP_DA_receive)&&(tmp<255))
39 1 {
40 2 tmp++;
41 2 }
42 1 i2c_EP_SCL_0;
43 1
44 1 if (tmp == 255)
45 1 return FALSE;
46 1 else return TRUE;
47 1 }
48 /*
49 void i2c_EP_send_Ack(void)
50 {
51 i2c_EP_SCL_0;
52 i2c_EP_DA_0;
53 i2c_EP_SCL_1;
54 _nop_();
55 _nop_();
C51 COMPILER V7.07 I2C 08/22/2008 23:25:43 PAGE 2
56 i2c_EP_SCL_0;
57
58 }
59 */
60 void i2c_EP_send(unsigned char ddd)
61 {
62 1 unsigned char tmp,i,da;
63 1
64 1 tmp = 0x80;
65 1 da = ddd;
66 1
67 1 for (i = 0; i < 8; i++)
68 1 {
69 2 i2c_EP_SCL_0;
70 2 delay_us(10);
71 2
72 2 if ( da & tmp )
73 2 i2c_EP_DA_1;
74 2 else i2c_EP_DA_0;
75 2
76 2 delay_us(10);
77 2
78 2 i2c_EP_SCL_1;
79 2 delay_us(10);
80 2
81 2 i2c_EP_SCL_0;
82 2 da =(da<<1);
83 2 }
84 1 delay_us(10);
85 1 i2c_EP_DA_1;
86 1 delay_us(10);
87 1
88 1 }
89
90 unsigned char i2c_EP_receive(void)
91 {
92 1 unsigned char tmp,i;
93 1
94 1 tmp = 0;
95 1
96 1 for (i = 0; i < 8; i++)
97 1 {
98 2 i2c_EP_SCL_0;
99 2 delay_us(10);
100 2 i2c_EP_DA_1;
101 2 delay_us(10);
102 2
103 2 i2c_EP_SCL_1;
104 2 delay_us(10);
105 2
106 2
107 2 if ( i2c_EP_DA_receive )
108 2 tmp++;
109 2
110 2 delay_us(10);
111 2
112 2 i2c_EP_SCL_0;
113 2 if (i != 7)
114 2 tmp <<= 1;
115 2 }
116 1 return tmp;
117 1 }
C51 COMPILER V7.07 I2C 08/22/2008 23:25:43 PAGE 3
118
119
120 void i2c_EP_end()
121 {
122 1 i2c_EP_SCL_0;
123 1 i2c_EP_DA_0;
124 1 delay_us(10);
125 1 i2c_EP_SCL_1;
126 1 delay_us(10);
127 1 i2c_EP_DA_1;
128 1 }
129
130
131 unsigned char EEPROM_write(unsigned char uiAddress, unsigned char ucData)
132 {
133 1 stopInterupt();
134 1
135 1 i2c_EP_start();
136 1
137 1 i2c_EP_send(EEPROM_wr);
138 1
139 1 if (!i2c_EP_receive_Ack())
140 1 return FALSE;
141 1
142 1 i2c_EP_send(uiAddress);
143 1
144 1 if (!i2c_EP_receive_Ack())
145 1 return FALSE;
146 1
147 1 i2c_EP_send(ucData);
148 1
149 1 if (!i2c_EP_receive_Ack())
150 1 return FALSE;
151 1
152 1 i2c_EP_end();
153 1
154 1 delay_us(50);
155 1
156 1 startInterupt();
157 1
158 1 }
159
160
161 unsigned char EEPROM_read(unsigned char uiAddress)
162 {
163 1 unsigned char tmp;
164 1
165 1 stopInterupt();
166 1
167 1 i2c_EP_start();
168 1
169 1 i2c_EP_send(EEPROM_wr);
170 1
171 1 if (!i2c_EP_receive_Ack())
172 1 return FALSE;
173 1
174 1 i2c_EP_send(uiAddress);
175 1
176 1 if (!i2c_EP_receive_Ack())
177 1 return FALSE;
178 1
179 1
C51 COMPILER V7.07 I2C 08/22/2008 23:25:43 PAGE 4
180 1 i2c_EP_start();
181 1
182 1 i2c_EP_send(EEPROM_rd);
183 1
184 1 if (!i2c_EP_receive_Ack())
185 1 return FALSE;
186 1
187 1 tmp = i2c_EP_receive();
188 1
189 1 i2c_EP_end();
190 1
191 1 delay_us(50);
192 1 startInterupt();
193 1
194 1 return tmp;
195 1 }
196
197
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 393 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 9
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -