Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

if else pls help.. i have a doubt on my code with this....

Status
Not open for further replies.

mldt28

Newbie level 6
Newbie level 6
Joined
Feb 20, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,401
is this correct????? does it affect timing of fetching data??
is there any other ways to combine this two without wasting time??
im using a AC POWER ANALYZER that transmits data every second.
PIC16f4550 is my controller...

Code:
while(1)
   {
     while(1)
     {
          do{ dat = Soft_Uart_Read(&err); }while(err);
          if(dat == 'O'){ break; }
          if((mypbuff == 0) && (dat != 'I')){ continue; }
          mybuff[mypbuff++] = dat;
          if(mypbuff == 53)
          {
               ptr = strtok(mybuff, ",");     //mybuff here contains the string from power analyzer module
               ptr = strtok(0, ",");          // ptr now contains string of watts
               count++;
               total += wattsec_;
               wattsec_ = atof(ptr);
               kw = wattsec_/1000;
               kwh = kw/3600;
               kwhrate = kwh * 4.0740;
               kwhsum += kwh;

               sprintf(kwdata, "%.2f", kw);
               //FloatToStr(kw,kwdata);
               sprintf(kwhdata, "%.2f", kwhsum);
               //FloatToStr(kwhsum,kwhdata);


                  if((count % 30) == 0){
                  ave = total / 1000;
                  ave2 = ave  / 3600;           //to kph /30 secs            // recode pagconvert**********************************************
                  sprintf(extra, "%.5f", ave2); // to GSM modem
                  //FloatToStr(ave2, extra);
                                                  // send to gsm program*************************************************************
                  ave   = 0;
                  ave2  = 0;
                  total = 0;
                  count = 0;
                  delay_ms(2000);

               }
               else if((count2 % 60) == 0){
                  rate += kwhrate;
                  sprintf(kwhratesum, "%.5f", rate);


                  rate = 0;
                  count2 = 0;
                  delay_ms(2000);
               }



               
               
               Lcd_Cmd(_LCD_CLEAR);
               Lcd_Out(1,1, "KW: ");
               Lcd_Out(1,5, kwdata);

               Lcd_Out(2,1, "KW/hour: ");
               Lcd_Out(2,10, kwhdata);

               Lcd_Out(3,1, "BILL: ");
               Lcd_Out(3,7, kwhratesum);
               Uart1_Write_Text(kwdata);
               
               Lcd_Out(4,1, "KWH/30SEC: ");
               Lcd_Out(4,12, extra);
               mypbuff = 0;
               break;
          }
     }
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top