📄 i2c.lst
字号:
C51 COMPILER V7.06 I2C 10/03/2006 10:29:04 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN I2C.OBJ
COMPILER INVOKED BY: E:\Program Files\C51\BIN\C51.EXE I2C.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg52.h>
2 #include <intrins.h>
3 #define uchar unsigned char
4 #define uint unsigned int
5 sbit SCL=P1^1;
6 sbit SDA=P1^3;
7
8 void delay(unsigned int loop) //延时函数
9 { unsigned int i ; //loop 为执行空指令的次数,改变它可一改变延时时长
10 1 for(i=0;i<loop;i++);//循环执行空指令loop次,达到延时目的
11 1 }
12
13
14 /***********开始**************/
15 void Start_I2c()
16 {
17 1 SDA=1;
18 1 delay(1);
19 1 SCL=1;
20 1 delay(3);
21 1 SDA=0;
22 1 delay(3);
23 1 SCL=0;
24 1 delay(1);
25 1 }
26
27
28
29 /************结束*************/
30 void Stop_I2c()
31 {
32 1 SDA=0;
33 1 delay(1);
34 1 SCL=1;
35 1 delay(3);
36 1 SDA=1;
37 1 delay(1);
38 1
39 1 }
40
41
42 /***********SendB**************/
43 void SendB(uchar c)
44 {
45 1 uchar BitCnt,ack;
46 1 for(BitCnt=0;BitCnt<8;BitCnt++)
47 1 {
48 2 if((c<<BitCnt)&0x80)SDA=1;
49 2 else SDA=0;
50 2 delay(2);
51 2 SCL=1;
52 2 delay(5);
53 2 SCL=0;
54 2 delay(2);
55 2
C51 COMPILER V7.06 I2C 10/03/2006 10:29:04 PAGE 2
56 2 }
57 1 delay(1);
58 1 SDA=1;
59 1 delay(5);
60 1 SCL=1;
61 1 delay(1);
62 1 if(SDA==1)ack=0;
63 1 else ack=1;
64 1 SCL=0;
65 1 delay(1);
66 1
67 1 }
68
69 /*************RcvB****************/
70 uchar RcvB()
71 {
72 1 uchar retc;
73 1 uchar BitCnt;
74 1 retc=0;
75 1 SDA=1;
76 1 for(BitCnt=0;BitCnt<8;BitCnt++)
77 1 {
78 2 delay(1);
79 2 SCL=0;
80 2 delay(5);
81 2 SCL=1;
82 2 delay(2);
83 2 retc=retc<<1;
84 2 if(SDA==1)retc=retc+1;
85 2 delay(1);
86 2 }
87 1 SCL=0;
88 1 delay(1);
89 1 return(retc);
90 1 }
91
92 /************应答****************/
93 void Ack_I2c(bit a)
94 {
95 1 if(a==0)SDA=0;
96 1 else SDA=1;
97 1 delay(1);
98 1 SCL=1;
99 1 delay(2);
100 1 SCL=0;
101 1 delay(1);
102 1
103 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 217 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -