void init_pic()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   EXT_INT_EDGE(L_TO_H);

   OUTPUT_B(0);
   OUTPUT_C(0);

   SET_TRIS_B(0b01000111);   //pins B0, B1 and B2 are set to give inputs. b0 is the external interuupt pin
   SET_TRIS_C(0b00000000);
   SET_TRIS_D(0b00000000);

   set_adc_channel(0);            //the next read_adc call will read channel 0
}
Esempio n. 2
0
void main()
{
   int16 valor;
   float tensao;
   lcd_init();



   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_16);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_adc_channel(0);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!

   while(1)
   {
      valor = read_adc();
      tensao = valor*5.0/1024.0;
      printf("ADC = %04ld",valor);
      printf("    Tensao = %.3fV\r", tensao);
      printf(lcd_putc,"\fADC = %ld",valor);
      printf(lcd_putc,"\nTensao = %.3fV",tensao);
      delay_ms(250);
   }
   
}
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

while (TRUE) {

      printf("\r\nSinyali Baslatmak icin B tusuna basiniz");
      if (getchar() == 'b')         //eðer b tuþuna basarsan
      {
         printf("\n1 hz sinyal aktif edildi\r");
            while (1) {
               output_high(PIN_B0);
               delay_ms(500);
               output_low(PIN_B0);
               delay_ms(500);
            }
      }
   }
}
Esempio n. 4
0
void main(){
   
   //CHAR letA[]="A";
   //CHAR letB[]="B";
   //CHAR letC[]="C";
   //CHAR espera[]="teste";
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_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);

   glcd_init(ON);   //inicializa o display
   glcd_fillScreen(0); //limpa display inteiro
   
   //glcd_text57(34, 55, letA, 1, 1);
   //glcd_rect(46,53,60,63,1,1);
   //glcd_text57(48,  55, letB, 1, 0);

   while(TRUE){
   
   glcd_imagem(1);
   delay_ms(3000);
   glcd_fillScreen(0); //limpa display inteiro
   glcd_imagem(2);
   delay_ms(3000);
   glcd_fillScreen(0); //limpa display inteiro
   
   }
}
void init_pic()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   EXT_INT_EDGE(L_TO_H);

   OUTPUT_B(0);
   OUTPUT_C(0);

   SET_TRIS_B(0b01000111);   //pins B0, B1, B2 and B6 are set to give inputs. B0 is the external interuupt pin
                             //B0, B1 & B2 are used for people counting. B6 for zero crossing detection in fan controlling
   SET_TRIS_C(0b00000000);
   SET_TRIS_D(0b00000000);   //D port except D0 pin, is used for lcd panel

   set_adc_channel(0);            //the next read_adc call will read channel 0
}
Esempio n. 6
0
//=============================================================================
void init_prog(void)
{
setup_wdt(WDT_OFF);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);                                                
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0
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_low_volt_detect(FALSE);              
setup_oscillator(OSC_32MHZ);                                        

set_tris_a(0xFF);//7F
set_tris_b(0xFF); //FF
set_tris_c(0x94);//94
set_tris_d(0xFF); //02                                     
set_tris_e(0xF0);  //f0   
set_tris_f(0xFF);//ff
set_tris_g(0xFC); //04
output_a(0x00);
output_b(0x00);
output_c(0x00);
output_d(0x00);
output_e(0x00);
output_f(0x00);
output_g(0x00);
}
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit);   //RTCC_DIV_32 -> 122 Hz ou 30 Hz por nivel
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(GLOBAL);

   
   set_tris_a (0b11110000);
   set_tris_c (0b00000000);
   set_tris_d (0b00000000);
   
   
   while(1){
	delay_ms(10);
   }

}
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_bit);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(GLOBAL);
   
   set_tris_a (0b11110000);
   set_tris_b (0b00000000);
   set_tris_c (0b00000000);
   
   cubeLevelC0 = 0xFF;
   cubeLevelC1 = 0x00;
   cubeLevelC2 = 0xFF;
   cubeLevelC3 = 0x00;
   
   cubeLevelD0 = 0x00;
   cubeLevelD1 = 0xFF;
   cubeLevelD2 = 0x00;
   cubeLevelD3 = 0xFF;

}
Esempio n. 9
0
void main()
{

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   
      set_adc_channel(0);            // set ref valus
      delay_ms(100);
      ref_0 =read_adc();
      delay_ms(100);
      
      set_adc_channel(3);            // set ref valus
      delay_ms(100);
      ref_3 =read_adc();
      delay_ms(100);
   
   output_b(0b11111111);
   delay_ms(700);
   output_b(0);
   
   while(1){
      set_adc_channel(0);
      delay_ms(20);                        // take readings
      adc_val_0 =read_adc();
      delay_ms(20);
      if(adc_val_0 > ref_0+cons){
         l_0 =1;
         output_high(pin_d7);
         delay_ms(500);
      }
      else{
         l_0=0;
         output_low(pin_d7);
     //    delay_ms(500);
      }
      
      set_adc_channel(3);
      delay_ms(20);                        // take readings
      adc_val_3 =read_adc();
      delay_ms(20);
      if(adc_val_3> ref_3+cons){
         l_3 =1;
         output_high(pin_d6);
         delay_ms(500);
      }
      else{
         l_3=0;
         output_low(pin_d6);
      }
   }
}
Esempio n. 10
0
File: main.c Progetto: Nico01/unidos
int main(int argc, char **argv)
{
    uc_engine *uc;
    uc_hook trace;
    uc_err err;

    uint8_t memory[MEM_SIZE];

    if (argc == 1) {
        usage(argv[0]);
        return -1;
    }

    const char *fname = argv[1];

    err = uc_open (UC_ARCH_X86, UC_MODE_16, &uc);
    if (err) {
        fprintf(stderr, "Cannot initialize unicorn\n");
        return 1;
    }

    // map 64KB in
    if (uc_mem_map (uc, 0, MEM_SIZE, UC_PROT_ALL)) {
        fprintf(stderr, "Failed to write emulation code to memory, quit!\n");
        uc_close(uc);
        return 0;
    }

    // initialize internal settings
    int21_init();

    //load executable
    size_t fsize = load_com(uc, memory, fname);

    // setup PSP
    setup_psp(0, memory, argc, argv);

    // write machine code to be emulated in, including the prefix PSP
    uc_mem_write(uc, 0, memory, DOS_ADDR + fsize);

    // handle interrupt ourself
    uc_hook_add(uc, &trace, UC_HOOK_INTR, hook_intr, NULL);

    err = uc_emu_start(uc, DOS_ADDR, DOS_ADDR + 0x10000, 0, 0);
    if (err) {
        fprintf(stderr, "Failed on uc_emu_start() with error returned %u: %s\n",
                err, uc_strerror(err));
    }

    uc_close(uc);

    return 0;
}
Esempio n. 11
0
/*======================= configuracon de dispositivos =======================*/
void setup_devices(){
	//int myerror = 0;
   /*========================= configuracion del USB =========================*/
   myerror = COM_init();
   /*========================= configuracion del MMA7455 =====================*/
   //myerror += MEMORIA_init_hw();
   //myerror += MEMORIA_init();
   
   /*========================= conversor analogo/digital =====================*/
   // myerror = AD_init_adc();
   
   /*========================= modulo CPP ====================================*/
   //myerror = CP_init_ccp();
   
   /*========================= configuracion del Reloj Digital ===============*/
   //ds1307_init(DS1307_OUT_ON_DISABLED_HIHG | DS1307_OUT_ENABLED | DS1307_OUT_1_HZ);
   //ds1307_set_date_time(0x0d, 0x01, 0x0d, 0x00, 0x0a, 0x2a, 0x00);
   
   
   
   /*-------------------------------------------------------------------------*/
   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_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   #ifndef CAPTURA_FRECUENCIA_H
	setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
	setup_ccp1(CCP_OFF);
   #endif
   
   /*-------------------------------------------------------------------------*/
   
   /*===================para los indicadores========================*/
   set_tris_e(0x00);
   set_tris_b(0x00);
   set_tris_c(0x80);		//configuracion para el modulo de memoria
   set_tris_d(0x48);
   output_bit(INDICADOR_USB, 0);
   output_bit(INDICADOR_AMARILLO, 1);
   ////////////////////////////////
   output_low(SPI_SCL);
   output_high(SPI_SS);
   output_low(SPI_MOSI);
   output_high(SPI_MISO);
   ////////////////////////////////
   //delay_ms(3000);
   /*===============================================================*/
   return;
}
Esempio n. 12
0
void main()
{


   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_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);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_low_volt_detect(FALSE);


    //Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
    //intitSerie(31);

   set_tris_a(0b00101111);
   set_tris_c(0b11111101);
   Set_tris_D(0b11100000); // port D : Led
   
   lectureTrame();
   
   while(true){
   
         if(truc=='c'){
         clignotement();
         }
         if(truc=='j'){
         johnson();
         }
         if(truc=='t'){
         compteur();
         }
         if(truc=='h'){
         chenillard();
         }
      
   }
}
Esempio n. 13
0
void main()
{
                                                                                                                                                                                 
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);

set_tris_b(0x00);
set_tris_d(0b00000001);
set_tris_a(0x00);


output_b(0x00);


   start:
    if (input(pin_a0)==true)
    { 
    while(1==1){
      for(a=pin_b0; a<=pin_b5; a++)
      {
         output_high(a);
         delay_ms(100);
         output_low(a);
      
      }
      for( b=a; b>=pin_b0; b--)
      {
         output_high(b);
         delay_ms(100);
         output_low(b);
       
      }
 
    }
    a=0;
    b=0;
    }
     goto start;             
}
Esempio n. 14
0
void PowerOnSetProc()
{		 	
	port_b_pullups(TRUE);	output_b(0xff); output_c(0xff);		
	
	set_tris_A(0b00000011);	set_tris_B(0b01111111);

	set_tris_D(0b00000000);	set_tris_E(0b00000000);
	
	set_tris_C(0b10010000);
	
	setup_adc_ports(NO_ANALOGS);
	setup_adc(ADC_OFF);

	setup_comparator(NC_NC_NC_NC);
	setup_vref(FALSE);
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

	setup_timer_2(T2_DIV_BY_4,250,2);		 // 8,000,000 / (4 * 8 * (249 +1)) = 1,000 = 1/1000 sec
	set_timer2(0);
	enable_interrupts(INT_TIMER2);
	
	// LCD 초기화 하기 전에 대기 없으면 이상한 현상이 생김  
	delay_ms(100); 

	LCD_Initialization();				

	setup_psp(PSP_DISABLED);	
	delay_ms(250);
	SerialPortSetup();	

	LCD_Clear();
	enable_interrupts(INT_RDA);	
	enable_interrupts(GLOBAL);	

             //"01234567890123456789"
	strcpy(st, "DIGITAL OPERAT      "); PrintLCD(0,0,st);
	strcpy(st, "[EwDo-21] v2.60     "); PrintLCD(1,0,st);
	strcpy(st, "EunWho Power Electic"); PrintLCD(2,0,st);
	strcpy(st, "TEL 82-51-262-7532  "); PrintLCD(3,0,st);
	delay_ms(3250);
	delay_ms(3250);
}
Esempio n. 15
0
void main()
{
   int i, seq[10] = {n0, n1, n2, n3, n4, n5, n6, n7, n8, n9}, tensao;

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_adc_channel(0);

   //TODO: User Code
   while(TRUE)
   {
      tensao = read_adc();
      if(tensao >= 127)
      {
         for(i = 1; i < 10; i++)
         {
            output_D(seq[i]);
            delay_ms(1000);
         }
      }
      else
      {
         for(i = 9; i >= 1; i--)
         {
            output_D(seq[i]);
            delay_ms(1000);
         }
      }
   }

}
Esempio n. 16
0
//------------------------------------------------------------------------------
void main(){
   int i;
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   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);
   disable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

   output_low(PIN_C5);
	
   while(TRUE){

      if(f_process){
         f_process=0;
         output_toggle(PIN_C5);
         disable_interrupts(INT_RDA);
			printf("\n\r");
         for(i=0;i<(cont-2);i++){
         	printf("vector[%u]=%c\n\r",i,p[i]); //muestro los datos recibidos
         }
         procesar_guardar();
         cont=0;
         printf("Fin programacion\n\r");
         enable_interrupts(INT_RDA);
      }
   }
}
Esempio n. 17
0
//------------------------------------------------------------------------------
void init_prog(void)
{
setup_wdt(WDT_OFF);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);                                                
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0
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_low_volt_detect(FALSE);              
setup_oscillator(OSC_32MHZ);                                        

set_tris_a(0x00);
set_tris_b(0x24); 
set_tris_c(0x80);
set_tris_d(0x00);                                      
set_tris_e(0x15);     
set_tris_f(0x58);
set_tris_g(0x10);
output_a(0x00);
output_b(0x00);
output_c(0x00);
output_d(0x00);
output_e(0x00);
output_f(0x00);
output_g(0x00);
// RF Modul and PA/LNA activation
 
   IOpin.modulepower=0;
   IOpin.moduleCTX=1;
   IOpin.moduleCPS=0;
   IOpin.modulePWRUP=1;
   
}
Esempio n. 18
0
//*****************************************************************************************
//*****************************************************************************************
//P RO G R A M A     P R I N C I P A L
//*****************************************************************************************
//*****************************************************************************************
void main(){
   float32* fltPtr;
   float32 varX,varY,varZ;
   float32 Xp,Yp;
   float32 fx,fy,fz;
   float incX;
   float incY;
   
   char x,y,z;
   char posicion;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_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_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0xC0);
   set_tris_d(0x00);
   set_tris_e(0x00);

   DELAY_MS(200);

   output_b(0xFF);

   GLCD_init(1);

   DELAY_MS(500);

   output_b(0x00);

   //Setear propiedades de la grafica.
   graph.x1=0.0;
   graph.y1=0.0;
   graph.x2=127.0;
   graph.y2=63.0;

   graph.minX=-1.0;
   graph.maxX=1.0;
   graph.minY=-1.0;
   graph.maxY=1.0;

   graph.minViewX=-2.5;
   graph.maxViewX=2.5;
   graph.minViewY=-1.25;
   graph.maxViewY=1.25;

   printf("Hecho por Bruno Fascendini @ 2009 para uControl y Todopic\r\ncomo parte de proyecto calculadora cientifica con PIC del foro uControl\r\n");
   printf("Parseador version: %s Evaluador version: %s\r\n",ParserVer,EvaluadorVer);
   //menú:
   printf("Ingrese la superficie a graficar: ");

   posicion=0;
   do{
      EquIn[posicion]=getc();
      if(posicion>0 && EquIn[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(EquIn[posicion-1]!=13);
   EquIn[posicion]='\0';

   printf("Ha pedido que se grafique la ecuacion: %s",EquIn);

   printf("Ingrese valor minimo de x: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.minX=atof(temp);
   
   printf("Ingrese valor maximo de x: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.maxX=atof(temp);

   printf("Ingrese valor minimo de y: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.minY=atof(temp);
   
   printf("Ingrese valor maximo de y: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.maxY=atof(temp);

   graph.minViewX=graph.minX;
   graph.maxViewX=graph.maxX;
   graph.minViewY=graph.minY;
   graph.maxViewY=graph.maxY;

   //Calculating centers...
   graph.centerX= (graph.x2-graph.x1)/2;
   graph.centerY= (graph.y2-graph.y1)/2;

   incX=(graph.maxX-graph.minX)/50;       //set step cuantity for X axis
   incY=(graph.maxY-graph.minY)/50;       //set step cuantity for Y axis

   printf("Graficando...\r\n");

   //////////////////////////////////////////////////
   //PROCESO..............
   //comienzo del parseado de la ecuacion ingresada...
   //////////////////////////////////////////////////

   strlwr(EquIn);                        //1) PASAR EQUACION A MINUSCULAS

   //printf("Cadena en minusculas: %s\r\n",EquIn); 
                                        
   strCodificar(EquIn);                   // 2) REDUCIR ECUACION PARA OPTIMIZAR PROCESADO POSTERIOR

   printf("Cadena codificada: %s\r\n",EquIn);

   strPosFijar(EquIn,EquIn);              // 3) Pasar a notación PostFija

   printf("Cadena en notacion postfija: %s\r\n",EquIn);

   //cut unuseful zones...
   //if(graph.minX<graph.minViewX) graph.minX=graph.minViewX;
   //if(graph.maxX>graph.maxViewX) graph.maxX=graph.maxViewX;
   //if(graph.minY<graph.minViewY) graph.minY=graph.minViewY;
   //if(graph.maxY>graph.maxViewY) graph.maxY=graph.maxViewY;

/*
//Ejes!
   varx=0.0;
   varz=0.0;
   for(vary=0.0;Xp>=0;vary+=0.4){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }

   vary=0.0;
   varz=0.0;
   for(varx=0.0;Xp<Radius+CentroX;varx+=0.4){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }

   varx=0.0;
   vary=0.0;
   for(varz=0.0;Yp>0;varz+=1.0){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }
*/


/*
//2D:
for(varX=graph.minX;varX<graph.maxX;varX+=0.1){
   fltPtr=strEvaluar(EquIn,StackNum,&varX,NULL,NULL);
   printf("X: %f Y: %f\r\n",varX,*fltPtr);

   Xp=varX+graph.centerX;
   Yp=graph.centerY-(*fltPtr);

   //ensure that pixel belongs to actual graph section...else do not show it!(out of bounds)
   if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1);
}

printf("HECHO!\r\n");
while(1);
*/

//Proyeccion Isométrica...
   for(varY=graph.minY;varY<graph.maxY;varY+=incY){
      for(varX=graph.minX;varX<graph.maxX;varX+=incX){
         //indicate no error...
         errno=0;
         fltPtr=strEvaluar(EquIn,StackNum,&varX,&varY,NULL);
         //if errors during calculating...do not bother at all..
         if(errno) continue;
         
         //calculate isometric proyection
         varZ = *fltPtr;
         Xp = RAIZ2SOBRE2 * (varX - varY);
         Yp = (RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY));
            
         //ensure that values are inside drawing zone...
         if(Xp>=graph.minViewX && Xp<=graph.maxViewX && Yp>=graph.minViewY && Yp<=graph.maxViewY){
            //printf("X: %f Y: %f Z: %f\r\n",varX,varY,varZ);
         
            //now let´s ubicate them inside actual graphic bounds...
            Xp=(Xp-graph.minViewX)*(float32)(graph.x2-graph.x1)/(graph.maxViewX-graph.minViewX)+(float32)graph.x1;
            Yp=(float32)graph.y2-((Yp-graph.minViewY)*(float32)(graph.y2-graph.y1)/(graph.maxViewY-graph.minViewY))+(float32)graph.y1; 

            //printf("XP: %f YP: %f\r\n",Xp,Yp);
            if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1);            
         }
      }
   }

   printf("Proceso de graficacion finalizado.\r\n");

/*
//polares
  for(varY=-PI/2;varY<PI/2;varY+=PI/63){
      for(varX=-PI;varX<PI;varX+=2*PI/31){
         fX=Radius*cos(varX)*cos(varY);
         fY=Radius*cos(varX)*sin(varY);
         fZ=Radius*sin(varX);

         Xp=Sqrt(2.0) / 2.0 * (fX - fY) * Distance + CentroX;
         Yp = (Sqrt(2.0 / 3.0) * fZ - (1.0 / Sqrt(6.0)) * (fX + fY)) * Distance + CentroY;
         GLCD_pixel((int8)Xp,(int8)Yp,1);
       //printf("Xp: %f Yp: %f\r\n",Xp,Yp);
      }
  }
*/  
  
 //printf("EL resultado de la ecuacion es: %9f\r\n",*fltPtr);
   while(1);
}
Esempio n. 19
0
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_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);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   set_tris_a(0b00000011);
   set_tris_b(0b00000000);
   set_tris_c(0b10110011);
   set_tris_d(0b11110000);
   set_tris_e(0b00000100);
   
   while(1)
   {
  
      // waits for B1 to go high
      while ( !input(PIN_B1) )
      {}




   
      //PE-
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tit
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Noe-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //el
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Quand
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Des-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cen-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //dras
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //du
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //ciel
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //A-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vec
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tes
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //ets
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //par
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //mi-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //liers
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //N'ou-
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //blie
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //pas
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //mon
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //pet-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tit
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //nier
      playSound(NOTE_RE4,TEMPS_BLANCHE);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Mais
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //a-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //vant
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //de
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //par-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tir
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fau-
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //dra
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //te
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cou-
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vrir
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //De-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //hors
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fait
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //dé-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jà
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //froid
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //C'est
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //un
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //peu
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //a
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //cau-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Moi
      playSound(NOTE_DO4,TEMPS_RONDE);
      delay_us(WAIT);
      //--------------------------------
      //Il
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //me
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //tar-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //tant
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      //que
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //le
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //jour
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //lè-
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      //ve
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //Pour
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //voir
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //si
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //m'as
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //ap-
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //por-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //té
      playSound(NOTE_RE4,TEMPS_RONDE);
      delay_us(WAIT);
      //--------------------------------
      //tous
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //les
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //beaux
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //joux
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //que
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //je
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //vois
      playSound(NOTE_FA4,TEMPS_NOIRE);
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //en
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //re-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //ve
      playSound(NOTE_SI3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //et
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //que
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //je
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //t'ai
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //com-
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //man-
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //de
      playSound(NOTE_SOL4,TEMPS_BLANCHE);
      playSound(NOTE_SOL4,TEMPS_BLANCHE);
      delay_us(WAIT);
       //PE-
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tit
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Noe-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //el
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Quand
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Des-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cen-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //dras
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //du
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //ciel
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //A-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vec
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tes
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //ets
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //par
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //mi-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //liers
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //N'ou-
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //blie
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //pas
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //mon
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //pet-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tit
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //nier
      playSound(NOTE_RE4,TEMPS_BLANCHE);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Mais
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //a-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //vant
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //de
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //par-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tir
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fau-
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //dra
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //te
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cou-
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vrir
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //De-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //hors
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fait
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //dé-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jà
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //froid
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //C'est
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //un
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //peu
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //a
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //cau-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Moi
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      playSound(NOTE_SOL4,TEMPS_RONDE);
      delay_us(WAIT);
   }
   
   
   
}
Esempio n. 20
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
}
Esempio n. 21
0
void main()
{
    setup_adc_ports(NO_ANALOGS);
    setup_adc(ADC_CLOCK_DIV_2);
    setup_psp(PSP_DISABLED);
    setup_spi(SPI_SS_DISABLED);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    setup_timer_1(T1_DISABLED);
    setup_timer_2(T2_DIV_BY_16,155,1);
    setup_ccp1(CCP_PWM);
    setup_ccp2(CCP_PWM);
    set_pwm1_duty(312); // Inicia el Ciclo de Trabajo PWM1 en 50%.
    set_pwm2_duty(312); // Inicia el Ciclo de Trabajo PWM2 en 50%.
    setup_comparator(NC_NC_NC_NC);
    setup_vref(FALSE);

    set_tris_a(0b11100000); // 
    set_tris_c(0b10000000); //Pone RC7 como input y RC6 como output (y de 5 a 0 también)
    set_tris_b(0b00000000); // Habilita como salidas los pines B0, B1,...,B7
    set_tris_e(0b010);



    // ************************ CONFIGURACIÓN PWM1 y PWM2: ************************
    int32 brillo=0;
    int32 exposicion=500;   //Tiempo de exposición de la cámara en [ms]
    int32 der_steps=0;
    int32 izq_steps=0;
    int32 led=0;
    int32 motor=0;
    int32 direccion=0;
    int32 pasos=0;
    int32 velocidad=0;
    char leido_pantalla[5];

    output_low(PIN_B0);
    output_low(PIN_B1);
    output_low(PIN_B2);
    output_low(PIN_B3);
    output_low(PIN_B4);
    output_high(PIN_B6); // Siempre en 5V para conectar pull up 10kOhm de RA4 para SLEEP MOTOR 3 (altura)

    set_pwm1_duty(0); // Mantiene Ciclos en 0 para reducir consumo al iniciar.
    set_pwm2_duty(0);

    //*************** INICIO ***************



    while(true)
    {

        char seleccionar=0;
        output_low(PIN_A2);
        output_low(PIN_A3);
        output_low(PIN_A4);


        printf("Set parameters: e=exposicion(%Ld), v=velocidad(%Ld)\n\r",exposicion,velocidad);
        printf("                b=brillo(%Ld), d=direccion(%Ld), p=pasos(%Ld)\n\r",brillo,direccion,pasos);
        printf("                l=led(%Ld), m=motores(%Ld) \n\r",led,motor);
        seleccionar=getc();

        switch(seleccionar)
        {

            case 'v':
                printf("Ingrese Velocidad en [ms] y [ENTER]\n\r");
                fgets(leido_pantalla);
                velocidad=atoi32(leido_pantalla);
                break;

            case 'e': 
                printf("Ingrese tiempo de exposicion en [ms] y [ENTER]\n\r");
                fgets(leido_pantalla);
                exposicion=atoi32(leido_pantalla);
                break;

            case 'b':
                printf("Ingrese Ciclo de Trabajo para PWM1 (0-100) (brillo) y [ENTER]:\n\r");
                fgets(leido_pantalla);
                brillo=atoi(leido_pantalla);
                set_pwm1_duty(brillo*20000000/(100*2000*16));
                set_pwm2_duty(brillo*20000000/(100*2000*16));
                break;

            case 'l':
                printf("Ingrese Led a encender: 0 a 7 y [ENTER]\n\r");
                fgets(leido_pantalla);
                led=atoi32(leido_pantalla);
                break;

            case 'd':
                printf("Ingrese direccion 1=Derecha, 0=Izquierda y [ENTER]\n\r");
                fgets(leido_pantalla);
                direccion = atoi32(leido_pantalla);               
                break;

            case 'p':
                printf("Ingrese el numero de pasos a utlizar y [ENTER]\n\r");
                fgets(leido_pantalla);
                pasos = atoi32(leido_pantalla);               
                break;

            case 'm':
                printf("Ingrese el numero de motor a utlizar: 1,2 o 3 y [ENTER]\n\r");
                fgets(leido_pantalla);
                motor = atoi32(leido_pantalla);               
                break;

            case '1':
                led_on(led);
                break;

            case '2':
                led_off();
                break;

            case '3':
                motor_move(motor,pasos,direccion);
                break;

            case '4':
                led_on_off(led,exposicion);
                break;

            case '5': 
                int32 pasos_restantes;
                int32 steps;
                int dir;
                dir = direccion;
                steps = pasos;
                pasos_restantes = pasos;
                motor_on(motor); 
                while(pasos_restantes > 0){
                    printf("pasos_restantes: %Ld\n\r",pasos_restantes);
                    delay_us(200);
                    steps = motores4(pasos_restantes,dir,velocidad);
                    pasos_restantes = pasos_restantes - steps;
                    if (pasos_restantes <=0)
                        break;
                    delay_us(200);
                    dir = (dir == 0)?1:0;
                    motores2(2000,dir);
                }
                break;

            case '6': 
                int32 pasos_restantes2;
                int32 steps2;
                int dir2;
                dir2 = direccion;
                steps2 = pasos;
                pasos_restantes2 = pasos;
                motor_on(motor); 
                while(true){
                    printf("pasos restantes: %Ld\n\r",pasos_restantes2);
                    delay_us(200);
                    steps2 = motores4(pasos_restantes2,dir2,velocidad);
                    delay_us(200);
                    dir2 = (dir2 == 0)?1:0;
                    motores2(2000,dir2);
                    pasos_restantes2 = pasos_restantes2 - steps2;
                    if (pasos_restantes2 <=0)
                        pasos_restantes2 = pasos;
                }
                break;

            case '7':
                int32 steps3; 
                motor_on(motor); 
                steps3 = motores4(pasos,direccion,velocidad);
                if (steps3 - pasos < 0){
                    direccion = (direccion == 0)?1:0;
                    motores2(2000,direccion);
                    delay_us(200);
                    motores3(2147483640,direccion);
                    direccion = (direccion == 0)?1:0;
                    motores2(2000,direccion);
                }
                break;

            case '8': 
                printf("Setup Calibracion Quick\n\r");
                motor_on(motor); 
                motores3(2147483640,DERECHA);
                delay_us(200);
                motores2(2000,IZQUIERDA);
                delay_us(200);
                izq_steps = motores3(2147483640,IZQUIERDA);
                delay_us(200);
                motores2(2000,DERECHA);
                delay_us(200);
                der_steps = motores3(2147483640,DERECHA);
                printf("izq_steps ->%Ld<-  \n\r",izq_steps);
                printf("der_steps ->%Ld<-  \n\r",der_steps);
                while(true){
                    motores2(izq_steps,IZQUIERDA);
                    delay_us(200);
                    motores2(der_steps,DERECHA);
                    delay_us(200);
                }

            case '9': 
                printf("Setup Velocidad ...\n\r");
                output_high(PIN_A4); 
                motores2(2000,IZQUIERDA);
                delay_us(200);
                izq_steps = motores3(2147483640,IZQUIERDA);
                delay_us(200);
                motores2(2000,DERECHA);
                delay_us(200);
                der_steps = motores3(2147483640,DERECHA);
                printf("izq_steps ->%Ld<-  \n\r",izq_steps);
                printf("der_steps ->%Ld<-  \n\r",der_steps);

                motores4(izq_steps,IZQUIERDA,velocidad);
                delay_us(200);
                motores4(der_steps,DERECHA,200);
                delay_us(200);
                break;

        }

    }



}  //FIN MAIN
Esempio n. 22
0
void main( void )
{
    unsigned char stateSem1 = vermelho;
    unsigned char stateSem2 = verde;
    unsigned char cntTimeSem1 = 0;
    unsigned char cntTimeSem2 = 0;
    unsigned char flgEnableSem1 = 0;
    unsigned char flgEnableSem2 = 0;
    setup_adc_ports( NO_ANALOGS );
    setup_adc( ADC_OFF );
    setup_psp( PSP_DISABLED );
    setup_spi( SPI_SS_DISABLED );
    setup_timer_0( RTCC_INTERNAL|RTCC_DIV_1 );
    setup_timer_1( T1_DISABLED );
    setup_timer_2( T2_DISABLED,0,1 );
    set_tris_c( 0x00 );
    //Inicializando os semáforos no estado conhecido.
    output_high( vermSem1 );
    output_high( verdeSem2 );

    while( 1 )
    {
        //máquina de estados do semáforo 1.
        switch( stateSem1 )
        {
        case vermelho:

            //Quando estiver no vermelho, se o flgEnableSem1 for verdadeiro, conto dois segundos antes de comutar para o estado verde.
            if( flgEnableSem1 == 1 )
            {
                cntTimeSem1++;

                if( cntTimeSem1 > 2 )
                {
                    cntTimeSem1 = 0;
                    stateSem1 = verde;
                    flgEnableSem1 = 0;
                    output_low( vermSem1 );
                    output_low( amarSem1 );
                    output_high( verdeSem1 );
                }
            }

            break;

        case amarelo:
            //Quando estiver no amarelo, conto 5 segundos antes de comutar para o vermelho. Observando que o estado amarelo de Sem1 habilita o flgEnableSem2, propiciando a
            //passagem de vermelho pra verde do semáforo2.
            cntTimeSem1++;

            if( cntTimeSem1 > 5 )
            {
                flgEnableSem2 = 1;
                stateSem1 = vermelho;
                cntTimeSem1 = 0;
                output_high( vermSem1 );
                output_low( amarSem1 );
                output_low( verdeSem1 );
            }

            break;

        case verde:
            //Quanto estiver no verde, aguardo 30 segundos antes e mudar para o vermelho.
            cntTimeSem1++;

            if( cntTimeSem1 > 30 )
            {
                cntTimeSem1 = 0;
                stateSem1 = amarelo;
                output_low( vermSem1 );
                output_high( amarSem1 );
                output_low( verdeSem1 );
            }

            break;
        }

        //máquina de estados do sem2
        switch( stateSem2 )
        {
            //Quando estiver no vermelho, se o flgEnableSem2 for verdadeiro, conto dois segundos antes de comutar para o estado verde.
        case vermelho:
            if( flgEnableSem2 == 1 )
            {
                cntTimeSem2++;

                if( cntTimeSem2 > 2 )
                {
                    stateSem2 = verde;
                    cntTimeSem2 = 0;
                    flgEnableSem2 = 0;
                    output_low( vermSem2 );
                    output_low( amarSem2 );
                    output_high( verdeSem2 );
                }
            }

            break;

        case amarelo:
            //Quando estiver no amarelo, conto 5 segundos antes de comutar para o vermelho. Observando que o estado amarelo de Sem1 habilita o flgEnableSem1, propiciando a
            //passagem de vermelho pra verde do semáforo1.
            cntTimeSem2++;

            if ( cntTimeSem2  > 5 )
            {
                cntTimeSem2 = 0;
                flgEnableSem1 = 1;
                stateSem2 = vermelho;
                output_high( vermSem2 );
                output_low( amarSem2 );
                output_low( verdeSem2 );
            }

            break;

        case verde:
            //Quanto estiver no verde, aguardo 30 segundos antes e mudar para o vermelho.
            cntTimeSem2++;

            if ( cntTimeSem2 > 30 )
            {
                cntTimeSem2 = 0;
                stateSem2 = amarelo;
                output_low( vermSem2 );
                output_high( amarSem2 );
                output_low( verdeSem2 );
            }

            break;
        }

        //Loop do programa será de 1segundo, que é a unidade mínima de contagem de tempo.
        delay_ms( 1000 );
    }
}
Esempio n. 23
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
}