C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 1   


C51 COMPILER V9.51, COMPILATION OF MODULE EEPROM_METHOD
OBJECT MODULE PLACED IN eeprom_method.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe eeprom_method.c LARGE INCDIR(c:\SiLabs\MCU\Inc;..\inc) DB OT(9,SPEED)

line level    source

   1          
   2          
   3          #include "PROJECT_INCLUDES.H"
   4          
   5          
   6          #define I2C_SDA_PORT_DIGITAL_MODE                       {P0MDIN   |= P06_I2C_SDA;}
   7          #define I2C_SCL_PORT_DIGITAL_MODE                       {P0MDIN   |= P07_I2C_SCL;}
   8          
   9          
  10          #define I2C_SDA_PORT_PUSH_PULL_OUT_MODE         {P0MDOUT  |= P06_I2C_SDA;}
  11          #define I2C_SDA_PORT_OPEN_DRAIN_IN_MODE         {P0MDOUT  &=~P06_I2C_SDA;}
  12          
  13          #define I2C_SCL_PORT_PUSH_PULL_OUT_MODE         {P0MDOUT  |= P07_I2C_SCL;}
  14          #define I2C_SCL_PORT_OPEN_DRAIN_IN_MODE         {P0MDOUT  &=~P07_I2C_SCL;} 
  15          
  16          #define I2C_SDA_HIGH                                            {P0 |= P06_I2C_SDA;}
  17          #define I2C_SDA_LOW                                             {P0 &=~P06_I2C_SDA;}
  18          #define I2C_SCL_HIGH                                            {P0 |= P07_I2C_SCL;}
  19          #define I2C_SCL_LOW                                                     {P0 &=~P07_I2C_SCL;} 
  20          
  21          
  22          extern volatile void Delay_us(volatile U32 idata  dlycnt);
  23          extern volatile void I2C_SDA_PORT_OUTPUT(void);
  24          extern volatile void I2C_SDA_PORT_INPUT(void);
  25          
  26          extern U32 Grap_Unit1;
  27          /////////////////////////////////////////////////////////////////////////////////////
  28          // I2C
  29          /*xdata volatile unsigned char i2c_delay;
  30          
  31          #define I2C_D {i2c_delay = 1; while(--i2c_delay);}
  32          
  33          char I2C_put_byte(char x)
  34          {
  35                  char ack;
  36          
  37                  I2C_SDA_PORT_PUSH_PULL_OUT_MODE;
  38          
  39                  pSDA = (x & 0x80) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  40                  pSDA = (x & 0x40) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  41                  pSDA = (x & 0x20) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  42                  pSDA = (x & 0x10) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  43                  pSDA = (x & 0x08) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  44                  pSDA = (x & 0x04) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  45                  pSDA = (x & 0x02) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  46                  pSDA = (x & 0x01) ? 1 : 0; pSCL = HIGH; I2C_D; pSCL = LOW; I2C_D;
  47          
  48                  SDA_IN(); I2C_D;
  49                  pSCL = 1; I2C_D; ack = pSDA; pSCL = 0; I2C_D;
  50                  SDA_OUT(); I2C_D;
  51                  
  52                  return ack;
  53          }
  54          
  55          char I2C_get_byte(char ack)
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 2   

  56          {
  57                  char x;
  58          
  59                  SDA_IN(); I2C_D;
  60                  pSCL = HIGH; I2C_D; x  = (pSDA) ? 0x80 : 0; pSCL = LOW; I2C_D;
  61                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x40 : 0; pSCL = LOW; I2C_D;
  62                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x20 : 0; pSCL = LOW; I2C_D;
  63                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x10 : 0; pSCL = LOW; I2C_D;
  64                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x08 : 0; pSCL = LOW; I2C_D;
  65                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x04 : 0; pSCL = LOW; I2C_D;
  66                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x02 : 0; pSCL = LOW; I2C_D;
  67                  pSCL = HIGH; I2C_D; x |= (pSDA) ? 0x01 : 0; pSCL = LOW; I2C_D;
  68          
  69                  SDA_OUT();  I2C_D;
  70                  pSDA = ack;
  71                  pSCL = 1; I2C_D; pSCL = 0; I2C_D;
  72          
  73                  return x;
  74          }*/
  75          /////////////////////////////////////////////////////////////////////////////////////
  76          
  77          
  78          
  79          /////////////////////////////////////////////////////////////////////////////////////
  80          // M24M02 EEPROM
  81          /*void M24M02_write_byte(unsigned long add, unsigned char x)
  82          {
  83                  unsigned char add_high;
  84          
  85                  add_high = (add >> 15) & 0x06;
  86          
  87                  I2C_start();
  88                  I2C_put_byte(M24M02_CHIP1_ADD | add_high);
  89                  I2C_put_byte((unsigned char)(add >> 8));
  90                  I2C_put_byte((unsigned char)(add));
  91                  I2C_put_byte(x);
  92                  I2C_stop();
  93          
  94                  Delay_us(10000);
  95          }
  96          
  97          unsigned char M24M02_read_byte(unsigned long add)
  98          {
  99                  unsigned char x;
 100                  unsigned char add_high;
 101          
 102                  add_high = (add >> 15) & 0x06;
 103          
 104                  I2C_start();
 105                  I2C_put_byte(M24M02_CHIP1_ADD | add_high);
 106                  I2C_put_byte((unsigned char)(add >> 8));
 107                  I2C_put_byte((unsigned char)(add));
 108          
 109                  I2C_start();
 110                  I2C_put_byte(M24M02_CHIP1_ADD | add_high | 0x01);
 111                  x = I2C_get_byte(I2C_NACK);
 112                  I2C_stop();
 113          
 114                  return x;
 115          }
 116          
 117          void M24M02_write_buff(unsigned long add, unsigned char *x, unsigned short len)
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 3   

 118          {
 119                  unsigned short i;
 120                  unsigned char  add_high;
 121          
 122                  add_high = (add >> 15) & 0x06;
 123          
 124                  I2C_start();
 125                  I2C_put_byte(M24M02_CHIP1_ADD | add_high);
 126                  I2C_put_byte((unsigned char)(add >> 8));
 127                  I2C_put_byte((unsigned char)(add));
 128          
 129                  for(i = 0; i < len; i++)
 130                          I2C_put_byte(x[i]);
 131          
 132                  I2C_stop();
 133          
 134                  Delay_us(10000);
 135          }
 136          
 137          
 138          void M24M02_read_buff(unsigned long add, unsigned char *x, unsigned short len)
 139          {
 140                  unsigned short i;
 141                  unsigned char  add_high;
 142          
 143                  add_high = (add >> 15) & 0x06;
 144          
 145                  I2C_start();
 146                  I2C_put_byte(M24M02_CHIP1_ADD | add_high);
 147                  I2C_put_byte((unsigned char)(add >> 8));
 148                  I2C_put_byte((unsigned char)(add));
 149          
 150                  for(i = 0; i < len; i++)
 151                  {
 152                          I2C_start();
 153                          I2C_put_byte(M24M02_CHIP1_ADD | add_high | 0x01);
 154                          x[i] = I2C_get_byte(I2C_NACK);
 155                          I2C_stop();
 156                  }
 157          
 158                  //I2C_start();
 159                  //I2C_put_byte(M24M02_CHIP1_ADD | add_high | 0x01);
 160                  //for(i = 1; i < len; i++)
 161                  //{
 162                  //      if(i == len - 1)
 163                  //              x[i] = I2C_get_byte(I2C_NACK);
 164                  //      else 
 165                  //              x[i] = I2C_get_byte(I2C_ACK);
 166                  //}
 167                  //I2C_stop();
 168          }*/
 169          /////////////////////////////////////////////////////////////////////////////////////
 170          
 171          
 172          
 173          /////////////////////////////////////////////////////////////////////////////////////
 174          xdata volatile CHEAD            ph;
 175          xdata volatile CHEAD_INFO       ph_info;
 176          xdata volatile CPOWERS          power;
 177          
 178          int get_head_info(void)
 179          {
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 4   

 180   1              volatile int                    i;
 181   1              volatile POWR_DATA      sWeek;
 182   1              
 183   1              for(i = 0; i < 4096; i += 8)
 184   1              {
 185   2                      sflash_fast_read(i, (unsigned char *)&ph, 1);
 186   2                      if(ph.flag == 0xff)break;
 187   2              }
 188   1      
 189   1              if(i >= 4096)
 190   1              { 
 191   2                      i = 0;
 192   2                      sflash_sector_erase(0, SECTOR_ERASE_DELAY);
 193   2              }
 194   1      
 195   1              i >>= 3;
 196   1              if(i)i--;
 197   1              else 
 198   1              {
 199   2                      // head area init
 200   2                      memset((void *)&ph, 0, sizeof(ph));
 201   2                      ph.flag = HEAD_FLAG;
 202   2                      ph.cur.point = DATA_BASE_ADD;
 203   2                      ph.cur.year = (unsigned char)(event1.years - 2000);
 204   2                      ph.cur.month = event1.output_month;
 205   2                      ph.cur.day = event1.output_days;
 206   2                      sflash_page_program(0, (unsigned char *)&ph, 8);
 207   2      
 208   2                      // power data area init
 209   2                      sWeek.Year = ph.cur.year;
 210   2                      sWeek.Month = ph.cur.month;
 211   2                      sWeek.Day = ph.cur.year;
 212   2                      Search_Weekly_SunDay(&sWeek, WEEK_);
 213   2      
 214   2                      memset((void *)&power, 0xff, POWER_DATA_LENGTH);
 215   2                      power.flag = POWER_FLAG;
 216   2                      power.year  = ph.cur.year;
 217   2                      power.month = ph.cur.month;
 218   2                      power.day   = ph.cur.day;
 219   2                      power.week  = sWeek.Week;
 220   2                      sflash_page_program(ph.cur.point, (unsigned char *)&power, 5);
 221   2      
 222   2                      ph_info.idx = 0;
 223   2      
 224   2                      //printf("@@headinit ");
 225   2                      return 0;
 226   2              }
 227   1      
 228   1              //printf("@@head %d ", i);
 229   1              sflash_fast_read(i<<3, (unsigned char *)&ph, 8);
 230   1              ph_info.idx = i;
 231   1      
 232   1              return i;
 233   1      }
 234          
 235          void put_head_info(void)
 236          {
 237   1              ph_info.idx++;
 238   1      
 239   1              if((ph_info.idx<<3) >= 4096)
 240   1              { 
 241   2                      ph_info.idx = 0;
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 5   

 242   2                      sflash_sector_erase(0, SECTOR_ERASE_DELAY);
 243   2              }
 244   1              sflash_page_program(ph_info.idx<<3, (unsigned char *)&ph, 8);
 245   1      }
 246          void Read_PowerInfomation(void)
 247          {
 248   1              get_head_info();
 249   1      
 250   1              if(ph.flag != HEAD_FLAG)
 251   1              {
 252   2                      sflash_bulk_erase();
 253   2                      get_head_info();
 254   2              }
 255   1      }
 256          
 257          unsigned long get_eeprom_address(CPOWERS_AUG *p, char kind)
 258          {
 259   1              volatile unsigned short  rep = 2044;
 260   1              volatile unsigned char   sbuff[6] = {0}, test;
 261   1              volatile unsigned long  address;
 262   1      
 263   1              if(!p->month || p->month > 12) return 0;
 264   1              if(!p->day   || p->day   > 31) return 0;
 265   1      
 266   1              address = ph.cur.point;
 267   1      
 268   1              while(--rep)
 269   1              {
 270   2                      address -= POWER_DATA_LENGTH;
 271   2      
 272   2                      if(address < DATA_BASE_ADD)
 273   2                              address = LAST_FIELD_ADDRESS;
 274   2      
 275   2                      sflash_fast_read(address, sbuff, 5);
 276   2      #if 1     // for debugging 
 277   2                      test=sbuff[0];         // power flag A0
 278   2                      test=sbuff[1];         //   year
 279   2                      test=sbuff[2];         //   month
 280   2                      test=sbuff[3];         //  day
 281   2                      test=sbuff[4];         // week 
 282   2                      test=sbuff[5];
 283   2                      test=p->year;
 284   2                      test=p->month;
 285   2                      test=p->day ;
 286   2      #endif 
 287   2      #if 1     // for testing OK
 288   2                      if(sbuff[0] != POWER_FLAG)
 289   2                              #if 0  // 저장되지 않은 데이터의 경우 데이터가 없으면 그냥 0으로 return 한다 그래서 저장되지 않을  경우
             -를 대비하여 addr 를 return 한다. 
                                      return 0;
                                      #else
 292   2                              return address;
 293   2                              #endif
 294   2      #endif 
 295   2                      if( sbuff[1] == p->year  && \
 296   2                              sbuff[2] == p->month && \
 297   2                              sbuff[3] == p->day   && \
 298   2                              kind     == DAY_K)
 299   2                      {
 300   3                              return address;
 301   3                      }
 302   2      
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 6   

 303   2                      if( sbuff[1] == p->year  && \
 304   2                              sbuff[4] == p->week  && \
 305   2                              kind     == WEEK_K)
 306   2                      {
 307   3                              return address;
 308   3                      }
 309   2      
 310   2                      if( sbuff[1] == p->year  && \
 311   2                              sbuff[2] == p->month && \
 312   2                              kind     == MONTH_K)
 313   2                      {
 314   3                              return address;
 315   3                      }
 316   2              }
 317   1              return 0;
 318   1      }
 319          
 320          void head_check(CPOWERS_AUG *p)
 321          {
 322   1              char w_flag = 0;
 323   1      
 324   1              /*if(!ph.cur.year && !ph.cur.month && !ph.cur.day)
 325   1              {
 326   1                      ph.cur.year = p->year;
 327   1                      ph.cur.month = p->month;
 328   1                      ph.cur.day = p->day;
 329   1                      w_flag = 1;
 330   1              }*/
 331   1      
 332   1              if(!(ph.cur.year  == p->year  &&        \
 333   1                       ph.cur.month == p->month &&    \
 334   1                       ph.cur.day   == p->day))
 335   1              {
 336   2                      ph.cur.year = p->year;
 337   2                      ph.cur.month = p->month;
 338   2                      ph.cur.day = p->day;
 339   2      
 340   2                      ph.cur.point += POWER_DATA_LENGTH;
 341   2      
 342   2                      if(ph.cur.point >= MAX_ADDRESS)
 343   2                              ph.cur.point = DATA_BASE_ADD;
 344   2      
 345   2                      memset((void *)&power, 0xff, POWER_DATA_LENGTH);
 346   2                      power.flag = POWER_FLAG;
 347   2                      power.year  = p->year;
 348   2                      power.month = p->month;
 349   2                      power.day   = p->day;
 350   2                      power.week  = p->week;
 351   2                      sflash_page_program(ph.cur.point, (unsigned char *)&power, 5);
 352   2      
 353   2                      w_flag = 1;
 354   2              }
 355   1      
 356   1              if(w_flag)put_head_info();
 357   1      }
 358          
 359          int PutEnergyData_OneHour(CPOWERS_AUG *p)
 360          {
 361   1              volatile unsigned long address, x;
 362   1      
 363   1              if(p->hour >= 24) return 0;
 364   1              if(p->channel_num >= MAX_CHANNEL)return 0;
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 7   

 365   1      
 366   1              DATA_READ(ph.cur.point);
 367   1      
 368   1              /*if(!power.year && !power.month && !power.day)
 369   1              {
 370   1                      power.year = p->year;
 371   1                      power.month = p->month;
 372   1                      power.day = p->day;
 373   1                      power.week = p->week;
 374   1              }*/
 375   1      
 376   1              if(!(power.year  == p->year  && \
 377   1                       power.month == p->month &&     \
 378   1                       power.day   == p->day))
 379   1              {
 380   2                      //printf("head_check()  ");
 381   2                      head_check(p);
 382   2              }
 383   1      
 384   1              power.value[p->hour][p->channel_num] = p->power;
 385   1      
 386   1              address = ph.cur.point + 64 + (p->hour*40) + (p->channel_num * 4);
 387   1              sflash_page_program(address, (unsigned char *)&p->power, 4);
 388   1              sflash_fast_read   (address, (unsigned char *)&x, 4);
 389   1      
 390   1      
 391   1      //SRAM 삭제 부분2014.04.12
 392   1              //printf("Put%05ld  ", x);
 393   1      
 394   1              //if(p->power != x)
 395   1              //{
 396   1                      //printf("sram op ");
 397   1              //      DATA_FLASH_WRITE(ph.cur.point);
 398   1              //}
 399   1      
 400   1      //SRAM 삭제 부분2014.04.12
 401   1      
 402   1              flash_next_sector_used_check(ph.cur.point);
 403   1      
 404   1              return 1;
 405   1      }
 406          
 407          int GetEnergyDataOneHour(CPOWERS_AUG *p)
 408          {
 409   1              volatile unsigned long address;
 410   1              
 411   1              if(p->month >  12)return 0;
 412   1              if(p->day   >  31)return 0;
 413   1              if(p->hour  >= 24)return 0;
 414   1              if(p->channel_num >= MAX_CHANNEL)return 0;
 415   1      
 416   1      
 417   1              if( ph.cur.year  == p->year  && \
 418   1                      ph.cur.month == p->month &&     \
 419   1                      ph.cur.day   == p->day)
 420   1              {
 421   2                      DATA_READ(ph.cur.point);
 422   2                      if(power.value[p->hour][p->channel_num] == 0xffffffff)
 423   2                              p->power = 0;
 424   2                      else
 425   2                              p->power = power.value[p->hour][p->channel_num];
 426   2              }else
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 8   

 427   1              {
 428   2                      address = get_eeprom_address(p, DAY_K);
 429   2      
 430   2                      if(!address)return 0;
 431   2      
 432   2                      DATA_READ(address);
 433   2      
 434   2                      if(power.value[p->hour][p->channel_num] == 0xffffffff)
 435   2                              p->power = 0;
 436   2                      else
 437   2                              p->power = power.value[p->hour][p->channel_num];
 438   2              }
 439   1              //printf("\n Hour%05ld  ", p->power);
 440   1              ///printf("\n OneHour = %ld  ", p->power);
 441   1              return 1;
 442   1      }
 443          
 444          int GetEnergyDataOneDay(CPOWERS_AUG *p)
 445          {
 446   1              volatile char                   i;
 447   1              volatile unsigned long  address;
 448   1              volatile unsigned long  powerDay = 0;
 449   1      
 450   1              if(p->month >  12)return 0;
 451   1              if(p->day   >  31)return 0;
 452   1              if(p->channel_num >= MAX_CHANNEL)return 0;
 453   1      
 454   1              #if 1
 455   1              if( ph.cur.year  == p->year  && \
 456   1                      ph.cur.month == p->month &&     \
 457   1                      ph.cur.day   == p->day)
 458   1              {
 459   2                      DATA_READ(ph.cur.point);
 460   2              }else
 461   1              {
 462   2                      address = get_eeprom_address(p, DAY_K);
 463   2                      if(!address)return 0;
 464   2                      DATA_READ(address);
 465   2              }
 466   1              #else
                      DATA_READ(ph.cur.point);
                      #endif
 469   1              
 470   1              for(i = 0; i < HOURS; i++)
 471   1              { 
 472   2                      if(power.value[i][p->channel_num] != 0xffffffff)
 473   2                      {
 474   3                              powerDay += power.value[i][p->channel_num];
 475   3                      }
 476   2              }
 477   1              power.sum_onehour[p->channel_num]=powerDay;   // store energy one day
 478   1              p->power = powerDay;
 479   1              //printf("\n Day%05ld  ", p->power);
 480   1      ///     printf("\n Day = %ld  ", p->power);
 481   1      
 482   1              return 1;
 483   1      }
 484           // thhan 0825
 485          int GetEnergyDataPeakOfWeek(CPOWERS_AUG *p)
 486          {
 487   1              volatile char i,j;
 488   1              volatile unsigned long address;
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 9   

 489   1              volatile unsigned long powerDay = 0;
 490   1              //U8 volatile  Dsp_Level1, test;
 491   1              //volatile  U32  test2;
 492   1              CPOWERS_AUG *temp;
 493   1              
 494   1              if(p->month > 12)return 0;
 495   1              if(p->channel_num >= MAX_CHANNEL)return 0;
 496   1      
 497   1      
 498   1              DATA_READ(ph.cur.point);
 499   1      
 500   1              if( power.year == p->year  &&   power.week == p->week)
 501   1              {
 502   2                      address = ph.cur.point;
 503   2              }else
 504   1              {
 505   2                      address = get_eeprom_address(p, WEEK_K);
 506   2                      if(!address)return 0;
 507   2              }
 508   1      
 509   1              temp = p;
 510   1              
 511   1              for(j=0;j<7;j++) 
 512   1              {
 513   2                      DATA_READ(address);
 514   2                      powerDay =0; 
 515   2      
 516   2                      for(i = 0; i < HOURS; i++)
 517   2                              if(power.value[i][p->channel_num] != 0xffffffff)
 518   2                              {
 519   3                                      powerDay += power.value[i][p->channel_num];
 520   3                                      ///printf("\n >>>>>>> day=%d, power= %ld, channel_num =%d  ", (U16)power.day, (U32)powerDay, (U16)p->c
             -hannel_num);
 521   3                              }
 522   2      
 523   2                              if(powerDay > Search_Week_Peak_Power[p->channel_num]) 
 524   2                              {
 525   3                                      Search_Week_Peak_Power[p->channel_num] = powerDay;
 526   3                              ///printf("\n ====> GetEnergyDataOneWeek1 powerDay= %ld, Week Peak Power =%ld  ", (U32)powerDay, 
             -Search_Week_Peak_Power[p->channel_num]);
 527   3                              }
 528   2      
 529   2                      address -= POWER_DATA_LENGTH;
 530   2                      if(address < DATA_BASE_ADD)
 531   2                              address = LAST_FIELD_ADDRESS;
 532   2              }
 533   1              
 534   1              return 1;
 535   1      }
 536          
 537          int GetEnergyDataOneWeek(CPOWERS_AUG *p)
 538          {
 539   1              volatile char rep = 7, i;
 540   1              volatile unsigned long address;
 541   1              volatile unsigned long powerWeek = 0;
 542   1      
 543   1              if(p->month > 12)return 0;
 544   1              if(p->channel_num >= MAX_CHANNEL)return 0;
 545   1      
 546   1      
 547   1              DATA_READ(ph.cur.point);
 548   1              #if 1
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 10  

 549   1              if( power.year == p->year  &&   \
 550   1                      power.week == p->week)
 551   1              {
 552   2                      address = ph.cur.point;
 553   2              }else
 554   1              {
 555   2                      address = get_eeprom_address(p, WEEK_K);
 556   2                      if(!address)return 0;
 557   2              }
 558   1              #else
                      address = ph.cur.point;
                      #endif
 561   1              while(rep--)
 562   1              {
 563   2                      DATA_READ(address);
 564   2      
 565   2                      if(!(power.year == p->year && power.week == p->week))
 566   2                              break;
 567   2      
 568   2                      for(i = 0; i < HOURS; i++)
 569   2                              if(power.value[i][p->channel_num] != 0xffffffff)
 570   2                                      powerWeek += power.value[i][p->channel_num];
 571   2      
 572   2                      address -= POWER_DATA_LENGTH;
 573   2                      if(address < DATA_BASE_ADD)
 574   2                              address = LAST_FIELD_ADDRESS;
 575   2              }
 576   1              p->power = powerWeek;
 577   1              //printf("\n Day%05ld  ", p->power);
 578   1      ///     printf("\n week = %ld  ", p->power);
 579   1              return 1;
 580   1      }
 581          
 582          
 583          int GetEnergyDataOneMonth(CPOWERS_AUG *p)
 584          {
 585   1              volatile char rep = 31, i;
 586   1              volatile unsigned long address;///,test;
 587   1              volatile unsigned long powerMonth = 0;
 588   1      
 589   1              if(p->month > 12) return 0;
 590   1              if(p->channel_num >= MAX_CHANNEL) return 0;
 591   1      
 592   1              DATA_READ(ph.cur.point);
 593   1              if( power.year  == p->year  &&  \
 594   1                      power.month == p->month)
 595   1              {
 596   2                      address = ph.cur.point;
 597   2              }else
 598   1              {
 599   2                      address = get_eeprom_address(p, MONTH_K);
 600   2                      if(!address)return 0;
 601   2              }
 602   1      
 603   1              while(rep--)
 604   1              {
 605   2                      DATA_READ(address);
 606   2      
 607   2                      if(!(power.year == p->year && power.month == p->month))
 608   2                              break;
 609   2      
 610   2                      for(i = 0; i < HOURS; i++)
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 11  

 611   2                              if(power.value[i][p->channel_num] != 0xffffffff)
 612   2                                      {
 613   3                                      ///test=power.value[i][p->channel_num];
 614   3                                      powerMonth += power.value[i][p->channel_num];
 615   3                                      }
 616   2                      address -= POWER_DATA_LENGTH;
 617   2      
 618   2                      if(address < DATA_BASE_ADD)
 619   2                              address = LAST_FIELD_ADDRESS;
 620   2              }
 621   1      
 622   1              p->power = powerMonth;
 623   1      ///     printf("\n Month = %ld  ", p->power);
 624   1      
 625   1              return 1;
 626   1      }
 627          
 628          int GetEnergyDataOneMonthFromToday(CPOWERS_AUG *p)
 629          {
 630   1              volatile char rep = 31, i;
 631   1              volatile unsigned long address;///,test;
 632   1              volatile unsigned long powerMonth = 0;
 633   1      
 634   1              if(p->month > 12) return 0;
 635   1              if(p->channel_num >= MAX_CHANNEL) return 0;
 636   1      
 637   1              DATA_READ(ph.cur.point);
 638   1              
 639   1              if( power.year  == p->year  &&  power.month == p->month)
 640   1              {
 641   2                      address = ph.cur.point;
 642   2              }else
 643   1              {
 644   2                      address = get_eeprom_address(p, MONTH_K);
 645   2                      if(!address)
 646   2                      {
 647   3                              return 0;
 648   3                      }
 649   2              }
 650   1      
 651   1              while(rep--)
 652   1              {
 653   2                      DATA_READ(address);
 654   2      
 655   2                      ///if(!(power.year == p->year && power.month == p->month))
 656   2                      ///     break;
 657   2      
 658   2                      for(i = 0; i < HOURS; i++)
 659   2                              if(power.value[i][p->channel_num] != 0xffffffff)
 660   2                              {
 661   3                                      powerMonth += power.value[i][p->channel_num];
 662   3                              }
 663   2                      address -= POWER_DATA_LENGTH;
 664   2      
 665   2                      if(address < DATA_BASE_ADD)
 666   2                      {
 667   3                              address = LAST_FIELD_ADDRESS;
 668   3                      }
 669   2              }
 670   1      
 671   1              p->power = powerMonth;
 672   1              //printf("\n Month = %ld  ", p->power);
C51 COMPILER V9.51   EEPROM_METHOD                                                         01/26/2016 23:34:27 PAGE 12  

 673   1      
 674   1              return 1;
 675   1      }
 676          /////////////////////////////////////////////////////////////////////////////////////
 677          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3468    ----
   CONSTANT SIZE    =      6    ----
   XDATA SIZE       =   1034     118
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
