📄 per.lst
字号:
260 1 cs5045=0;
261 1 _nop_();
262 1 write_8bit(WREN);//send write enable command
263 1 _nop_();
264 1 cs5045=1;
265 1 _nop_();
266 1 cs5045=0;
267 1 _nop_();
268 1 write_8bit(WRITE0);//send write command
269 1 write_8bit(StartAddr);//send write address
270 1 for(i=0;i<12;i++)
271 1 {
272 2 write_8bit(*(p+i));
273 2 }
274 1 _nop_();
275 1 cs5045=1;
276 1 for(nopp=0;nopp<4000;nopp++)
277 1 {
278 2 ;
279 2 }
280 1 write_8bit(WRDI);//send write disable command
281 1 }
282 //*****************************************************************************************
283 //function: void write_page_array4(unsigned char StartAddr,unsigned char *p)
284 //description: this function write 4 byte data to x5045,the first byte address is specified
285 //parameter: StartAddr---the first address of the unit will be write;value---value to be write
286 // p---pointer to array
287 //return: none
288 //*****************************************************************************************
289 /*
290 void write_page_array4(unsigned char StartAddr,unsigned char *p)//write 12 byte data to x5045
291 { //address from the parametre StartAddr
292 unsigned int nopp;
293 unsigned char i;
294 ////write one byte to 00-ffh address
295 cs5045=0;
296 _nop_();
297 write_8bit(WREN);//send write enable command
298 _nop_();
299 cs5045=1;
300 _nop_();
301 cs5045=0;
302 _nop_();
303 write_8bit(WRITE0);//send write command
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 6
304 write_8bit(StartAddr);//send write address
305 for(i=0;i<4;i++)
306 {
307 write_8bit(*(p+i));
308 }
309 _nop_();
310 cs5045=1;
311 for(nopp=0;nopp<4000;nopp++)
312 {
313 ;
314 }
315 write_8bit(WRDI);//send write disable command
316 }
317 */
318 //*****************************************************************************************
319 //function: void write1_page_array4(unsigned char StartAddr,unsigned char *p)
320 //description: this function write 4 byte data to x5045,the first byte address is specified
321 //parameter: StartAddr---the first address of the unit will be write;value---value to be write
322 // p---pointer to array
323 //return: none
324 //*****************************************************************************************
325 void write1_page_array4(unsigned char StartAddr,unsigned char *p)//write 12 byte data to x5045
326 { //address from the parametre StartAddr
327 1 unsigned int nopp;
328 1 unsigned char i;
329 1 ////write one byte to 00-ffh address
330 1 cs5045=0;
331 1 _nop_();
332 1 write_8bit(WREN);//send write enable command
333 1 _nop_();
334 1 cs5045=1;
335 1 _nop_();
336 1 cs5045=0;
337 1 _nop_();
338 1 write_8bit(WRITE0);//send write command
339 1 write_8bit(StartAddr);//send write address
340 1 for(i=0;i<4;i++)
341 1 {
342 2 write_8bit(*(p+i));
343 2 }
344 1 _nop_();
345 1 cs5045=1;
346 1 for(nopp=0;nopp<4000;nopp++)
347 1 {
348 2 ;
349 2 }
350 1 write_8bit(WRDI);//send write disable command
351 1 }
352
353 //*****************************************************************************************
354 //function: float read_page_float4(unsigned char FirstAddr);
355 //description: this function read float data from x5045,the first byte address is specified
356 //parameter: addr---the first address of the unit will be read;
357 //return: the storing float data
358 //*****************************************************************************************
359 float read_page_float4(unsigned char FirstAddr)
360 {
361 1 union{float x1;unsigned char x2[4];}ReadValue;
362 1 cs5045=0;
363 1 write_8bit(READ0);//send read command
364 1 write_8bit(FirstAddr);//send address
365 1 ReadValue.x2[0]=read_8bit();//read one byte
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 7
366 1 ReadValue.x2[1]=read_8bit();//read one byte
367 1 ReadValue.x2[2]=read_8bit();//read one byte
368 1 ReadValue.x2[3]=read_8bit();//read one byte
369 1 _nop_();
370 1 cs5045=1;
371 1 return(ReadValue.x1);
372 1 }
373
374 float read1_page_float4(unsigned char FirstAddr)
375 {
376 1 union{float x1;unsigned char x2[4];}ReadValue;
377 1 cs5045=0;
378 1 write_8bit(READ0);//send read command
379 1 write_8bit(FirstAddr);//send address
380 1 ReadValue.x2[0]=read_8bit();//read one byte
381 1 ReadValue.x2[1]=read_8bit();//read one byte
382 1 ReadValue.x2[2]=read_8bit();//read one byte
383 1 ReadValue.x2[3]=read_8bit();//read one byte
384 1 _nop_();
385 1 cs5045=1;
386 1 return(ReadValue.x1);
387 1 }
388
389
390 void wdt_init(void)
391 {
392 1 WDTREL=WDT_TIME;
393 1 WDT=1;
394 1 SWDT=1;
395 1 }
396
397 void wdt_refresh(void)
398 { //WatchDogTimer refresh function
399 1 WDT=1;
400 1 SWDT=1;
401 1 }
402
403 /*void output (unsigned int ad_value){
404 TMOD = 0x20;
405 TL1 = 0xe8;
406 TH1 = 0xe8;
407 TR1 = 1;
408 SCON = 0x40;
409 TI = 1;
410 // printf("The A/D value is %4.2fV. \n",(float)ad_value*5.0/1024);
411 }*/
412
413 /*//////////////////// functions for finding bit from message table/////*/
414 //******************************************************************************
415 //function: bit get_bit(unsigned char ModuleName,unsigned char BitNumber,
416 // unsigned char * BasePointer);
417 //description: thi function get the bit value from specified location of
418 // the seven row and eight line array such as MsgTrans[7][8].
419 //parameter: ModuleName---which module;BitNumber---bit location of the data block
420 // BasePointer---the pointer pointing to the base address.
421 //return: the bit value. |
422 //******************************************************************************
423 bit get_bit(unsigned char ModuleName,unsigned char BitNumber,unsigned char * BasePointer)
424 {
425 1 unsigned char char_v;
426 1 // ModuleName--;
427 1 char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(BitNumber>>3);
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 8
428 1 BasePointer += char_v;
429 1 while(BitNumber>=8)
430 1 {
431 2 BitNumber-=8;
432 2 }
433 1 if (*BasePointer & (unsigned char)(1<<BitNumber)) return 1;
434 1 else return 0;
435 1 }
436 //******************************************************************************
437 //function: void set_bit(unsigned char ModuleName,unsigned char BitNumber,bit value
438 // unsigned char * BasePointer);
439 //description: thi function set the bit value specified location of
440 // the seven row and eight line array such as MsgTrans[7][8].
441 //parameter: ModuleName---which module;BitNumber---bit location of the data block
442 // value---specified bit value;
443 // BasePointer---the pointer pointing to the base address.
444 //return: none. |
445 //******************************************************************************
446 void set_bit(unsigned char ModuleName,unsigned char BitNumber,bit value,unsigned char * BasePointer)
447 {
448 1 unsigned char char_v;
449 1 // ModuleName--;
450 1 char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(BitNumber>>3);
451 1 BasePointer += char_v;
452 1 while(BitNumber>=8)
453 1 {
454 2 BitNumber-=8;
455 2 }
456 1 if(value)
457 1 *BasePointer |= (unsigned char)(1<<BitNumber);
458 1 else
459 1 *BasePointer &= ~(unsigned char)(1<<BitNumber);
460 1 }
461 /////////////////????????????????????????//////////////////////////////////////////////
462 /////////////// 函数有问题///////////////////////////////////////////////////////
463 //****************************************************************************
464 //function: unsigned char get_byte(unsigned char ModuleName,unsigned char ByteNumber,
465 // unsigned char * BasePointer);
466 //description: thi function set the byte value from specified location of
467 // the seven row and eight line array such as MsgTrans[7][8].
468 //parameter: ModuleName---which module;ByteNumber---byte location of the data block
469 // value---specified byte value;
470 // BasePointer---the pointer pointing to the base address.
471 //return: none. |
472 //******************************************************************************
473 unsigned char get_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char * BasePointer)
474 {
475 1 unsigned char char_v;
476 1 // ModuleName--;
477 1 char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
478 1 BasePointer += char_v;
479 1 return(*BasePointer);
480 1 }
481
482 //******************************************************************************
483 //function: void set_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value
484 // unsigned char * BasePointer);
485 //description: thi function set the byte value from specified location of
486 // the seven row and eight line array such as MsgTrans[7][8].
487 //parameter: ModuleName---which module;ByteNumber---byte location of the data block
488 // value---specified byte value;
489 // BasePointer---the pointer pointing to the base address.
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 9
490 //return: none. |
491 //******************************************************************************
492
493 void set_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value,unsigned char * BasePo
-inter)
494 {
495 1 unsigned char char_v;
496 1 // ModuleName--;
497 1 char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
498 1 BasePointer += char_v;
499 1 *BasePointer=value;
500 1 }
501
502
503 //******************************************************************************
504 //function: unsigned char get_byte1(unsigned char ModuleName,unsigned char ByteNumber,
505 // unsigned char * BasePointer);
506 //description: thi function set the byte value from specified location of
507 // the seven row and eight line array such as MsgTrans[7][8].
508 //parameter: ModuleName---which module;ByteNumber---byte location of the data block
509 // value---specified byte value;
510 // BasePointer---the pointer pointing to the base address.
511 //return: none. |
512 //******************************************************************************
513
514 unsigned char get_byte1(unsigned char ModuleName,unsigned char ByteNumber,unsigned char * BasePointer)
515 {
516 1 unsigned char char_v;
517 1 // ModuleName--;
518 1 char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
519 1 BasePointer += char_v;
520 1 return(*BasePointer);
521 1 }
522
523 //******************************************************************************
524 //function: void set_byte1(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value
525 // unsigned char * BasePointer);
526 //description: thi function set the byte value from specified location of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -