📄 24c02.lst
字号:
C51 COMPILER V8.08 24C02 12/26/2008 22:02:34 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE 24C02
OBJECT MODULE PLACED IN 24C02.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE 24C02.C BROWSE DEBUG OBJECTEXTEND
line level source
*** WARNING C500 IN LINE 1 OF 24C02.C: LICENSE ERROR (R208: RENEW LICENSE ID CODE (LIC))
1 #include <reg52.h>
2 #include <ctype.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math.h>
7 #include <absacc.h>
8
9 #define uchar unsigned char
10 #define uint unsigned int
11 #define ulong unsigned long
12
13 sbit at24c02_scl=P1^6;
14 sbit at24c02_sda=P1^7;
15
16 void delay(uchar delay_temp);//长延时
17 void delaym(uchar delaym_temp);//短延时
18 void sta(void);//启动IIC总线
19 void stop(void);//停止IIC总线数据传送
20 //void mack(void);//发送应答位
21 void mnack(void);//发送非应答位
22 uchar cack(void);//应答位检查
23 void wrbyt(uchar date_24c02);//向SDA线上发送一个数据字节
24 uchar rdbyt(void);//从SDA线上读取一个数据字节
25
26 uint ii;
27 uchar temp_1;
28
29 main(void)
30 {
31 1 start: for(ii=0;ii<256;ii++)//写入0x55
32 1 {
33 2 sta();
34 2 wrbyt(0xa0);//写24C02
35 2 if(cack()!=0)break;
36 2 wrbyt((uchar)ii);//地址
37 2 if(cack()!=0)break;
38 2 wrbyt(0x55);//写数据
39 2 if(cack()!=0)break;
40 2 stop();
41 2 delay(20);//停止到启动信号之间需要延时
42 2 }
43 1 for(ii=0;ii<256;ii++)//读出并校验0x55
44 1 {
45 2 sta();
46 2 wrbyt(0xa0);
47 2 if(cack()!=0)break;
48 2 wrbyt((uchar)ii);//地址
49 2 if(cack()!=0)break;
50 2 sta();
51 2 wrbyt(0xa1);//读24C02
52 2 if(cack()!=0)break;
53 2 temp_1=rdbyt();//在仿真环境中执行到下一步观察temp_1的值
54 2 if(temp_1!=0x55)break;
C51 COMPILER V8.08 24C02 12/26/2008 22:02:34 PAGE 2
55 2 mnack();
56 2 stop();
57 2 delay(20);
58 2 }
59 1 goto start;
60 1 }
61
62 void delay(uchar delay_temp)//延时子程序
63 {
64 1 uchar i,j;
65 1 for(i=0;i<delay_temp;i++)
66 1 {
67 2 for(j=0;j<255;j++);
68 2 }
69 1 }
70
71 void delaym(uchar delaym_temp)//延时子程序
72 {
73 1 uchar i;
74 1 for(i=0;i<delaym_temp;i++);
75 1 }
76
77 void sta(void)//启动IIC总线
78 {
79 1 at24c02_sda=1;
80 1 at24c02_scl=1;
81 1 delaym(1);
82 1 at24c02_sda=0;
83 1 delaym(1);
84 1 at24c02_scl=0;
85 1 }
86
87 void stop(void)//停止IIC总线数据传送
88 {
89 1 at24c02_sda=0;
90 1 at24c02_scl=1;
91 1 delaym(1);
92 1 at24c02_sda=1;
93 1 delaym(1);
94 1 at24c02_scl=0;
95 1 }
96
97 /*
98 void mack(void)//发送应答位
99 {
100 at24c02_sda=0;
101 at24c02_scl=1;
102 delaym(1);
103 at24c02_scl=0;
104 at24c02_sda=1;
105 }
106 */
107
108 uchar cack(void)//应答位检查
109 {
110 1 uchar i;
111 1 i=0x00;
112 1 at24c02_sda=1;
113 1 at24c02_scl=1;
114 1 if(at24c02_sda==1)i=0xff;
115 1 at24c02_scl=0;
116 1 return i;
C51 COMPILER V8.08 24C02 12/26/2008 22:02:34 PAGE 3
117 1 }
118
119 void mnack(void)//发送非应答位
120 {
121 1 at24c02_sda=1;
122 1 at24c02_scl=1;
123 1 delaym(1);
124 1 at24c02_scl=0;
125 1 at24c02_sda=0;
126 1 }
127
128 void wrbyt(uchar date_w24)//向SDA线上发送一个数据字节
129 {
130 1 uchar i,j;
131 1 j=0x80;
132 1 for(i=0;i<8;i++)
133 1 {
134 2 if((date_w24&j)==0)
135 2 {
136 3 at24c02_sda=0;
137 3 at24c02_scl=1;
138 3 delaym(1);
139 3 at24c02_scl=0;
140 3 }
141 2 else
142 2 {
143 3 at24c02_sda=1;
144 3 at24c02_scl=1;
145 3 delaym(1);
146 3 at24c02_scl=0;
147 3 at24c02_sda=0;
148 3 }
149 2 j=j>>1;
150 2 }
151 1 }
152
153 uchar rdbyt(void)//从SDA线上读取一个数据字节
154 {
155 1 uchar i,j;
156 1 j=0x00;
157 1 for(i=0;i<8;i++)
158 1 {
159 2 at24c02_sda=1;
160 2 at24c02_scl=1;
161 2 if(at24c02_sda==0)
162 2 {
163 3 j=j&0xfe;
164 3 }
165 2 else
166 2 {
167 3 j=j|0x01;
168 3 }
169 2 if(i!=7)j=j<<1;
170 2 at24c02_scl=0;
171 2 }
172 1 return j;
173 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 296 ----
CONSTANT SIZE = ---- ----
C51 COMPILER V8.08 24C02 12/26/2008 22:02:34 PAGE 4
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -