📄 beacon.lst
字号:
452 1 uart_sendchar(link_status_1[i].address_R);
453 1 uart_sendchar(link_status_1[i].address_L);
454 1 uart_sendchar(link_status_1[i].average_ea);
455 1 uart_sendchar(link_status_1[i].average_eb);
456 1 uart_sendchar(link_status_1[i].success_rate);
457 1
458 1 }
459
460 /*=============================================================================
461
462 ******** Using timer1 as beacon timer *******
463
464 =============================================================================*/
465 void timer1_init(unsigned char interval, unsigned char count)
466 {
467 1 TMOD = (TMOD & 0x0F) | 0x10; /* Set Mode 2 (8 bit reload) 使用T0与串口*/
468 1 TAMOD = 0x00;
469 1
470 1 TH1 = interval; // count 185 times from 71 to 256
471 1 // = 50 us, Reload TL0 to count count_val clocks TH0 = 0x47 */
472 1 TL1 = 0; // In LPC922
473 1 inter1=TH1;
474 1
475 1 EX1 = 1; //<----------------开外部中断1
476 1 IT1 = 1; //<---------------- 外部中断下沿触发
477 1 ET1 = 1; /* Enable Timer 0 Interrupts */
478 1 TR1 = 1; /* Start Timer 0 Running */
479 1 EA = 1; /* Global Interrupt Enable */
480 1
481 1 count1_reload = count;
482 1 tm1_count = count;
483 1
C51 COMPILER V7.50 BEACON 11/12/2005 01:18:45 PAGE 9
484 1 // Agilent beacon timer
485 1 beacon_timer_enable = 0;
486 1 beacon_rx_timer_enable = 0;
487 1 }
488
489
490 /*=============================================================================*/
491 // Timer 1 Interrupt Service Routine.
492
493 // Interrupt is generated everytime timer1 overflows.
494 /*=============================================================================*/
495
496 void timer1_ISR (void) interrupt 3
497 {
498 1 TH1 = inter1; // reload timer1 1ms
499 1 TL1 = 0;
500 1
501 1 if (tm1_count-- == 0)
502 1 {
503 2 tm1_count = count1_reload;
504 2
505 2 // Agilent beacon tx timer
506 2 if (beacon_timer_enable == 1)
507 2 {
508 3 beacon_timer_count++;
509 3 if (beacon_timer_count == beacon_timer_val)
510 3 {
511 4 beacon_timer_count = 0;
512 4 beacon_timer_proc();
513 4 }
514 3 }
515 2
516 2 // Agilent beacon rx timer
517 2 if (beacon_rx_timer_enable == 1)
518 2 {
519 3 beacon_rx_timer_count++;
520 3 if (beacon_rx_timer_count == beacon_rx_timer_val)
521 3 {
522 4 beacon_rx_timer_count = 0;
523 4 beacon_rx_timer_proc();
524 4 }
525 3 }
526 2 }
527 1 }
528
529 /* Agilent beacon timer */
530 void setup_beacon_timer(unsigned char t, void (*proc)())
531 {
532 1 beacon_timer_val = t;
533 1 beacon_timer_proc = proc;
534 1 beacon_timer_count = 0;
535 1
536 1 beacon_timer_enable = 1;
537 1 }
538
539 /* Agilent beacon timer */
540 void setup_beacon_rx_timer(unsigned char t, void (*proc)())
541 {
542 1 beacon_rx_timer_val = t;
543 1 beacon_rx_timer_proc = proc;
544 1 beacon_rx_timer_count = 0;
545 1
C51 COMPILER V7.50 BEACON 11/12/2005 01:18:45 PAGE 10
546 1 beacon_rx_timer_enable = 1;
547 1 }
548
549 void send_table_frame()
550 {
551 1 unsigned int i,j;
552 1 // send to power line
553 1 uart_sendchar(0x77);
554 1 for(i=0;i<18;i++) uart_sendchar(plc_frame[i]);
555 1
556 1 sync_sendchar(BUFFER_WR_TXBUF);
557 1 send_block(plc_frame, 18);
558 1 send();
559 1 while(TX_BUSY == 0); // wait tx finish
560 1
561 1 RXOK = 0;
562 1 for(i=0;i<350;i++)
563 1 for(j=0;j<500;j++);
564 1 RXOK = 1;
565 1 RXOK = 0;
566 1 for(i=0;i<350;i++)
567 1 for(j=0;j<500;j++);
568 1 RXOK = 1;
569 1 }
570
571 void send_table()
572 {
573 1 // Totally the table will send out using (15*5)/13 = 75/13 = 6 frames.
574 1
575 1 unsigned char local_address_R, local_address_L, i, j;
576 1
577 1 local_address_R = METER_ADDR[0];
578 1 local_address_L = METER_ADDR[1];
579 1
580 1 plc_frame[0]=local_address_R;
581 1 plc_frame[1]=local_address_L;
582 1 plc_frame[2]=0x00;
583 1 plc_frame[3]=0x00;
584 1
585 1 // send first frame
586 1 plc_frame[4]=0xF0;
587 1
588 1 i = 0;
589 1 j = 4;
590 1 while(i<75)
591 1 {
592 2 if (++j>17)
593 2 {
594 3 send_table_frame();
595 3 j = 4;
596 3 plc_frame[4]++;
597 3 }
598 2 else plc_frame[j] = *(int code *)(&link_status_1[0].address_R+i++);
599 2
600 2 }
601 1 while(j ++ < 18) plc_frame[j] = 0xaa;
602 1 send_table_frame();
603 1 }
604
605 void clear_table()
606 {
607 1 uchar i;
C51 COMPILER V7.50 BEACON 11/12/2005 01:18:45 PAGE 11
608 1
609 1 // use all 00 to pad the table.
610 1 for(i=0;i<15;i++)
611 1 {
612 2 write_table(i,0,0,0,0,0);
613 2 }
614 1 }
615
616 /*===============================disable watchdog ==================================*/
617
618 void disable_watchdog()
619 {
620 1 EA = 0;
621 1 ACC = WDCON; //<------读取WDT控制寄存器
622 1 ACC = ACC & 0x00; //<------置位ACC.2,准备启动WDT
623 1 // WDL = 0xff; //<------设置8位倒计时初值
624 1 WDCON = ACC; //<------启动WDT
625 1 WFEED1 = 0xA5; //<------清第一部分
626 1 WFEED2 = 0x5A; //<------清第二部分
627 1 EA = 1;
628 1 }
629
630 /*=============================== send to LED ==================================*/
631 //
632 //void send_to_LED()
633 //{
634 // unsigned char send_to_LED[8];
635 //
636 // EA = 0; // disable Interrupt
637 // send_to_LED[0] = 0xFF;
638 // send_to_LED[1] = thres_ea; // thres1
639 // send_to_LED[2] = read_reg(0xF6); // thres2
640 // send_to_LED[3] = read_reg(0XEA); // ea
641 // send_to_LED[4] = read_reg(0XEB); // eb
642 // send_to_LED[5] = read_reg(0xFE); // AGC value
643 // send_to_LED[6] = read_reg(0xF7); // FIR
644 // send_to_LED[7] = 0x00; // automatic control
645 //
646 // EA = 1; // enable interrupt
647 //
648 // uart_sendblock(send_to_LED, 8);
649 //}
650
651 //void send_to_LED()
652 //{
653 // unsigned char send_to_LED[6];
654 //
655 // EA = 0; // disable Interrupt
656 // send_to_LED[0] = 0xEA;
657 // send_to_LED[1] = read_reg(0XEA); // ea
658 // send_to_LED[2] = thres_ea; // thres1
659 // send_to_LED[3] = read_reg(0XEB); // eb
660 // send_to_LED[4] = read_reg(0xF6); // thres2
661 // send_to_LED[5] = 0xEB;
662 //
663 // EA = 1; // enable interrupt
664 //
665 // uart_sendblock(send_to_LED, 6);
666 //}
MODULE INFORMATION: STATIC OVERLAYABLE
C51 COMPILER V7.50 BEACON 11/12/2005 01:18:45 PAGE 12
CODE SIZE = 1764 ----
CONSTANT SIZE = 77 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 9 23
IDATA SIZE = 6 ----
BIT SIZE = 2 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -