📄 24c02.lst
字号:
C51 COMPILER V6.23a 24C02 11/16/2005 20:39:02 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE 24C02
OBJECT MODULE PLACED IN 24C02.OBJ
COMPILER INVOKED BY: D:\Program Files\KeilC51Full\C51\BIN\C51.EXE 24C02.c ROM(SMALL) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //////////////////////////////////////////////////////////////////////
2 //
3 //this file shows how to use 24c02 in a 89C51 system
4 //
5 //the commom-used function is ReadByte(),WriteByte,Clear()
6 //ReadPage() and WritePage() is in vacancy now
7 //
8 // - HateMath 2005.11.7
9 //////////////////////////////////////////////////////////////////////
10
11 #include<At89X51.h>
12 #include <intrins.h>
13
14 //////////////////////////////////////////////////////////////////////
15 //maybe use #define is better here
16 sbit SDA = 0xB0^5; //P3_5 connect the SDA footprint
17 sbit SCL = 0xB0^4; //P3_4 connect the CLK footprint
18
19
20
21 //////////////////////////////////////////////////////////////////////
22 //delay some time
23 void Delay()
24 {
25 1 _nop_();
26 1 _nop_();
27 1 }
28
29 //////////////////////////////////////////////////////////////////////
30 // get ACK signal from 24c02
31 bit GetACK()
32 {
33 1 bit bACK = 1;
34 1
35 1 SDA = 1; //recover SDA
36 1 Delay();
37 1 SCL = 1; //then, 24c02to pull SDA down if we send byte correctly
38 1 Delay();
39 1 bACK = SDA;
40 1 SCL = 0;
41 1
42 1 return bACK;
43 1 }
44
45 //////////////////////////////////////////////////////////////////////
46 //tell 24c02 to stop
47 void Stop()
48 {
49 1 SDA = 0;
50 1 Delay();
51 1 SCL = 1;
52 1 Delay();
53 1 SDA = 1;
54 1 Delay();
55 1 }
C51 COMPILER V6.23a 24C02 11/16/2005 20:39:02 PAGE 2
56 //////////////////////////////////////////////////////////////////////
57 //tell 24c02 to start
58 void Start()
59 {
60 1 SCL = 1;
61 1
62 1 SDA = 1;
63 1 Delay();
64 1 SDA = 0;
65 1 Delay();
66 1 }
67
68 //////////////////////////////////////////////////////////////////////
69 //send one byte(word adress or device adress) to 24c02
70 //
71 //Parameters:
72 // nData: data to be write to 24c02, 8 bit by default
73 void SendByte(char nData)
74 {
75 1
76 1 //test each bit of nData,then send to 24c02 bit by bit
77 1 //MSB of nData first, LSB last
78 1 unsigned char nTestBit = 0x80; //mask bit
79 1 unsigned char i = 0;
80 1
81 1 SCL = 0; //pull the SCL low first , so the SDA can setup(change) data
82 1 Delay();
83 1 for(i = 0; i < 8; i++)
84 1 {
85 2 SDA = nData & nTestBit;
86 2 Delay(); //(? necessarry)
87 2 SCL = 1;
88 2 Delay();
89 2 SCL = 0;
90 2
91 2 nTestBit >>= 1;
92 2 }
93 1 }
94
95 //////////////////////////////////////////////////////////////////////
96 //random write one byte to 24c02
97 //
98 //Parameters:
99 // nData: data to be write to 24c02, 8 bit by default
100 // nAdress:adress in 24c02, from which write the nData
101 void WriteByte(char nData, const unsigned char nAdress)
102 {
103 1 unsigned int i = 0; //for loop
104 1
105 1
106 1 //1.start signal
107 1 Start();
108 1
109 1 //2.send device adress(0xA0 when write)
110 1 SendByte(0xA0);
111 1 while(GetACK());
112 1
113 1 //3.send word adress
114 1 SendByte(nAdress);
115 1 while(GetACK());
116 1
117 1 //4.send nData
C51 COMPILER V6.23a 24C02 11/16/2005 20:39:02 PAGE 3
118 1 SendByte(nData);
119 1 while(GetACK());
120 1
121 1 //5.send stop signal
122 1 Stop();
123 1
124 1 //6.delay for 10ms, (! necessary)see "write cycle timing" in the data-sheet for 24c02
125 1 for(i = 0; i < 2000; i++) //at 12MHz condition, 2000 is OK
126 1 {
127 2 Delay();
128 2 }
129 1 }
130
131 //////////////////////////////////////////////////////////////////////
132 //read one byte from 24c02
133 //
134 //Parameters:
135 // nAddress: adress of memory in 24c02,range:(0 - 256)
136 char ReadByte(const unsigned char nAddress)
137 {
138 1 char i = 0; //not the unsigned char
139 1 char nBuff = 0;
140 1
141 1 //1.start signal
142 1 Start();
143 1
144 1 //2.send device adress(write)
145 1 SendByte(0xA0);
146 1 while(GetACK());
147 1
148 1 //3.send word adress
149 1 SendByte(nAddress);
150 1 while(GetACK());
151 1
152 1 //4.start signal again
153 1 Start();
154 1
155 1 //5.send device adress(read)
156 1 SendByte(0xA1);
157 1 while(GetACK());
158 1
159 1 //6.get each bit from 24c02,MSB first,LSB last.
160 1 for(i = 7; i >= 0; i--)
161 1 {
162 2 SCL = 1;
163 2 Delay();
164 2 nBuff |= (unsigned char)SDA << i;//(?)to be changed
165 2 SCL = 0;
166 2 Delay();
167 2 }
168 1
169 1 //7.stop
170 1 Stop();
171 1
172 1 return nBuff;
173 1 }
174
175
176 //////////////////////////////////////////////////////////////////////
177 //write 8 BYTE data into 24c02 from nStartAddress
178 //
179 //Parameters:
C51 COMPILER V6.23a 24C02 11/16/2005 20:39:02 PAGE 4
180 // nStartAddress: adress of memory in 24c02,range:(0 - 256)
181 void WritePage(const unsigned char nStartAddress)
182 {
183 1
184 1 }
*** WARNING C280 IN LINE 181 OF 24C02.C: 'nStartAddress': unreferenced local variable
185
186
187 //////////////////////////////////////////////////////////////////////
188 //clear all data in 24c02
189 //the memory will be FF all.
190 //
191 void ClearAll()
192 {
193 1 unsigned short i = 0;
194 1
195 1 //24c02 has 256BYTEs total
196 1 for(i = 0; i <= 255; i++)
197 1 {
198 2 WriteByte(0xFF, i);
199 2 }
200 1
201 1 }
202
203
204
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 232 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 3
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -