⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beacon.lst

📁 此源码为商用的电力抄表系统的从机端源程序。通过电力载波模块
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   BEACON                                                                11/12/2005 01:18:45 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE BEACON
OBJECT MODULE PLACED IN beacon.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE beacon.c ROM(COMPACT) OPTIMIZE(9,SPEED) BROWSE MODP2 DEBUG OBJECTEXTEND PRE
                    -PRINT

line level    source

   1          /* *****************************************************************************
   2                                           Becaon send and process module. Used for system debug and test
   3           *******************************************************************************/
   4          #include "absacc.h"
   5          #include "stdlib.h"
   6          #include "beacon.h"
   7          #include "timer.h"
   8          #include "plc.h"
   9          #include "sart.h"
  10          #include "wr_flash.h"
  11          #define uint unsigned int
  12          #define uchar unsigned char
  13          
  14          #define  BUFFER_WR_TXBUF        0x7F
  15          #define  BEACON_FRAME 0xFF
  16          #define  BEACON_TABLE_NM           15
  17          #define  BEACON_FRAME_COUNT        10
  18          #define  BEACON_RX_FRAME_COUNT 10
  19          
  20          #define  BEACON_INTERVAL        100     // * 10ms
  21          #define  BEACON_RX_INTERVAL     230     // * 10ms
  22          
  23          extern code uchar  METER_ADDR[6];
  24          uchar  code  reg_setting[2]; // reg_setting[0]: Gain, reg_setting[1]: amplitue
  25          //#define  self_address_R 0x00 
  26          //#define  self_address_L 0x01
  27          
  28          uchar tm1_count, count1_reload; 
  29          uchar inter1;
  30          
  31          void (*beacon_timer_proc)();   // Agilent beacon timer 
  32          idata uchar beacon_timer_count;
  33          idata uchar beacon_timer_val;
  34          bit beacon_timer_enable;
  35          
  36          void (*beacon_rx_timer_proc)();   // Agilent beacon timer 
  37          idata uchar beacon_rx_timer_count;
  38          idata uchar beacon_rx_timer_val;
  39          bit beacon_rx_timer_enable;
  40          
  41          void delay(uint cnt);
  42          
  43          
  44          /* transmit beacon contiously from beacon mode PLM, beacon sequence number increase from 0 to beacon_num
  45            beacon_interval is the timer to control interval between two beacon                                                           */
  46          
  47          
  48          extern idata uchar plc_frame[18];
  49          idata char beacon_frame_count,beacon_rx_frame_count;
  50          code struct link_status link_status_1[15];
  51          
  52          extern idata uchar thres_ea;
  53          
  54          void plc_tx_beacon();
C51 COMPILER V7.50   BEACON                                                                11/12/2005 01:18:45 PAGE 2   

  55          
  56          void beacon_time_out();
  57          void enable_beacon_timer();
  58          void disable_beacon_timer(void);
  59          
  60          void beacon_rx_time_out();
  61          void enable_beacon_rx_timer();
  62          void disable_beacon_rx_timer(void);
  63          
  64          //void write_table(unsigned char i, unsigned char ave_ea, unsigned char ave_eb);
  65          
  66          void write_table(uchar i, uchar add_R, uchar add_L, uchar ave_ea, uchar ave_eb,uchar succ_rate);
  67          
  68          // beacon_interval * 10ms is the real interval between beacon
  69          void send_beacon()
  70          {
  71   1         uchar i, k;
  72   1         setup_beacon_timer(BEACON_INTERVAL, beacon_time_out);
  73   1         beacon_frame_count = 0;
  74   1         enable_beacon_timer();
  75   1      
  76   1         while(beacon_frame_count < BEACON_FRAME_COUNT){;}
  77   1              
  78   1         disable_beacon_timer();
  79   1      
  80   1         // after finish tx beacon, keep on flashing RXOK to indicate this node has finish beacon transmission
  81   1         while(1)
  82   1         {
  83   2                      for (k=1; k<=5; k++)
  84   2                      {
  85   3      //                      clr_wdt();
  86   3      
  87   3                              delay (50000);
  88   3                              delay (50000);
  89   3                              //brightening
  90   3                              for (i=1; i<=100; i++)  // define 100 steps
  91   3                              {
  92   4      //                              clr_wdt();
  93   4                                      Rxok = 0;       
  94   4                                      delay (i*100);
  95   4                                      Rxok = 1;
  96   4                                      delay (10100-i*100);
  97   4                              }
  98   3      
  99   3                              for (i=1; i<=50; i++)
 100   3                              {                               
 101   4      //                              clr_wdt();
 102   4                                      Rxok = 0;
 103   4                                      delay (10200-i*200);
 104   4                                      Rxok = 1;
 105   4                                      delay (i*200);
 106   4                              }
 107   3                      }
 108   2         }
 109   1      }
 110          
 111          void delay (uint cnt)
 112          {
 113   1        while (--cnt);
 114   1      }
 115          
 116          void beacon_time_out()
C51 COMPILER V7.50   BEACON                                                                11/12/2005 01:18:45 PAGE 3   

 117          {
 118   1      //       clr_wdt();
 119   1           disable_beacon_timer();
 120   1                      
 121   1           plc_tx_beacon();
 122   1               beacon_frame_count++;
 123   1               /* set up timer seconds again. */
 124   1           enable_beacon_timer();
 125   1      }
 126          
 127          void enable_beacon_timer(void)
 128          {
 129   1        beacon_timer_count = 0;
 130   1        beacon_timer_enable = 1;
 131   1      }
 132          
 133          void disable_beacon_timer(void)
 134          {
 135   1        beacon_timer_count = 0;
 136   1        beacon_timer_enable = 0;
 137   1      }
 138          
 139          /**************************************************************************************
 140                                                  Beacon
 141           **************************************************************************************/
 142          void plc_tx_beacon(void)
 143          {
 144   1              uchar i;
 145   1              uchar self_address_R,self_address_L;
 146   1              
 147   1              self_address_R = METER_ADDR[0]; 
 148   1              self_address_L = METER_ADDR[1];
 149   1               
 150   1              plc_frame[0] = self_address_R; // local address high byte
 151   1              plc_frame[1] = self_address_L; // local address low byte
 152   1              plc_frame[2] = self_address_R; // local address high byte
 153   1              plc_frame[3] = self_address_L; // local address low byte
 154   1              
 155   1              plc_frame[4] = 0xcc; // beacon command
 156   1              plc_frame[5] = 0xBC; // padding
 157   1              plc_frame[6] = beacon_frame_count;
 158   1      
 159   1              for(i=7;i<18;i++)
 160   1              {plc_frame[i] = 0xBC;}
 161   1      
 162   1              sync_sendchar(BUFFER_WR_TXBUF);
 163   1              send_block(plc_frame, 18);
 164   1      
 165   1              send();
 166   1              while (TX_BUSY == 0);  // wait tx finish
 167   1      }
 168          
 169          /**************************************************************************************
 170                                                  Receive Beacon Frame and process, record Ea and Eb, Save to Flash
 171           **************************************************************************************/
 172          
 173          void beacon_rx_process()
 174          {
 175   1              unsigned char local_address_R, local_address_L;
 176   1              unsigned char average_ea , average_eb;
 177   1              unsigned char i,j,min_ea, wr_ea_index;
 178   1              bit flag_first_frame; // when the first frame come in, = 1, average_ea  and average_eb do not average
C51 COMPILER V7.50   BEACON                                                                11/12/2005 01:18:45 PAGE 4   

 179   1                                                        // after that, each frame come in, average Ea and Eb with last value.
 180   1      
 181   1              unsigned char success_received_frame;
 182   1      //      unsigned char beacon_reply_frame[18];
 183   1              
 184   1              local_address_R = METER_ADDR[0];
 185   1              local_address_L = METER_ADDR[1];
 186   1      
 187   1              average_ea = 0;
 188   1              average_eb = 0;
 189   1              beacon_rx_frame_count = 0;
 190   1      
 191   1              setup_beacon_rx_timer(BEACON_RX_INTERVAL, beacon_rx_time_out);
 192   1              disable_beacon_rx_timer();
 193   1          
 194   1              // for debug only
 195   1              uart_sendchar(0XFF);
 196   1              uart_sendchar(0XFF);
 197   1              uart_sendchar(0XFF);
 198   1              uart_sendchar(0XFF);
 199   1      
 200   1              for(i=0;i<BEACON_TABLE_NM;i++)
 201   1              {
 202   2                      uart_sendchar(link_status_1[i].address_R);
 203   2                      uart_sendchar(link_status_1[i].address_L);
 204   2                      uart_sendchar(link_status_1[i].average_ea);
 205   2                      uart_sendchar(link_status_1[i].average_eb);
 206   2                      uart_sendchar(link_status_1[i].success_rate); 
 207   2                      
 208   2              }
 209   1      
 210   1              uart_sendchar(reg_setting[0]);
 211   1              uart_sendchar(reg_setting[1]);
 212   1      
 213   1              // end of for debug
 214   1              while(1)
 215   1              {
 216   2                      if (plc_recved()) 
 217   2                      {
 218   3                              plc_getframe(plc_frame);         //* read  the frame in
 219   3      
 220   3                          if(!read_crc())
 221   3                              {
 222   4      
 223   4                                      RXOK = 0;
 224   4                                      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -