📄 24c16a.lst
字号:
183 1
184 1 r_1_byte = read_8_bit_24() ; //读得数据
185 1 _nop_() ;_nop_() ;
186 1 stop_24();
187 1
188 1 return r_1_byte ;
189 1 }
190
191 /*===============================================================
192 * 写1 Byte 数据
193 * 输入参数:w_add 写的地址,格式为:1010+页码(3位)+0+地址(8位)
194 * w_1_byte 要写入的数据
195 =================================================================*/
196 void write_1_byte_24(UINT16 w_add , UINT8 w_1_byte)
197 {
198 1 UINT8 H,L;
199 1 H = w_add / 256 ;
200 1 L = w_add % 256 ;
201 1
202 1 wp = 0 ; //写允许
203 1 delay_n5ms_24(1); //加延时,解决了连续写要延时的问题
204 1
205 1 start_24();
206 1
207 1 write_8_bit_24(H); //发写指令,写高8位
208 1 _nop_() ;_nop_() ;
209 1
210 1 write_8_bit_24(L); //写入地址,写低8位
211 1 _nop_() ;_nop_() ;
212 1
213 1 write_8_bit_24(w_1_byte); //写入数据
214 1 _nop_() ;_nop_() ;
215 1
216 1 stop_24();
217 1
218 1 wp = 1 ; //写保护
219 1
220 1 }
221
222 /*=======================================================================
223 连续写入单个数据
224 *说明: 每次调用后地址自动加1,此函数适用于隔段时间输入一个数据,
225 * 每次调用写入数据的地址是一个外部变量(R_Address)
226 * 写完数据后在固定位置存放数据的地址的下一位
227 *输入参数:w_data 需存的的数据
228 ========================================================================*/
229 void Continuum_Write_1_byte_24(UINT8 w_data)
230 {
231 1 UINT8 H,L;
232 1 UINT8 temp_data ;
233 1 temp_data = w_data ;
234 1
235 1 write_1_byte_24(W_Address, temp_data); //在地址Address处写下w_data
236 1
237 1 //以下是将地址(Address)加1
238 1 H = W_Address / 256 ; //取得地址的高8位
239 1 L = W_Address % 256 ; //取得地址的低8位
C51 COMPILER V7.06 24C16A 11/25/2006 17:36:28 PAGE 5
240 1
241 1 if(L == 255) //若一页写满
242 1 {
243 2 L = 0 ; //下一页的0地址
244 2 H = H + 2 ; //下一页
245 2 }
246 1 else L+=1 ;
247 1 W_Address = H*256+L ;
248 1
249 1 write_1_byte_24(0xaefe,H) ; //在0xaefe存入地址的高8位
250 1 write_1_byte_24(0xaeff,L) ; //在0xaeff存入地址的低8位
251 1 //W_Address此时为所存数据地址的下一个
252 1 }
253
254 /*=======================================================================
255 连续读单个数据
256 *说明: 每次调用后地址自动加1,此函数适用于隔段时间读出一个数据,
257 * 从0单元开始,直到读完存入的所有数据(读到地址为写入的最后地址)
258 * 每次调用读出数据的地址是一个外部变量
259 *返回参数:r_data 读得的数据
260 ========================================================================*/
261 UINT8 Continuum_Read_1_byte_24(void)
262 {
263 1 UINT8 H,L;
264 1 UINT8 r_data ;
265 1
266 1 r_data = read_1_byte_24(R_Address) ;
267 1
268 1 H = R_Address / 256 ; //取得地址的高8位
269 1 L = R_Address % 256 ; //取得地址的低8位
270 1
271 1 if(L == 255) //若一页写满
272 1 {
273 2 L = 0 ; //下一页的0地址
274 2 H = H + 2 ; //下一页
275 2 R_Address = H*256+L ;
276 2 }
277 1 else R_Address+=1 ;
278 1
279 1 return r_data ;
280 1 }
281 /***********************************************************************/
282 void ReadWorkpieceNum(void)
283 {
284 1 WorkpieceNum[0] =read_1_byte_24(0xa000);delay_n5ms_24(1);
285 1 WorkpieceNum[1] =read_1_byte_24(0xa001);delay_n5ms_24(1);
286 1 WorkpieceNum[2] =read_1_byte_24(0xa002);delay_n5ms_24(1);
287 1 WorkpieceNum[3] =read_1_byte_24(0xa003);delay_n5ms_24(1);
288 1 }
289
290 /*========================
291 * 延时函数 5n ms
292 =======================*/
293 void delay_n5ms_24(UINT8 n)
294 {
295 1 UINT8 q ;
296 1 UINT16 p ;
297 1 for(q=0;q<n;q++)
298 1 for(p=0;p<5000;p++){};
299 1 }
300
301
C51 COMPILER V7.06 24C16A 11/25/2006 17:36:28 PAGE 6
302
303 void main(void)
304 {
305 1 UINT8 n ;
306 1
307 1 /*R_Address = 0xa000 ;
308 1
309 1 for(n=0;n<80;n++)
310 1 {
311 1 Continuum_Write_1_byte_24(0x64);
312 1 }
313 1 while(1);
314 1 */
315 1
316 1
317 1
318 1
319 1 write_1_byte_24(0xa000 , 1);
320 1 write_1_byte_24(0xa001 , 2);
321 1 write_1_byte_24(0xa002 , 3);
322 1 write_1_byte_24(0xa003 , 4);
323 1 //ReadWorkpieceNum();
324 1
325 1
326 1
327 1 while(1)
328 1 {
329 2 for(n=0 ; n<4 ; n++){P0 = read_1_byte_24(0xa000) ;delay_n5ms_24(20);}
330 2 }
331 1
332 1 /*UINT8 H ,L ;
333 1 H = read_1_byte_24(0xaefe) ;
334 1 L = read_1_byte_24(0xaeff) ;
335 1 W_Address = H*256+L ; //读出地址
336 1
337 1 R_Address = 0xa000 ;
338 1 Continuum_Write_1_byte_24(0x50);
339 1 Continuum_Write_1_byte_24(0x51);
340 1 Continuum_Write_1_byte_24(0x52);
341 1 Continuum_Write_1_byte_24(0x53);
342 1 Continuum_Write_1_byte_24(0x54);
343 1 Continuum_Write_1_byte_24(0x55);
344 1 Continuum_Write_1_byte_24(0x56);
345 1 Continuum_Write_1_byte_24(0x57);
346 1 Continuum_Write_1_byte_24(0x58);
347 1 Continuum_Write_1_byte_24(0x59);
348 1
349 1
350 1 while(1)
351 1 {
352 1 if(R_Address < W_Address) //读到写的最后位
353 1 {
354 1 P0 = Continuum_Read_1_byte_24();delay_n5ms_24(20);
355 1 }
356 1
357 1
358 1
359 1 }*/
360 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
C51 COMPILER V7.06 24C16A 11/25/2006 17:36:28 PAGE 7
CODE SIZE = 539 ----
CONSTANT SIZE = 16 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 8 25
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -