Exemplo n.º 1
0
void blink(uint32_t delay, int num_blinks, int pls_update_readings) {
    uint32_t ctr;
    while(num_blinks--) {
        LED_PIN = 1;
        for(ctr = 0; ctr < delay; ++ctr) {
            if (pls_update_readings)
                update_readings();
        }
        LED_PIN = 0;
        for(ctr = 0; ctr < delay; ++ctr) {
            if (pls_update_readings)
                update_readings();
        }
    }
}
Exemplo n.º 2
0
void poll_ok(void)
{  
   if(timer_ok>1520)  //1955 for 5min
   {
      okst=0;
      output_high(LED_WARNING);
      update_readings();
      
   }
   else
   {
      okst=1;
      output_low(LED_WARNING);
      update_readings();
      
   }
   
}
Exemplo n.º 3
0
/************************************************************************
*  Main Program  *****  Programa Principal                              *
************************************************************************/
void main()
{

   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DIV_BY_16,0xFF,16);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   setup_adc( ADC_OFF );

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT1);
   enable_interrupts(global);
   

   str_init(print_date);
   str_init(print_time);
   
   
   
   
   
   set_timer1(0);
   
   init_ext_eeprom();
   ds1307_init();
   glcd_init(ON);    

   

   readconfig();

      
  

   draw_sect();

   while (1)
   { 
      
      
      
      if (firstrun==255)
      {
         glcd_fillscreen(OFF);
         glcd_loadscreen();
         glcd_showlogo();
         delay_ms(1500);
         menu_mainmenu();
         firstrun = 0;
         write_eeprom(0x00, firstrun);
      }
      
      if (config==1)
      {   
         menu_mainmenu();
         if(UniTemp[0]==0x43)
         {
            write_eeprom(0x01, 1);
         }
         else if(UniTemp[0]==0x46)
         {
            write_eeprom(0x01, 2);
         }
         if(UniPres[0]==0x6D)
         {
            write_eeprom(0x02, 1);
         }
         else if(UniPres[0]==0x50)
         {
            write_eeprom(0x02, 2);
         }
         if(UniVel[0]==0x4E)
         {
            write_eeprom(0x03, 1);
         }
         else if(UniVel[0]==0x6B)
         {
            write_eeprom(0x03, 2);
         }
         else if(UniVel[0]==0x6D)
         {
            write_eeprom(0x03, 3);
         }
         
         update_readings();
         
         button = !PRESSED;
         config=0;
      }
      
      if (uh>40)
      {
       
         twop[0]=":";
         guion[0]="-";
         spa[0]=" ";  

         str_init(print_time);
         str_init(print_date);
         
         ds1307_get_time(aux_hr,aux_min,aux_sec);
         ds1307_get_date(aux_day, aux_month, aux_year, aux_dow);

         itoa(aux_day,10,print_day);
         itoa(aux_month,10,print_month);
         itoa(aux_year,10,print_year);
         switch(aux_dow)
         {
            case 0:
            {
               print_dow[0] = "D";
               break;
            }
            case 1:
            {
               print_dow[0] = "L";
               break;
            }
            case 2:
            {
               print_dow[0] = "M";
               break;
            }
            case 3:
            {
               print_dow[0] = "I";
               break;
            }
            case 4:
            {
               print_dow[0] = "J";
               break;
            }
            case 5:
            {
               print_dow[0] = "V";
               break;
            }
            case 6:
            {
               print_dow[0] = "S";
               break;
            }
         }
         sprintf(print_date,"%s:%s-%s-%s",print_dow,print_day,print_month,print_year);
         //strcat(print_date,print_dow);
         //strcat(print_date,twop);
         //strcat(print_date,print_day);
         //strcat(print_date,guion);
        // strcat(print_date,print_month);
         //strcat(print_date,guion);
         //strcat(print_date,print_year);

         if(aop[0]==0x50)
         {
            aux_hr=aux_hr-20;
         }
         itoa(aux_hr,10,print_hr);
         itoa(aux_min,10,print_min);
         strcat(print_time,print_hr);
         strcat(print_time,twop);
         strcat(print_time,print_min);
         
         if ((aop[0]==0x41)||(aop[0]==0x50))
         {
            strcat(print_time,twop);
            strcat(print_time,aop);
         }
         


         
         rcv_td=1;
         uh=0;
      }

      poll_ok();
      lightbuttons();

      while(bkbhit) 
      {
         
         auxi = bgetc();
         switch (auxi)
         {
            case 0x54:     //T
            {
               type=1;
               str_init(string);
               break;
            }
            case 0x50:     //P
            {
               type=2;
               str_init(string);
               break;
            }
            case 0x48:     //H
            {
               type=3;
               str_init(string);
               break;
            }
            case 0x41:     //A
            {
               type=4;
               str_init(string);
               break;
            }
            case 0x57:     //W
            {
               type=5;
               str_init(string);
               break;
            }
            case 0x52:     //R 
            {
               type=6;
               str_init(string);
               break;
            }
            case 0x44:     //D
            {
               type=7;
               str_init(string);
               break;
            }
            case 0x4C:     //L
            {
               type=8;
               str_init(string);
               break;
            }
            case 0x56:     //V
            {
               type=9;
               str_init(string);
               break;
            }
            case 0x42:     //B
            {
               type=10;
               str_init(string);
               break;
            }         
            
         }
         
         switch (type)
         {
            case 1:                 //Temperatura
            {
               if ((auxi!=0x0D)&&(auxi!=0x54))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  str_init(tprint);
                  tt = atol(string);  

                  if(UniTemp[0]==0x46)
                  {
                     tt = ((tt*9)/5)+320;
                  }

                  strcat(temp_buffer_eeprom,string);
                  eep+=3;

                  sprintf(ttt,"%3.1w",tt);
                  strcat(tprint,ttt);
                  strcat(tprint,UniTemp);

                  strcpy(t2_print,tprint);

                  rcv_t=1;
               }
               break;
            }
            case 2:                 //Presion
            {
               if ((auxi!=0x0D)&&(auxi!=0x50))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  str_init(pprint);
                  pp = atoi32(string);

                  if(UniPres[0]==0x50)
                  {
                     pp = pp*10;
                     sprintf(ppp,"%6.0w",pp);
                     strcat(pprint,ppp);
                     strcat(pprint,UniPres);  
                  }
                  else
                  {
                     sprintf(ppp,"%4.1w",pp);
                     strcat(pprint,ppp);
                     strcat(pprint,UniPres);  
                  }

                  rcv_p=1;
                  
               }
               break;
            }
            case 3:                 //Humedad
            {
               if ((auxi!=0x0D)&&(auxi!=0x48))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  char uni[]="%";
                  str_init(hprint);
                  hh = atol(string);
                  sprintf(hhh,"%2.1w",hh);
                  strcat(hprint,hhh);
                  strcat(hprint,uni);

                  rcv_h=1;
               }
               break;
            }
            case 4:                 //Altitud
            {
               if ((auxi!=0x0D)&&(auxi!=0x41))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  char uni[]="m";
                  str_init(aprint);
                  aa = atol(string);
                  sprintf(aaa,"%5.1w",aa);
                  strcat(aprint,aaa);
                  strcat(aprint,uni);

                  rcv_a=1;
                    
               }
               break;
            }
            case 5:                 //Clima
            {
               if ((auxi!=0x0D)&&(auxi!=0x57))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;                  
                  
                  ww = atoi(string);
                                    
                  rcv_w=1;
               }
               break;
            }
            case 6:                 //Probabilidad de lluvia
            {
               if ((auxi!=0x0D)&&(auxi!=0x52))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;

                  char uni[]="%";
                  str_init(pdlprint);
                  ppdl = atol(string);
                  sprintf(pppdl,"%2.0w",ppdl);
                  strcat(pdlprint,pppdl);
                  strcat(pdlprint,uni);
                  
                  rcv_pdl=1;
               }
               break;
            }
            case 7:                 //Direccion del viento
            {
               if ((auxi!=0x0D)&&(auxi!=0x44))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  str_init(dprint);
                  dd = atol(string);
                  switch(dd)
                  {
                     case 0:
                     {
                        dprint[0]="N";
                        dprint[1]="\0";
                        break;
                     }
                     case 1:
                     {
                        dprint[0]="N";
                        dprint[1]="E";
                        dprint[2]="\0";
                        break;
                     }
                     case 2:
                     {
                        dprint[0]="E";
                        dprint[1]="\0";
                        break;
                     }
                     case 3:
                     {
                        dprint[0]="S";
                        dprint[1]="E";
                        dprint[2]="\0";
                        break;
                     }
                     case 4:
                     {
                        dprint[0]="S";
                        dprint[1]="\0";
                        break;
                     }
                     case 5:
                     {
                        dprint[0]="S";
                        dprint[1]="O";
                        dprint[2]="\0";
                        break;
                     }
                     case 6:
                     {
                        dprint[0]="O";
                        dprint[1]="\0";
                        break;
                     }
                     case 7:
                     {
                        dprint[0]="N";
                        dprint[1]="O";
                        dprint[2]="\0";
                        break;
                     }
                  }
                  
                  rcv_d=1;           
               }
               break;
            }
            case 8:                 //Intensidad de luz
            {
               if ((auxi!=0x0D)&&(auxi!=0x4C))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;                  
                  
                  ll = atoi(string);
                  ll = ll*6.3+67;
                  
                  rcv_l=1;
               }
               break;
            }
            case 9:                 //Velocidad del viento
            {
               if ((auxi!=0x0D)&&(auxi!=0x56))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  str_init(vprint);
                  vv = atoi32(string);

                  if(UniVel[0]==0x6D)
                  {
                     vv = vv * 0.5144;
                  }
                  else if(UniVel[0]==0x6B)
                  {
                     vv = vv * 1.852;
                  }
                  else
                  {

                  }

                  sprintf(vvv,"%4.1w",vv);
                  strcat(vprint,vvv);
                  strcat(vprint,UniVel);  

                  
                  rcv_v=1;
               }
               break;
            }
            case 10:                //Bat Status
            {
               if ((auxi!=0x0D)&&(auxi!=0x42))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  
                  bat1_st = atoi(string);
                  
                  rcv_bat1_st=1;
               }
               break;
            }
            
         }

         if(eep>=9)
         {
            update_eeprom();
            eep=0;
         }
         update_readings();
         glcd_update();
         //END KBHIT 
      }
      

      
      glcd_update();
      //ENDWHILE
   }
//ENDMAIN
}