Ejemplo n.º 1
0
//		SET CALIB. VALUES
//input:
//	s	Sensor structure.
//	index	Point to a specific sensor.
//description:
//	function devoted to set each (x,y) 
//	point to be used in the linear 
//	regression.
//-------------------------------------------	
static void set_calib_values(sensor s,unsigned int index)
{
	unsigned int j;
	float v,w;

	for(j=0;j<NKVAL;j++){

		w=0.0;
		v=0.0;
		while(OK==0){	
			get_adc(s);
			v=(float) s[index].adc*5/1023;
			w=counter(w);
			glcd_rect(0,10,90,30,YES,OFF);
			sprintf(text,"X[%d]= %.1f gr",j+1,w);
			glcd_text57(0,10, text,1,ON);
			sprintf(text,"Y[%d]= %.1f V ",j+1,v);
			glcd_text57(0,20, text,1,ON);
#ifdef FAST_GLCD
			glcd_update();
#endif	
		}
		load[j]=w;
		voltage[j]=v;
		delay_ms(600);
	}
}
Ejemplo n.º 2
0
// Purpose:       Initialize the LCD.
//                Call before using any other LCD function.
// Inputs:        OFF - Turns the LCD off
//                ON  - Turns the LCD on
void glcd_init(int1 mode)
{
   // Initialze some pins
   output_high(GLCD_RST);
   output_low(GLCD_E);
   output_low(GLCD_CS1);
   output_low(GLCD_CS2);

   output_low(GLCD_DI);                 // Set for instruction
   glcd_writeByte(GLCD_LEFT,  0xC0);    // Specify first RAM line at the top
   glcd_writeByte(GLCD_RIGHT, 0xC0);    //   of the screen
   glcd_writeByte(GLCD_LEFT,  0x40);    // Set the column address to 0
   glcd_writeByte(GLCD_RIGHT, 0x40);
   glcd_writeByte(GLCD_LEFT,  0xB8);    // Set the page address to 0
   glcd_writeByte(GLCD_RIGHT, 0xB8);

   if(mode == ON)
   {
      glcd_writeByte(GLCD_LEFT,  0x3F); // Turn the display on
      glcd_writeByte(GLCD_RIGHT, 0x3F);
   }
   else
   {
      glcd_writeByte(GLCD_LEFT,  0x3E); // Turn the display off
      glcd_writeByte(GLCD_RIGHT, 0x3E);
   }

   glcd_fillScreen(OFF);                // Clear the display

   #ifdef FAST_GLCD
   glcd_update();
   #endif
}
Ejemplo n.º 3
0
// Purpose:       Initialize the LCD.
//                Call before using any other LCD function.
// Inputs:        OFF - Turns the LCD off
//                ON  - Turns the LCD on
void glcd_init(int mode)
{

   low_Enable;
   low_CS1;
   low_CS2;
   low_DI;


   glcd_writeByte(GLCD_LEFT,  0xC0);    // Specify first RAM line at the top
   glcd_writeByte(GLCD_RIGHT, 0xC0);    //   of the screen
   glcd_writeByte(GLCD_LEFT,  0x40);    // Set the column address to 0
   glcd_writeByte(GLCD_RIGHT, 0x40);
   glcd_writeByte(GLCD_LEFT,  0xB8);    // Set the page address to 0
   glcd_writeByte(GLCD_RIGHT, 0xB8);

   if(mode == ON)
   {
      glcd_writeByte(GLCD_LEFT,  0x3F); // Turn the display on
      glcd_writeByte(GLCD_RIGHT, 0x3F);
   }
   else
   {
      glcd_writeByte(GLCD_LEFT,  0x3E); // Turn the display off
      glcd_writeByte(GLCD_RIGHT, 0x3E);
   }

   glcd_fillScreen(OFF);                // Clear the display


   glcd_update();

}
Ejemplo n.º 4
0
void menu_drawmain(void)
{
   	glcd_fillScreen(OFF);
	glcd_text57(0, 0, mainmenu[0].menutext, 1, ON);
   	glcd_bar(0, 9, 127, 9, 2, ON); //div

   	for(i=1;i<mm;i++)
   	{
		glcd_text57(0, 14+((i-1)*9), mainmenu[i].menutext, 1, ON);
   		menu_enter(14+((i-1)*9),ON);
   	}
   	
   	glcd_update();
}
Ejemplo n.º 5
0
//	LINEAR REGRESSION ALGORITHM
//input:
//	s	Sensor structure.
//	index	Point to a specific sensor.
//description:
//	algorithm based in a simple linear 
//	regression.
//	At the end, it writes the new calib.
//	parameters (m and b) in the EEPROM.
//-------------------------------------------	
static void linear_reg(sensor s,unsigned int index)
{

	float Xm,Ym,Sx,Sy,Sxy,r,b0,b1;
	int i;

	Xm=0;
	Ym=0;
	for(i=0;i<NKVAL;i++){
		Xm = Xm + load[i];
		Ym = Ym + Voltage[i];
	}
	Xm=Xm/NKVAL;
	Ym=Ym/NKVAL;

	Sx=0;
	Sy=0;
	Sxy=0;
	for(i=0;i<NKVAl;i++){
		Sx= Sx + pow(load[i]-Xm,2);
		Sy= Sy + pow(voltage[i]-Ym,2);
		Sxy = Sxy + (load[i]-Xm)*(voltage[i]-Ym);
	}

	b1=Sxy/Sx;
	b0=Ym-b1*Xm;
	r=Sxy/(sqrt(Sx)*sqrt(Sy));

	s[index].m=b1;
	s[index].b=b0;

	glcd_fillScreen(OFF);  
	sprintf(text,"Sensor # %d",index+1);
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"R=%.3f",r);
	glcd_text57(20,30, text,1,ON); 
	sprintf(text,"m=%.3f",s[index].m);
	glcd_text57(20,40, text,1,ON); 
	sprintf(text,"b=%.3f",s[index].b);
	glcd_text57(20,50, text,1,ON); 
#ifdef FAST_GLCD
	glcd_update();
#endif	
	delay_ms(5000);
	
	write_2_eeprom(s,index);
}
Ejemplo n.º 6
0
/************************************************************************
*                                                                       *
*  Purpose:    Draw main menu                                           *
*                                                                       *
*  Proposito:  Dibuja el menu principal                                 *
*                                                                       *
*  Passed:     None                                                     *
*  Argumento:  Nada                                                     *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void menu_drawmain(void)
{
    glcd_fillScreen(OFF);
    glcd_text57(0, 0, MENUTITLE, 1, ON);
    glcd_bar(0, 9, 127, 9, 2, ON); //div
    glcd_text57(0, 14, MENU1, 1, ON);
    menu_entrar(14,ON);
    glcd_text57(0, 23, MENU2, 1, ON);
    glcd_text57(100, 23, UniTemp, 1, ON);
    menu_entrar(23,ON);
    glcd_text57(0, 32, MENU3, 1, ON);
    glcd_text57(100, 32, UniPres, 1, ON);
    menu_entrar(32,ON);
    glcd_text57(0, 41, MENU4, 1, ON);
    glcd_text57(100, 41, UniVel, 1, ON);
    menu_entrar(41,ON);
    glcd_update();
}
Ejemplo n.º 7
0
int main(void)
{
 systick_hw_init();
 led_hw_init();
 USART0_Init(115200);
 glcd_init();
 glcd_draw_string(0,0,"<<SSD1306 OLED>>",WHITE);
	glcd_draw_string(0,16,"Hello,SAM4N",WHITE);
	glcd_draw_string(0,32,"www.eeboard.com",WHITE);
	glcd_draw_string(0,48,"oled font test",WHITE);
 glcd_update();
 while(1){
	 USART0_Init(115200);
USART0_SendString("hello\r\n");
 PIOB->PIO_CODR=(0x01<<LED0_PIN);
 delay_ms(100);
 PIOB->PIO_SODR=(0x01<<LED0_PIN);
 delay_ms(100);
 }

}
Ejemplo n.º 8
0
/************************************************************************
*                                                                       *
*  Purpose:    Draw and handles the time config menu                    *
*                                                                       *
*  Proposito:  Dibuja y maneja el menu de configuracion de la hora      *
*                                                                       *
*  Passed:     None                                                     *
*  Argumento:  Nada                                                     *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void menu_timemenu(void)
{
    glcd_fillScreen(OFF);
    glcd_text57(0, 0, MENU1, 1, ON);
    glcd_bar(0, 9, 127, 9, 2, ON); //div

    glcd_rect(5, 20, 25, 35, NO, ON);         //DoW
    glcd_text57(9, 24, dow, 1, ON);

    glcd_rect(35, 20, 55, 35, NO, ON);         //Dia
    glcd_text57(39, 24, dia, 1, ON);

    glcd_rect(65, 20, 85, 35, NO, ON);        //Mes
    glcd_text57(69, 24, mes, 1, ON);

    glcd_rect(95, 20, 115, 35, NO, ON);        //Año
    glcd_text57(99, 24, ao, 1, ON);


    glcd_rect(5, 45, 25, 60, NO, ON);         //Hora
    glcd_text57(9, 49, hora, 1, ON);

    glcd_rect(35, 45, 55, 60, NO, ON);        //Minuto
    glcd_text57(39, 49, min, 1, ON);

    glcd_rect(65, 45, 85, 60, NO, ON);        // AM/PM.
    glcd_text57(69, 49, aop, 1, ON);


    glcd_update();



    while (1)
    {

        readbuttons();
        if (right==PRESSED)
        {
            control+=1;
            if (control>=8)
            {
                control = 1;
            }
        }
        if (left==PRESSED)
        {
            control-=1;
            if (control<=0)
            {
                control = 7;
            }
        }
        if (enter==PRESSED)
        {
            control = 10;
        }


        switch (control)
        {
        case 1:
        {
            glcd_rect(65, 45, 85, 60, YES, OFF);
            glcd_rect(65, 45, 85, 60, NO, ON);        // AM/PM.
            glcd_text57(69, 49, aop, 1, ON);


            glcd_rect(5, 20, 25, 35, YES, ON);         //DoW
            glcd_text57(9, 24, dow, 1, OFF);

            glcd_rect(35, 20, 55, 35, YES, OFF);
            glcd_rect(35, 20, 55, 35, NO, ON);         //Dia
            glcd_text57(39, 24, dia, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                k++;

                if(k>=7)
                {
                    k=0;
                }

                switch(k)
                {
                case 0:
                {
                    dow[0] = "L";
                    break;
                }
                case 1:
                {
                    dow[0] = "M";
                    break;
                }
                case 2:
                {
                    dow[0] = "I";
                    break;
                }
                case 3:
                {
                    dow[0] = "J";
                    break;
                }
                case 4:
                {
                    dow[0] = "V";
                    break;
                }
                case 5:
                {
                    dow[0] = "S";
                    break;
                }
                case 6:
                {
                    dow[0] = "D";
                    break;
                }
                }


                glcd_rect(5, 20, 25, 35, YES, ON);         //DoW

                glcd_text57(9, 24, dow, 1, OFF);
                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                k--;

                if((k<0)||(k>10))
                {
                    k=6;
                }

                switch(k)
                {
                case 0:
                {
                    dow[0] = "L";
                    break;
                }
                case 1:
                {
                    dow[0] = "M";
                    break;
                }
                case 2:
                {
                    dow[0] = "I";
                    break;
                }
                case 3:
                {
                    dow[0] = "J";
                    break;
                }
                case 4:
                {
                    dow[0] = "V";
                    break;
                }
                case 5:
                {
                    dow[0] = "S";
                    break;
                }
                case 6:
                {
                    dow[0] = "D";
                    break;
                }
                }

                glcd_rect(5, 20, 25, 35, YES, ON);         //DoW

                glcd_text57(9, 24, dow, 1, OFF);
                glcd_update();

            }



            break;
        }
        case 2:           // DIA
        {

            glcd_rect(5, 20, 25, 35, YES, OFF);
            glcd_rect(5, 20, 25, 35, NO, ON);        // DoW
            glcd_text57(9, 24, dow, 1, ON);


            glcd_rect(35, 20, 55, 35, YES, ON);         //Dia
            glcd_text57(39, 24, dia, 1, OFF);

            glcd_rect(65, 20, 85, 35, YES, OFF);
            glcd_rect(65, 20, 85, 35, NO, ON);         //Mes
            glcd_text57(69, 24, mes, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                int8 auxdia;
                auxdia = atoi(dia);
                auxdia -=1;
                if (auxdia==0)
                {
                    if (atoi(mes)==2)
                    {
                        auxdia = 28;
                    }
                    else
                    {
                        auxdia = 31;
                    }
                }
                itoa(auxdia,10,dia);
                glcd_rect(35, 20, 55, 35, YES, ON);         //Dia

                glcd_text57(39, 24, dia, 1, OFF);
                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                int8 auxdia;
                auxdia = atoi(dia);
                auxdia +=1;
                if (atoi(mes)==2)
                {
                    if(auxdia==29)
                    {
                        auxdia = 1;
                    }
                }
                if (auxdia==32)
                {
                    auxdia = 1;
                }
                itoa(auxdia,10,dia);
                glcd_rect(35, 20, 55, 35, YES, ON);         //Dia

                glcd_text57(39, 24, dia, 1, OFF);
                glcd_update();

            }
            break;
        }
        case 3:           // MES
        {

            glcd_rect(35, 20, 55, 35, YES, OFF);
            glcd_rect(35, 20, 55, 35, NO, ON);         //Dia
            glcd_text57(39, 24, dia, 1, ON);

            glcd_rect(65, 20, 85, 35, YES, ON);         //Mes
            glcd_text57(69, 24, mes, 1, OFF);

            glcd_rect(95, 20, 115, 35, YES, OFF);
            glcd_rect(95, 20, 115, 35, NO, ON);         //Año
            glcd_text57(99, 24, ao, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                int8 auxmes;
                auxmes = atoi(mes);
                auxmes -=1;
                if (auxmes==0)
                {
                    auxmes = 12;
                }
                itoa(auxmes,10,mes);
                glcd_rect(65, 20, 85, 35, YES, ON);         //Mes

                glcd_text57(69, 24, mes, 1, OFF);
                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                int8 auxmes;
                auxmes = atoi(mes);
                auxmes +=1;
                if (auxmes==13)
                {
                    auxmes = 1;
                }
                itoa(auxmes,10,mes);
                glcd_rect(65, 20, 85, 35, YES, ON);         //Mes

                glcd_text57(69, 24, mes, 1, OFF);
                glcd_update();

            }
            break;
        }
        case 4:           // AÑO
        {

            glcd_rect(65, 20, 85, 35, YES, OFF);
            glcd_rect(65, 20, 85, 35, NO, ON);         //Mes
            glcd_text57(69, 24, mes, 1, ON);

            glcd_rect(95, 20, 115, 35, YES, ON);         //Año
            glcd_text57(99, 24, ao, 1, OFF);

            glcd_rect(5, 45, 25, 60, YES, OFF);
            glcd_rect(5, 45, 25, 60, NO, ON);         //Hora
            glcd_text57(9, 49, hora, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                int8 auxao;
                auxao = atoi(ao);
                auxao -=1;
                if (auxao==0)
                {
                    auxao = 99;
                }
                itoa(auxao,10,ao);

                glcd_rect(95, 20, 115, 35, YES, ON);         //Año
                glcd_text57(99, 24, ao, 1, OFF);

                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                int8 auxao;
                auxao = atoi(ao);
                auxao +=1;
                if (auxao==99)
                {
                    auxao = 0;
                }
                itoa(auxao,10,ao);
                glcd_rect(95, 20, 115, 35, YES, ON);         //Año

                glcd_text57(99, 24, ao, 1, OFF);
                glcd_update();

            }
            break;
        }
        case 5:           // HORA
        {

            glcd_rect(95, 20, 115, 35, YES, OFF);
            glcd_rect(95, 20, 115, 35, NO, ON);         //Año
            glcd_text57(99, 24, ao, 1, ON);

            glcd_rect(5, 45, 25, 60, YES, ON);         //Hora
            glcd_text57(9, 49, hora, 1, OFF);

            glcd_rect(35, 45, 55, 60, YES, OFF);
            glcd_rect(35, 45, 55, 60, NO, ON);        //Minuto
            glcd_text57(39, 49, min, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                int8 auxhora;
                auxhora = atoi(hora);
                auxhora -=1;

                if ((aop[0]==0x41)||(aop[0]==0x50))
                {
                    if (auxhora<=0)
                    {
                        auxhora = 12;
                    }
                }
                else
                {
                    if ((auxhora<0)||(auxhora>50))
                    {
                        auxhora = 23;
                    }
                }


                itoa(auxhora,10,hora);

                glcd_rect(5, 45, 25, 60, YES, ON);         //Hora
                glcd_text57(9, 49, hora, 1, OFF);

                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                int8 auxhora;
                auxhora = atoi(hora);
                auxhora +=1;
                if ((aop[0]==0x41)||(aop[0]==0x50))
                {
                    if (auxhora>12)
                    {
                        auxhora = 1;
                    }
                }
                else
                {
                    if (auxhora>23)
                    {
                        auxhora = 0;
                    }
                }

                itoa(auxhora,10,hora);
                glcd_rect(5, 45, 25, 60, YES, ON);         //Hora

                glcd_text57(9, 49, hora, 1, OFF);
                glcd_update();

            }

            break;
        }
        case 6:           // MINUTOS
        {
            glcd_rect(5, 45, 25, 60, YES, OFF);
            glcd_rect(5, 45, 25, 60, NO, ON);         //Hora
            glcd_text57(9, 49, hora, 1, ON);

            glcd_rect(35, 45, 55, 60, YES, ON);        //Minuto
            glcd_text57(39, 49, min, 1, OFF);


            glcd_rect(65, 45, 85, 60, YES, OFF);
            glcd_rect(65, 45, 85, 60, NO, ON);        // AM/PM.
            glcd_text57(69, 49, aop, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                int8 auxmin;
                auxmin = atoi(min);

                if (auxmin==0)
                {
                    auxmin = 60;
                }
                auxmin -=1;
                itoa(auxmin,10,min);

                glcd_rect(35, 45, 55, 60, YES, ON);        //Minuto
                glcd_text57(39, 49, min, 1, OFF);
                glcd_update();
            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                int8 auxmin;
                auxmin = atoi(min);
                auxmin +=1;
                if (auxmin>=60)
                {
                    auxmin = 0;
                }
                itoa(auxmin,10,min);

                glcd_rect(35, 45, 55, 60, YES, ON);        //Minuto
                glcd_text57(39, 49, min, 1, OFF);
                glcd_update();

            }
            break;
        }
        case 7:           // AM - PM
        {

            glcd_rect(35, 45, 55, 60, YES, OFF);
            glcd_rect(35, 45, 55, 60, NO, ON);        //Minuto
            glcd_text57(39, 49, min, 1, ON);

            glcd_rect(65, 45, 85, 60, YES, ON);        //AM PM
            glcd_text57(69, 49, aop, 1, OFF);

            glcd_rect(5, 20, 25, 35, YES, OFF);
            glcd_rect(5, 20, 25, 35, NO, ON);         //DoW
            glcd_text57(9, 24, dow, 1, ON);

            glcd_update();

            if ((up==!PRESSED)&&(down==PRESSED))
            {
                if (aop[0]==0x41)
                {
                    aop[0] = "P";
                }
                else if (aop[0]==0x50)
                {
                    aop[0] = "M";
                }
                else if (aop[0]==0x4D)
                {
                    aop[0] = "A";
                }

                glcd_rect(65, 45, 85, 60, YES, ON);        //Minuto
                glcd_text57(69, 49, aop, 1, OFF);

                glcd_update();

            }
            if ((up==PRESSED)&&(down==!PRESSED))
            {
                if (aop[0]==0x41)
                {
                    aop[0] = "M";
                }
                else if (aop[0]==0x50)
                {
                    aop[0] = "A";
                }
                else if (aop[0]==0x4D)
                {
                    aop[0] = "P";
                }

                glcd_rect(65, 45, 85, 60, YES, ON);        //Minuto
                glcd_text57(69, 49, aop, 1, OFF);

                glcd_update();

            }

            break;
        }
        case 10:          // SET
        {
            glcd_fillscreen(OFF);
            glcd_text57(0, 0, MENU1, 1, ON);
            glcd_bar(0, 9, 127, 9, 2, ON); //div

            glcd_rect(5, 20, 25, 35, YES, ON);         //DoW
            glcd_text57(9, 24, dow, 1, OFF);

            glcd_rect(5, 20, 25, 35, NO, ON);         //Dia
            glcd_text57(9, 24, dia, 1, ON);

            glcd_rect(35, 20, 55, 35, NO, ON);        //Mes
            glcd_text57(39, 24, mes, 1, ON);

            glcd_rect(65, 20, 85, 35, NO, ON);        //Año
            glcd_text57(69, 24, ao, 1, ON);


            glcd_rect(5, 45, 25, 60, NO, ON);         //Hora
            glcd_text57(9, 49, hora, 1, ON);

            glcd_rect(35, 45, 55, 60, NO, ON);        //Minuto
            glcd_text57(39, 49, min, 1, ON);

            glcd_rect(65, 45, 85, 60, NO, ON);        // AM/PM.
            glcd_text57(69, 49, aop, 1, ON);

            glcd_update();

            break;
        }

        }



        button = !PRESSED;
        if (control==10)
        {
            /*GRABAR EN RTC*/
            ds1307_set_date_time(atoi(dia),atoi(mes),atoi(ao),(k+1),atoi(hora),atoi(min),0,aop[0]);
            return;
        }

    }
}
Ejemplo n.º 9
0
/************************************************************************
*                                                                       *
*  Purpose:    Draw and handle the submenu                              *
*                                                                       *
*  Proposito:  Dibuja y maneja cada submenu                             *
*                                                                       *
*  Passed:     SubMenu position identifier                              *
*  Argumento:  Identificador de posicion del submenu                    *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void menu_submenu(char menu)
{
    switch (menu)
    {
    case 1:
    {
        menu_timemenu();
        i=0;
        return;
        break;
    }
    case 2:
    {

        glcd_fillScreen(OFF);
        glcd_text57(0, 0, MENU2, 1, ON)   ;
        glcd_bar(0, 9, 127, 9, 2, ON); //div
        glcd_text57(0, 14, MENU2ITEM1, 1, ON)   ;
        glcd_text57(0, 23, MENU2ITEM2, 1, ON)   ;
        glcd_update();
        i = 0;
        break;
    }
    case 3:
    {
        glcd_fillScreen(OFF);
        glcd_text57(0, 0, MENU3, 1, ON)   ;
        glcd_bar(0, 9, 127, 9, 2, ON); //div
        glcd_text57(0, 14, MENU3ITEM1, 1, ON)   ;
        glcd_text57(0, 23, MENU3ITEM2, 1, ON)   ;
        glcd_update();
        i = 0;
        break;
    }
    case 4:
    {
        glcd_fillScreen(OFF);
        glcd_text57(0, 0, MENU4, 1, ON)   ;
        glcd_bar(0, 9, 127, 9, 2, ON); //div
        glcd_text57(0, 14, MENU4ITEM1, 1, ON)   ;
        glcd_text57(0, 23, MENU4ITEM2, 1, ON)   ;
        glcd_text57(0, 32, MENU4ITEM3, 1, ON)   ;
        glcd_update();
        i = 0;
        break;
    }
    }

    while(1)
    {
        readbuttons();
        if ((up==!PRESSED)&&(down==PRESSED))
        {
            i+=1;
            menu_select(i,menu);

        }
        if ((up==PRESSED)&&(down==!PRESSED))
        {
            i-=1;
            menu_select(i,menu);

        }
        if (left==PRESSED)
        {
            i = 0;

            button = !PRESSED;
            break;
        }
        if (enter==PRESSED)
        {
            switch (menu)
            {
            case 2:
            {
                switch (i)
                {
                case 1:
                {
                    UniTemp = "C";

                    break;
                }
                case 2:
                {
                    UniTemp = "F";

                    break;
                }
                }
                break;
            }
            case 3:
            {
                switch (i)
                {
                case 1:
                {
                    UniPres = "mBa";

                    break;
                }
                case 2:
                {
                    UniPres = "Pa";
                    break;
                }
                }
                break;
            }
            case 4:
            {
                switch (i)
                {
                case 1:
                {
                    UniVel = "Nud";

                    break;
                }
                case 2:
                {
                    UniVel = "km/h";

                    break;
                }
                case 3:
                {
                    UniVel = "m/s";
                    break;
                }
                }
                break;
            }

            }
            i=0;
            button = !PRESSED;
            break;
        }
        button = !PRESSED;
    }
    button = !PRESSED;
}
Ejemplo n.º 10
0
/************************************************************************
*                                                                       *
*  Purpose:    Draw the selected item                                   *
*                                                                       *
*  Proposito:  Dibuja el item seleccionado                              *
*                                                                       *
*  Passed:     char item - Nº of item                                   *
*              char menu - The menu it belongs                          *
*  Argumento:  char item - Posicion del item                            *
*              char menu - El menu al que pertenece                     *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void menu_select(char item, char menu)
{
    switch (menu)
    {
    case 0:
    {
        switch (item)
        {
        case 1:
        {
            menu_drawmain();

            glcd_bar(0, 17, 127, 17, 9, ON);    //selected
            glcd_text57(0, 14, MENU1, 1, OFF);
            menu_entrar(14,OFF);

            glcd_update();
            break;
        }
        case 2:
        {
            menu_drawmain();

            glcd_bar(0, 26, 127, 26, 9, ON);    //selected
            glcd_text57(0, 23, MENU2, 1, OFF);
            glcd_text57(100, 23, UniTemp, 1, OFF);
            menu_entrar(23,OFF);

            glcd_update();
            break;
        }
        case 3:
        {
            menu_drawmain();

            glcd_bar(0, 35, 127, 35, 9, ON); //selected
            glcd_text57(0, 32, MENU3, 1, OFF);
            glcd_text57(100, 32, UniPres, 1, OFF);
            menu_entrar(32,OFF);


            glcd_update();
            break;
        }
        case 4:
        {
            menu_drawmain();

            glcd_bar(0, 44, 127, 44, 9, ON); //selected
            glcd_text57(0, 41, MENU4, 1, OFF);
            glcd_text57(100, 41, UniVel, 1, OFF);
            menu_entrar(41,OFF);



            glcd_update();
            break;
        }
        }
        break;
    }
    case 1:
    {

        break;
    }
    case 2:
    {
        switch (item)
        {
        case 1:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU2, 1, ON)   ; //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);      //div
            glcd_bar(0, 17, 127, 17, 9, ON);    //selected
            glcd_text57(0, 14, MENU2ITEM1, 1, OFF);

            glcd_text57(0, 23, MENU2ITEM2, 1, ON)   ;

            glcd_update();
            break;
        }
        case 2:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU2, 1, ON);       //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);         //div
            glcd_text57(0, 14, MENU2ITEM1, 1, ON);
            glcd_bar(0, 26, 127, 26, 9, ON);       //selected
            glcd_text57(0, 23, MENU2ITEM2, 1, OFF);


            glcd_update();
            break;
        }

        }
        break;
    }
    case 3:
    {
        switch (item)
        {
        case 1:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU3, 1, ON)   ; //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);      //div
            glcd_bar(0, 17, 127, 17, 9, ON);    //selected
            glcd_text57(0, 14, MENU3ITEM1, 1, OFF);

            glcd_text57(0, 23, MENU3ITEM2, 1, ON)   ;

            glcd_update();
            break;
        }
        case 2:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU3, 1, ON);       //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);         //div
            glcd_text57(0, 14, MENU3ITEM1, 1, ON);
            glcd_bar(0, 26, 127, 26, 9, ON);       //selected
            glcd_text57(0, 23, MENU3ITEM2, 1, OFF);


            glcd_update();
            break;
        }
        }
        break;
    }
    case 4:
    {
        switch (item)
        {
        case 1:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU4, 1, ON)   ; //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);      //div
            glcd_bar(0, 17, 127, 17, 9, ON);    //selected
            glcd_text57(0, 14, MENU4ITEM1, 1, OFF);

            glcd_text57(0, 23, MENU4ITEM2, 1, ON)   ;
            glcd_text57(0, 32, MENU4ITEM3, 1, ON)   ;
            glcd_update();
            break;
        }
        case 2:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU4, 1, ON);       //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);         //div
            glcd_text57(0, 14, MENU4ITEM1, 1, ON);
            glcd_bar(0, 26, 127, 26, 9, ON);       //selected
            glcd_text57(0, 23, MENU4ITEM2, 1, OFF);
            glcd_text57(0, 32, MENU4ITEM3, 1, ON)   ;

            glcd_update();
            break;
        }
        case 3:
        {
            glcd_fillScreen(OFF);
            glcd_text57(0, 0, MENU4, 1, ON);       //Titulo
            glcd_bar(0, 9, 127, 9, 2, ON);         //div
            glcd_text57(0, 14, MENU4ITEM1, 1, ON);

            glcd_text57(0, 23, MENU4ITEM2, 1, ON);
            glcd_bar(0, 35, 127, 35, 9, ON); //selected
            glcd_text57(0, 32, MENU4ITEM3, 1, OFF)   ;

            glcd_update();
            break;
        }
        }
        break;
    }

    }
}
Ejemplo n.º 11
0
void main()
{

   
   glcd_init(ON);  

   delay_ms(100);
   
   draw_sect();
   int t = 234;
   char temp[10];
   sprintf(temp,"%3.1w",t);
   glcd_text_sec(1,1,temp,OFF);
   glcd_update();
   
  
  /*
  
   while (1)
   {
   int8 i=0;
   for (i=0;i<63;i++)
   {  
   
      char h,k;
      h = (2*i);
      k = (2*i)+1;
      
      char l[] = "Iniciando X-Weather";
      
       char n[] = "Iniciando Sensores";
      glcd_bar(h, 5, h, 15, 1, ON);
      glcd_bar(k, 5, k, 15, 1, ON);
      glcd_text57(5, 7, l, 1, OFF) ;
      
      
      
      glcd_update();
      
      
   }
   glcd_rect(0,6,127,15,YES,ON);
   for (i=0;i<63;i++)
   {  
   
      char h,k;
      h = (2*i);
      k = (2*i)+1;
      
      
      
       char n[] = "Iniciando Sensores";
       
      glcd_bar(h, 5, h, 15, 1, OFF);
      glcd_bar(k, 5, k, 15, 1, OFF);
      glcd_text57(5, 7, n, 1, ON) ;
      
      
      
      glcd_update();
      
      
   }
   break;
   }
   //glcd_showimage2()  ;
   //glcd_update();
   delay_ms(1000);
   glcd_showimage1()  ;
   
   draw_sect();
   
   
   char a[] = "Hola 1234";
   glcd_text_sec(1,1,a,OFF);
   glcd_text_sec(1,2,a,OFF);
   glcd_text_sec(1,3,a,OFF);
   
   glcd_text_sec(2,1,a,ON);
   glcd_text_sec(2,2,a,ON);
   glcd_text_sec(2,3,a,ON);
   
   glcd_text_sec(3,1,a,ON);
   glcd_text_sec(3,2,a,ON);
   glcd_text_sec(3,3,a,ON);
   
   glcd_text_sec(4,1,a,OFF);
   glcd_text_sec(4,2,a,OFF);
   glcd_text_sec(4,3,a,OFF);
   
   glcd_update();
   */
}
Ejemplo n.º 12
0
//		SENSOR TEST ROUTINE
//input:
//	s	Sensor structure.
//description:
//	This function perform a test to
//	each sensor.
//	First, it asks to the user to connect
//	all the sensors, then it checks for the
//	value read in all the ADC channels and
//	compares these values with those stored
//	in the EEPROM memory. If the full scale
//	error is bigger than MAXERROR a warning
//	is displayed.
//-------------------------------------------	
unsigned int test_calib(sensor s)
{

	unsigned int op,k,i,j;
	unsigned int status[4]={0 0 0 0};
	float Vx,error;

intro:	
	glcd_fillScreen(OFF);   
	sprintf(text,"Conectar todos\n\r los sensores");
	glcd_text57(9,0, text,1,ON); 
	sprintf(text,"2-> Ejecutar."); 
	glcd_text57(10,40, text,1,ON);
	sprintf(text,"3-> Atras."); 
	glcd_text57(10,50, text,1,ON);
	op=0;
	j=0;

command:							// code to attend the user request. 
#ifdef FAST_GLCD
	glcd_update();
#endif	
	delay_ms(200);
	while(op==0){
		op=swap( PORTB & 0b00110000);	
	}
	if(op==2)
		goto exit;
	if(op==1){
		if(j)
			goto done;
	}
	
test:
	delay_ms(2000);
	get_adc(s);						// read all ADC channels.
	for(i=0;i<NCH;i++){
		Vx = (float) s[i].adc*5.0/1023.0;		// compare the read value and the stored value.
		error=fabs(Vx - s[i].b)/5.0; 
		
		if(error >= MAXERROR)
			status[i]=1;
	}

	glcd_fillScreen(OFF);   				// display warning menssage
	sprintf(text,"Recalibrar Sensores\a");
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"2-> Calibrar."); 
	glcd_text57(10,40, text,1,ON);
	sprintf(text,"3-> Atras."); 
	glcd_text57(10,50, text,1,ON);
	
	k=0;
	for(i=0;i<NCH;i++){
		if(status[i]){
			sprintf(text,"S%d",i+1);
			glcd_text57(10+k,20, text,1,ON); 
			k+=20;
		}
	}
	j=1;
	op=0;

	goto command;
	
done:
	return 0;

exit:
	return 1;
}
Ejemplo n.º 13
0
//		SENSOR CALIBRATION
//input:
//	s	Sensor structure.
//description:
//	This function stars the sensor's 
//	calibration.
//	First, it allocate in memory the
//	arrays "voltage" and "load", used to
//	store the points for the linear 
//	regression.
//	The code ask to the user to select a
//	sensor, then it calls for the values of
//	each point (load[i],voltage[i]) to be
//	used in the regression, and finaly it
//	computes the linear reg.
//-------------------------------------------	
void sensor_calibration(sensor s)
{
	unsigned int k=0,op=0;

	voltage=(float *)malloc(NKVAL*sizeof(float));	// allocate variables in memory.	
	load=(float *)malloc(NKVAL*sizeof(float));
	if((voltage==NULL) || (load==NULL))	
		goto exit;

intro:	
	glcd_fillScreen(OFF);  				// screen to select a sensor. 
	sprintf(text,"Elegir Sensor");
	glcd_text57(10,0, text,1,ON); 
	sprintf(text,"1-> Siguiente.");
	glcd_text57(10,30, text,1,ON); 
	sprintf(text,"2-> Ejecutar."); 
	glcd_text57(10,40, text,1,ON);
	sprintf(text,"3-> Atras."); 
	glcd_text57(10,50, text,1,ON);
	if(k<NCH){
		sprintf(text,"Sensor %d",k+1);
		glcd_text57(20,15, text,1,ON); 
	}
	else{
		sprintf(text,"Todos");
		glcd_text57(20,15, text,1,ON);
	}
	op=0;

command:						// code to attend the user request. 
#ifdef FAST_GLCD
	glcd_update();
#endif	
	delay_ms(500);
	while(op==0){
		op=swap( PORTB & 0b00110001);		// wait until the user press a button.
	}
	if (op==2)					// checks if the user wants to go out the from the menu.
		goto exit;
	if((op==16)){					// checks which sensor the user wants to calibrate.
		k++;
		if(k>NCH)
			k=0;
		op=0;
		goto intro;
	}
	if((op==1)){					
		switch (k){

			case 0: {	goto s0;
					break;
				}

			case 1: {	goto s1;
					break;
				}

			case 2: {	goto s2;
					break;
				}

			case 3: {	goto s3;
					break;
				}
			case 4: {	goto s0;
					break;
				}
		}
	}

s0:							// option to calibrate sensor one.
	glcd_fillScreen(OFF);   
	sprintf(text,"Sensor # 1");
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"1-> Incre.");
	glcd_text57(0,35, text,1,ON); 
	sprintf(text,"2-> Decre."); 
	glcd_text57(0,45, text,1,ON);
	sprintf(text,"3-> Acep."); 
	glcd_text57(0,55, text,1,ON);
	set_calib_values(s,0);
	linear_reg(s,0);
	if(k<NCH){
		k=0;
		goto intro;
	}

s1:							// option to calibrate sensor two.
	glcd_fillScreen(OFF);   
	sprintf(text,"Sensor # 2");
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"1-> Incre.");
	glcd_text57(0,35, text,1,ON); 
	sprintf(text,"2-> Decre."); 
	glcd_text57(0,45, text,1,ON);
	sprintf(text,"3-> Acep."); 
	glcd_text57(0,55, text,1,ON);
	set_calib_values(s,1);				// call the function to set the reg. points.
	linear_reg(s,1);				// call the linear reg. algorithm.
	if(k<NCH){
		k=0;
		goto intro;
	}

s2:							// option to calibrate sensor three.
	glcd_fillScreen(OFF);   
	sprintf(text,"Sensor # 3");
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"1-> Incre.");
	glcd_text57(0,35, text,1,ON); 
	sprintf(text,"2-> Decre."); 
	glcd_text57(0,45, text,1,ON);
	sprintf(text,"3-> Acep."); 
	glcd_text57(0,55, text,1,ON);
	set_calib_values(s,2);
	linear_reg(s,2);
	if(k<NCH){
		k=0;
		goto intro;
	}

s3:							// option to calibrate sensor four.
	glcd_fillScreen(OFF);   
	sprintf(text,"Sensor # 4");
	glcd_text57(0,0, text,1,ON); 
	sprintf(text,"1-> Incre.");
	glcd_text57(0,35, text,1,ON); 
	sprintf(text,"2-> Decre."); 
	glcd_text57(0,45, text,1,ON);
	sprintf(text,"3-> Acep."); 
	glcd_text57(0,55, text,1,ON);
	set_calib_values(s,3);
	linear_reg(s,3);
	k=0;
	goto intro;
exit:							// end of calibration.
	free(voltage);
	free(load);
}
Ejemplo n.º 14
0
void main()
{

   
   
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT1);
   enable_interrupts(global);
   
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   setup_adc( ADC_OFF );


   //setup_adc_ports(NO_ANALOGS|VREF_VREF);


  // setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_PLL_OFF);   
   
   
   glcd_init(ON);    
   
   
   
         int8 axt,axp,axv;
         axt = read_eeprom(0x01);
         axp = read_eeprom(0x02);
         axv = read_eeprom(0x03);
   
         if(axt==1)
         {
            UniTemp[0]="C";
         }
         if(axt==2)
         {
            UniTemp[0]="F";
         }
         if(axp==1)
         {
            UniPres[0]="Pa";
         }
         if(axp==2)
         {
            UniPres[0]="mBa";
         }
         if(axv==1)
         {
            UniVel[0]="m/s";
         }
         if(axv==2)
         {
            UniVel[0]="km/h";
         }
         if(axv==3)
         {
            UniVel[0]="Nud";
         }
         
         
         
   
  
   
   int16 auxi;
   int8 type,z;
   int8 string[10];
   int16 tt;
   int32 pp;
   char tprint [15];
   char pprint [15];
   char ttt[10];
   char ppp[10];
      char temp[] = "T:";
      char pres[] = "P:";
      
   for (z=0;z<15;z++)
      {
         tprint[z]=0;
         pprint[z]=0;
      }
   //firstrun = read_eeprom(0x00);      
  

      draw_sect();
   while (1)
   {
     
      
      
      
      if (firstrun==71)
      {
         glcd_loadscreen();
         glcd_showlogo();
         delay_ms(1500);
         menu_mainmenu();
         firstrun = 0;
         write_eeprom(0x00, firstrun);
      }
      
      if (config==1)
      {
        
        
        
        
        
         menu_mainmenu();
         if(UniTemp[1]=="C")
         {
            write_eeprom(0x01, 1);
         }
         else if(UniTemp[1]=="F")
         {
            write_eeprom(0x01, 2);
         }
         if(UniPres[1]=="P")
         {
            write_eeprom(0x02, 1);
         }
         else if(UniPres[1]=="m")
         {
            write_eeprom(0x02, 2);
         }
         if(UniVel[1]=="m")
         {
            write_eeprom(0x03, 1);
         }
         else if(UniVel[1]=="k")
         {
            write_eeprom(0x03, 2);
         }
         else if(UniVel[1]=="N")
         {
            write_eeprom(0x03, 3);
         }
         
        
         
         pressed=0;
         config=0;
      }
      
      if (try==1)
      {
         
               try=0;
               output_toggle(PIN_C2);
      }
      
      while(bkbhit) 
      {
         auxi = bgetc();
         if (auxi==0x54)
         {
            type=1;
            for(i=0;i<15;i++)
            {                   
               string[i]=0x00;                          
            }
            i = 0;
         }
         if (auxi==0x50)
         {
            type=2;
            for(i=0;i<15;i++)
            {                   
               string[i]=0x00;                          
            }
            i = 0;
         }
         if (auxi!=0x0D)
         {
            
         }
         if (type==1)      //Temperatura
         {
         
            if ((auxi!=0x0D)&&(auxi!=0x54))
            {
               string[i] = auxi;
               i++;
            }
            if (auxi==0x0D)
            {
               str_init(tprint);
               tt = atol(string);  
               sprintf(ttt,"%3.1w",tt);
               strcat(tprint,temp);
               strcat(tprint,ttt);
               strcat(tprint,UniTemp);
                draw_sect();
               glcd_text_sec(1, 1, tprint, OFF);
               glcd_update();
               
            }
         }
         if (type==2)      //Presion
         {
            if ((auxi!=0x0D)&&(auxi!=0x50))
            {
               string[i] = auxi;
               i++;
            }
            if (auxi==0x0D)
            {
               str_init(pprint);
               pp = atoi32(string);
               sprintf(ppp,"%3.1w",pp);
               strcat(pprint,pres);
               strcat(pprint,ppp);
               strcat(pprint,UniPres);  
                draw_sect();
               glcd_text_sec(1, 2, pprint, OFF);
               glcd_update();
            }
         }
         
         glcd_update();
         //END KBHIT
      }
      
      
      glcd_update();
      //ENDWHILE
   }
//ENDMAIN
}
Ejemplo n.º 15
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
}