📄 isr_i2c.lst
字号:
191 2 I2C_pt->I2CTCHandler = I2CTxSetSCL;
192 2 }
193 1 else{ //All the bits has been sent...
194 2 //SDA_INPUT(); //* set SDA line as an input
195 2 //* change interrupt handler to I2CTxPrepareACK
196 2 I2C_pt->I2CTCHandler = I2CTxPrepareACK;
197 2 }
198 1 }
199 //*-----------------------------------------------------------------------------
200 //* 函数名称 : I2CTxSendStartSDA (I2Cdesc *I2C_pt)
201 //* Object : I2C
202 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
203 //* 输出变量 : 无
204 //* 功能 :为I2C的开始时序SDA的变化
205 //*-----------------------------------------------------------------------------
206 void I2CTxSendStartSDA (I2Cdesc *I2C_pt){
207 1 SDA_CLR(); //* clear SDA line
208 1 //* change interrupt handler to I2CTxSendStartSCL
209 1 I2C_pt->I2CTCHandler = I2CTxSendStartSCL;
210 1 }
211
212 //*-----------------------------------------------------------------------------
213 //* 函数名称 : I2CTxSendStartSDA (I2Cdesc *I2C_pt)
214 //* Object : I2C
215 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
216 //* 输出变量 : 无
217 //* 功能 :为I2C的开始时序SCL的变化
218 //*-----------------------------------------------------------------------------
219 void I2CTxSendStartSCL (I2Cdesc *I2C_pt){
220 1 SCL_CLR(); //* clear SCL line
221 1 //* change interrupt handler to I2CTxSendBit
222 1 I2C_pt->I2CTCHandler = I2CTxSendBit;
223 1 }
224
225 //*-----------------------------------------------------------------------------
226 //* 函数名称 : I2CTxPrepareSTOP (I2Cdesc *I2C_pt)
227 //* Object : I2C
228 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
229 //* 输出变量 : 无
230 //* 功能 :为I2C的发送准备停止
231 //*-----------------------------------------------------------------------------
232 void I2CTxPrepareSTOP (I2Cdesc *I2C_pt)
233 //* Begin
234 {
235 1 //* clear SDA line
236 1 SDA_CLR();
237 1
238 1 //* set SCL line
239 1 SCL_SET();
240 1
241 1 //* change interrupt handler to I2CTxSendStopSDA
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 5
242 1 I2C_pt->I2CTCHandler = I2CTxSendStopSDA;
243 1
244 1 //* End
245 1 }
246
247
248 //*-----------------------------------------------------------------------------
249 //* 函数名称 : I2CTxSendStopSCL (I2Cdesc *I2C_pt)
250 //* Object : I2C
251 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
252 //* 输出变量 : 无
253 //* 功能 :为I2C的停止时序SCL的变化
254 //*-----------------------------------------------------------------------------
255 void I2CTxSendStopSCL (I2Cdesc *I2C_pt){
256 1 SCL_SET();; //* set SCL line
257 1 //* change interrupt handler to I2CTxSendStopSDA
258 1 I2C_pt->I2CTCHandler = I2CTxSendStopSDA;
259 1 }
260
261 //*-----------------------------------------------------------------------------
262 //* 函数名称 : I2CTxSendStopSDA (I2Cdesc *I2C_pt)
263 //* Object : I2C
264 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
265 //* 输出变量 : 无
266 //* 功能 :为I2C的停止时序SDA的变化
267 //*-----------------------------------------------------------------------------
268 void I2CTxSendStopSDA (I2Cdesc *I2C_pt){
269 1 SDA_SET();; //Set SDA line high
270 1 I2C_pt->state = OK; //Return to "OK"(Idle) state
271 1
272 1 I2C_pt->I2CTCHandler = I2C_pt->I2cFinish; //change interrupt handler
273 1 }
274
275 //*-----------------------------------------------------------------------------
276 //* 函数名称 : I2CTxPrepareACK (I2Cdesc *I2C_pt)
277 //* Object : I2C
278 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
279 //* 输出变量 : 无
280 //* 功能 :为I2C的发送应答时序的前的准备
281 //*-----------------------------------------------------------------------------
282 void I2CTxPrepareACK (I2Cdesc *I2C_pt){
283 1 SCL_SET(); //* set SCL line
284 1 //* change interrupt handler to I2CTxWaitACK
285 1 I2C_pt->I2CTCHandler = I2CTxWaitACK;
286 1 }
287
288 //*-----------------------------------------------------------------------------
289 //* 函数名称 : I2CRxPrepareACK (I2Cdesc *I2C_pt)
290 //* Object : I2C
291 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
292 //* 输出变量 : 无
293 //* 功能 :为I2C的接收应答时序的前的准备
294 //*-----------------------------------------------------------------------------
295 void I2CRxPrepareACK (I2Cdesc *I2C_pt)
296 //* Begin
297 {
298 1 //* set SCL line
299 1 SCL_SET();
300 1
301 1 if(I2C_pt->mode == STOP)
302 1 //* change interrupt handler to
303 1 I2C_pt->I2CTCHandler = I2CTxPrepareSTOP;
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 6
304 1
305 1 else
306 1 //* change interrupt handler to I2CRxDoACK
307 1 I2C_pt->I2CTCHandler = I2CRxDoACK;
308 1
309 1 //* End
310 1 }
311
312
313 //*-----------------------------------------------------------------------------
314 //* 函数名称 : I2CTxWaitACK (I2Cdesc *I2C_pt)
315 //* Object : I2C
316 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
317 //* 输出变量 : 无
318 //* 功能 :为I2C的等待芯片的应答
319 //*-----------------------------------------------------------------------------
320 void I2CTxWaitACK (I2Cdesc *I2C_pt){
321 1 if(SDA_VAL() == 0){ //* if ACK (SDA = 0)...
322 2 switch(I2C_pt->mode){
323 3 case STOP :
324 3 SCL_CLR(); //* clear SCL line
325 3 I2C_pt->I2CTCHandler = I2CTxPrepareSTOP; //* change interrupt handler to
326 3 break;
327 3 case DEVICE_READ :
328 3 SCL_CLR(); //* clear SCL line
329 3 I2C_pt->I2CTCHandler = I2CDeviceRead; //* change interrupt handler to
330 3 break;
331 3 case DATA_READ :
332 3 I2C_pt->I2CTCHandler = I2CRxReceiveByte; //* change interrupt handler to
333 3 break;
334 3 default :
335 3 SCL_CLR(); //* clear SCL line
336 3 //* change interrupt handler to
337 3 I2C_pt->I2CTCHandler = I2CTxSendByte;
338 3 break;
339 3 }
340 2 }
341 1 else{
342 2 I2C_pt->nb_ACK--; //Decrease the counter.
343 2 if(I2C_pt->nb_ACK == 0)
344 2 I2C_pt->I2CTCHandler = I2CError; //Timeout, change interrupt handler to I2C
345 2 }
346 1 }
347
348
349 //*-----------------------------------------------------------------------------
350 //* 函数名称 : I2CRxDoACK (I2Cdesc *I2C_pt)
351 //* Object : I2C
352 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
353 //* 输出变量 : 无
354 //* 功能 :为主动发送应答给I2C设备
355 //*-----------------------------------------------------------------------------
356 void I2CRxDoACK (I2Cdesc *I2C_pt)
357 //* Begin
358 {
359 1 //* clear SCL line
360 1 SCL_CLR();
361 1
362 1 //* change interrupt handler to
363 1 I2C_pt->I2CTCHandler = I2CRxReceiveByte;
364 1
365 1 //* End
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 7
366 1 }
367
368
369 //*-----------------------------------------------------------------------------
370 //* 函数名称 : I2CTxSetSCL (I2Cdesc *I2C_pt)
371 //* Object : I2C
372 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
373 //* 输出变量 : 无
374 //* 功能 :为在发送数据时把I2C的SCL线设置为高电平
375 //*-----------------------------------------------------------------------------
376 void I2CTxSetSCL (I2Cdesc *I2C_pt){
377 1 SCL_SET(); //* set SCL line
378 1 //* change interrupt handler to I2CTxSendBit
379 1 I2C_pt->I2CTCHandler = I2CTxSendBit;
380 1 }
381
382
383 //*-----------------------------------------------------------------------------
384 //* 函数名称 : I2CTxClearSCL (I2Cdesc *I2C_pt)
385 //* Object : I2C
386 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
387 //* 输出变量 : 无
388 //* 功能 :为在发送数据时把SCL线设置为低电平
389 //*-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -