📄 iicled.lst
字号:
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE IICLED
OBJECT MODULE PLACED IN IICLED.OBJ
COMPILER INVOKED BY: C:\Keilc51\C51\BIN\C51.EXE IICLED.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /************************************************/
2 #include <REG52.H>
3 #include <intrins.h>
4 #define uchar unsigned char
5 #define uint unsigned int
6 #define ulong unsigned long
7 #define int8 unsigned char
8 #define int16 unsigned int
9 #define int32 unsigned long
10 sbit I2C_SDA= P1^5;
11 sbit I2C_SCK= P1^4;
12 sbit I2C_WP= P1^3;
13
14 //============================
15 sbit LED1=P3^4;
16 sbit GRE=P1^7;
17 sbit s1=P0^3;
18 sbit s2=P2^3;
19 sbit SCK=P2^4;
20 sbit RCK=P2^5;
21 sbit nG=P2^6;
22 sbit SER=P2^7;
23 uchar xdata tab[16][6];
24 //===============================================
25 /* 列选择*/
26 void lay(int8 n)
27 {
28 1 int8 i;
29 1 i=n;
30 1 s1=0;
31 1 s2=0;
32 1 if(n<8)
33 1 {
34 2 _nop_();
35 2 P0=(P0&0xf8)|(~i);
36 2 }
37 1 else
38 1 { i=i-7;
39 2 i=i&0x07;
40 2 i=i|0xf0; //保护nG位
41 2 P2=(P2&0xf8)|(~i);
42 2 }
43 1
44 1 }
45 /*延时*/
46 void delay(int8 N)
47 {
48 1 int8 i,j,k;
49 1 for(i=0;i<100;i++)
50 1 for(j=0;j<10;j++)
51 1 for(k=0;k<N;k++);
52 1
53 1 }
54 /*发送字节,移位发送*/
55 void WriteByte(int8 val)
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 2
56 {
57 1 int8 i,m;
58 1 m=~val;
59 1 for (i = 8; i > 0; i --)
60 1 {
61 2 SCK = 0;//拉低74HC595时钟
62 2 SER = m&0x01;//发送74HC595一位串行数据
63 2 SCK = 1;//拉高74HC595时钟
64 2 m=m>>1;
65 2 _nop_();//延时
66 2 }
67 1 SER = 1;//释放数据总线
68 1 //========================
69 1 // 以下3条指令若在多字节时,应该移入多字节全发送完后在执行此3条指令
70 1 // RCLK = 0;
71 1 // _nop_();//延时
72 1 // RCLK = 1;//打入并行数据
73 1 }
74
75 /*保存串行发送的数据,并打入到并行引脚寄存器*/
76 //void Save595(void)
77 //{
78 // RCK=0; //保存并行数据
79 // _nop_();
80 // RCK=1;
81 //}
82
83 /*发送字*/
84 void display(int8 n )
85 {
86 1 int8 i;
87 1 for(i=0;i<6;i++)
88 1 WriteByte(tab[n][i]);
89 1 RCK=0; //保存并行数据
90 1 _nop_();
91 1 RCK=1;
92 1 }
93
94 void delays(int8 n)
95 {
96 1 int8 i;
97 1 n=n;
98 1 for(i=10;i>0;i--);
99 1 }
100
101 void XianShiX(void)
102 {
103 1 /**/display(0);//行0
104 1 lay(14); //列
105 1 delays(1); //短延时
106 1 /**/display(1);//行1
107 1 lay(13);
108 1 delays(1);
109 1 /**/display(2);//行2
110 1 lay(12);
111 1 delays(1);
112 1 /**/display(3);//行3
113 1 lay(11);
114 1 delays(1);
115 1 /**/display(4);//行4
116 1 lay(10);
117 1 delays(1);
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 3
118 1 /**/display(5);//行5
119 1 lay(9);
120 1 delays(1);
121 1 /**/display(6);//行6
122 1 lay(8);
123 1 delays(1);
124 1 /**/display(7);//行7
125 1 lay(15);
126 1 delays(1);
127 1 /**/display(8);//行8
128 1 lay(7);
129 1 delays(1);
130 1 /**/display(9);//行9
131 1 lay(6);
132 1 delays(1);
133 1 /**/display(10);//行10
134 1 lay(5);
135 1 delays(1);
136 1 /**/display(11);//行11
137 1 lay(4);
138 1 delays(1);
139 1 /**/display(12); //行12
140 1 lay(0);
141 1 delays(1);
142 1 /**/display(13); //行13
143 1 lay(1);
144 1 delays(1);
145 1 /**/display(14); //行14
146 1 lay(2);
147 1 delays(1);
148 1 /**/display(15); //行15
149 1 lay(3);
150 1 delays(1);
151 1 }
152 //=============================
153 //延时10US
154 //内部调用函数
155 void Delay_10_uS(void)
156 {
157 1 char i=10;
158 1 while(i--);
159 1 }
160
161 //延时n_milisecond MS
162 //供内部调用函数
163 void delay_n_ms( uint n_milisecond) /* n mS delay */
164 {
165 1 uchar i;
166 1 while(n_milisecond--)
167 1 {
168 2 i=37;
169 2 while(i--);
170 2 }
171 1 }
172
173 //开始位
174 //内部调用函数
175 bit I2C_Start(void)
176 {
177 1 Delay_10_uS();
178 1 I2C_SDA =1;
179 1 Delay_10_uS();
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 4
180 1 I2C_SCK =1;
181 1 Delay_10_uS();
182 1 if ( I2C_SDA == 0) return 0;
183 1 if ( I2C_SCK == 0) return 0;
184 1 I2C_SDA = 0;
185 1 Delay_10_uS();
186 1 I2C_SCK = 0;
187 1 Delay_10_uS();
188 1 return 1;
189 1 }
190
191 //停止位
192 //内部调用函数
193 void I2C_Stop(void)
194 {
195 1 Delay_10_uS();
196 1 I2C_SDA = 0;
197 1 Delay_10_uS();
198 1 I2C_SCK = 1;
199 1 Delay_10_uS();
200 1 I2C_SDA = 1;
201 1 Delay_10_uS();
202 1 }
203
204 //写数据后拉低应答信号
205 //内部调用函数
206
207 void I2C_Ack(void)
208 {
209 1 Delay_10_uS();
210 1 I2C_SDA=0;
211 1 Delay_10_uS();
212 1 I2C_SCK=1;
213 1 Delay_10_uS();
214 1 I2C_SCK=0;
215 1 Delay_10_uS();
216 1 }
217
218 //读数据后拉高应答信号
219 //内部调用函数
220 void I2C_Nack(void)
221 {
222 1 Delay_10_uS();
223 1 I2C_SDA=1;
224 1 Delay_10_uS();
225 1 I2C_SCK=1;
226 1 Delay_10_uS();
227 1 I2C_SCK=0;
228 1 Delay_10_uS();
229 1 }
230
231 //写单字节数据
232 //内部调用函数
233 bit I2C_Send_Byte( uchar d)
234 {
235 1 uchar i = 8;
236 1 bit bit_ack;
237 1 while( i-- )
238 1 {
239 2 Delay_10_uS();
240 2 if ( d &0x80 ) I2C_SDA =1;
241 2 else I2C_SDA =0;
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 5
242 2 Delay_10_uS();
243 2 I2C_SCK = 1;
244 2 Delay_10_uS();
245 2 I2C_SCK = 0;
246 2 d = d << 1;
247 2 }
248 1 Delay_10_uS();
249 1 I2C_SDA = 1;
250 1 Delay_10_uS();
251 1 I2C_SCK = 1;
252 1 Delay_10_uS();
253 1 bit_ack = I2C_SDA;
254 1 I2C_SCK =0;
255 1 Delay_10_uS();
256 1 return bit_ack;
257 1 }
258
259 //接收单字节数据
260 //内部调用函数
261 uchar I2C_Receive_Byte(void)
262 {
263 1 uchar i = 8, d;
264 1 Delay_10_uS();
265 1 I2C_SDA = 1;
266 1 while ( i--)
267 1 {
268 2 d = d << 1;
269 2 Delay_10_uS();
270 2 I2C_SCK =1;
271 2 if ( I2C_SDA ) d++;
272 2 Delay_10_uS();
273 2 I2C_SCK =0;
274 2 }
275 1 return d;
276 1 }
277
278 //写多字节数据
279 //供外部调用函数
280 void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
281 {
282 1
283 1 while(count--)
284 1 {
285 2 I2C_Start();
286 2 /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/ /* 24C16 USE */
287 2 I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
288 2 I2C_Send_Byte( AT24C64_address/256 );//写存储器页地址
289 2 I2C_Send_Byte( AT24C64_address %256 );//写存储器字节地址
290 2 I2C_Send_Byte( *(uchar*)mcu_address );//写MCU地址指针指数据到存储单元
291 2 I2C_Stop();
292 2 delay_n_ms(10); /* waiting for write cycle to be completed */
293 2 ((uchar*)mcu_address)++;
294 2 AT24C64_address++;
295 2 }
296 1 }
297
298 //读多字节数据
299 //供外部调用函数
300 void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count)
301 {
302 1
303 1 while(count--)
C51 COMPILER V8.05a IICLED 01/07/2008 17:57:46 PAGE 6
304 1 {
305 2 I2C_Start();
306 2 /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256
307 2 *2 );*/ /* 24C16 USE */
308 2 I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
309 2 I2C_Send_Byte( AT24C64_address/256 );//写存储器页地址
310 2 I2C_Send_Byte( AT24C64_address % 256 );//写存储器字节地址
311 2 I2C_Start();
312 2 /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
313 2 I2C_Send_Byte( 0xa1 );//写命令设备地址为10100001最后一位为1"读标志"
314 2 *(uchar*)mcu_address = I2C_Receive_Byte();//读单字节数据到MCU指针指向的地址
315 2 I2C_Nack();//回应答信号
316 2 I2C_Stop();
317 2 ((uchar*)mcu_address)++;
318 2 AT24C64_address++;
319 2 }
320 1 }
321
322 //=====================================
323 void main()
324 {
325 1 //uchar i,j;
326 1 //uchar tab[16][6];
327 1 P1=0;
328 1 P2=0;
329 1 P3=0;
330 1 GRE=1;
331 1 AT24C64_R(tab,0x00,96);
332 1 while(1) XianShiX();
333 1
334 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 685 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 96 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 14
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 + -