📄 24c04.lst
字号:
C51 COMPILER V7.01 24C04 10/04/2007 23:23:02 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE 24C04
OBJECT MODULE PLACED IN 24c04.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24c04.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include<reg51.H>
2 #include <intrins.h>
3 #define uchar unsigned char
4 #define uint unsigned int
5 sbit SCL=P1^6;
6 sbit SDA=P1^7;
7 sbit led=P1^0;
8 sbit key=P1^2;
9 sbit led2=P1^1;
10 //定时函数
11 void DelayMs(unsigned int number)
12 {
13 1 unsigned char temp;
14 1 for(;number>=1;number--)
15 1 {
16 2 for(temp=112;temp>=1;temp--) ;
17 2 }
18 1 }
19 ////////////start//////////////
20 start_iic()
21 {
22 1 SDA=1;
23 1 SCL=1;
24 1 _nop_();
25 1 _nop_();
26 1 _nop_();
27 1 _nop_();
28 1 _nop_();
29 1 SDA=0;
30 1 _nop_();
31 1 _nop_();
32 1 _nop_();
33 1 _nop_();
34 1 _nop_();
35 1 SCL=0;
36 1 }
37 ///////////stop ////////////////
38 stop_iic()
39 {
40 1 SDA=0;
41 1 SCL=1;
42 1 _nop_();
43 1 _nop_();
44 1 _nop_();
45 1 _nop_();
46 1 _nop_();
47 1 SDA=1;
48 1 _nop_();
49 1 _nop_();
50 1 _nop_();
51 1 _nop_();
52 1 _nop_();
53 1 }
54 //////////ack ///////////////
55 ack_iic()
C51 COMPILER V7.01 24C04 10/04/2007 23:23:02 PAGE 2
56 {
57 1 SDA=0;
58 1 SCL=1;
59 1 _nop_();
60 1 _nop_();
61 1 _nop_();
62 1 _nop_();
63 1 SDA=1;
64 1 SCL=0;
65 1 }
66 /////////nack/////////////////
67 nack_iic()
68 {
69 1 SDA=1;
70 1 SCL=1;
71 1 _nop_();
72 1 _nop_();
73 1 _nop_();
74 1 _nop_();
75 1 SDA=0;
76 1 SCL=0;
77 1 }
78 /////////write_byte///////////////////
79 write_byte(uchar c)
80 {
81 1 uchar i;
82 1 for (i=0;i<8;i++)
83 1 {
84 2 if(c&0x80)SDA=1;
85 2 else SDA=0;
86 2 SCL=1;
87 2 _nop_();
88 2 _nop_();
89 2 _nop_();
90 2 _nop_();
91 2 _nop_();
92 2 SCL=0;
93 2 c=c<<1;
94 2 }
95 1 SCL=0;
96 1 DelayMs(10);
97 1 }
98 /////////read_byte begin///////////////////
99 uchar read_byte()
100 {
101 1 uchar i;
102 1 uchar r=0;
103 1 SDA=1;
104 1 for(i=0;i<8;i++)
105 1 {
106 2 r=r<<1;
107 2 SCL=1;
108 2 _nop_();
109 2 _nop_();
110 2 _nop_();
111 2 _nop_();
112 2 if(SDA==1)r++;
113 2 _nop_();
114 2 _nop_();
115 2 _nop_();
116 2 _nop_();
117 2 SCL=0;
C51 COMPILER V7.01 24C04 10/04/2007 23:23:02 PAGE 3
118 2 }
119 1 SCL=0;
120 1 return r;
121 1 }
122
123 void main(void)
124 { uchar j=0;
125 1 while(1)
126 1 {
127 2 if(!key)
128 2 {
129 3 start_iic();
130 3 write_byte(0xa0);////send order
131 3 ack_iic();
132 3 write_byte(j);/////send address
133 3 ack_iic();
134 3 write_byte(j);////send data
135 3 ack_iic();
136 3 stop_iic();///////////
137 3 DelayMs(10);
138 3 //////////////////////////////
139 3 start_iic();
140 3 write_byte(0xa0);////send order
141 3 ack_iic();
142 3 write_byte(j);////send ADDress
143 3 ack_iic();
144 3 ////////////////read ready
145 3 start_iic();
146 3 write_byte(0xa1);////send order
147 3 ack_iic();
148 3 P2=read_byte();/////read
149 3 SCL=0;
150 3 nack_iic();
151 3 stop_iic();
152 3 while(!key);
153 3 j++;
154 3 }}}
155
156
157
158 /*需要上拉电阻PULLUP
159 IIC的接口为开漏输出,因而需要上拉电阻,但在用PROTEUS仿真时加上拉电阻不能用那种带阻值的电阻上拉,不然后会
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -