void  RTCC_isr(void) {

	//output_toggle(PIN_B6);

   
   switch(levelEnable){
      case 0:output_a(level_0_Enable);
          output_c(cubeLevelC0);
             output_d(cubeLevelD0); 
      break;
      case 1:output_a(level_1_Enable);
          output_c(cubeLevelC1);
             output_d(cubeLevelD1);
      break;
      case 2:output_a(level_2_Enable);
          output_c(cubeLevelC2);
             output_d(cubeLevelD2);
      break;
      case 3:output_a(level_3_Enable);
          output_c(cubeLevelC3);
             output_d(cubeLevelD3);
      break;
   }
   
   if (levelEnable == 3){
      levelEnable = 0;
   }else{
       levelEnable++;
   }
   
   output_toggle(PIN_B6);
}
Ejemplo n.º 2
0
void driverDisplay( timeDef *time )
{
    unsigned char Umin = 0;
    unsigned char Dmin = 0;
    unsigned char Uhora = 0;
    unsigned char Dhora = 0;
    unsigned char display = 0;
    unsigned char input = 0;
    //Carrego os valores de dezena e unidade dos minutos e horas
    Dmin = time->minuto/10;
    Umin = time->minuto - 10*Dmin;
    Dhora = time->hora/10;
    Uhora = time->hora - 10*Dhora;

    while( display < 4 )
    {
        switch( display )
        {
        case 0:
            //Carrego os dados da porta, para não mudar o estado do outro decoder( 2 )
            input = portc&0xF0;
            //Carrego para os 4 bits menos significativos o estado atual do decoder 1
            output_c( input |= bcdTable[ Umin ] );
            break;

        case 1:
            //Carrego os dados da porta, para não mudar o estado do outro decoder
            input = portc&0x0F;
            //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 2
            output_c( input | ( bcdTable[ Dmin ]<<4 ) );
            break;

        case 2:
            //Carrego os dados da porta, para não mudar o estado do outro decoder( 3 )
            input = portd&0xF0;
            //Carrego para os 4 bits menos significativos o estado atual do decoder 4
            output_d( input |= bcdTable[ Uhora ] );
            break;

        case 3:
            //Carrego os dados da porta, para não mudar o estado do outro decoder
            input = portd&0x0F;
            //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 4
            output_d( input | ( bcdTable[ Dhora ]<<4 ) );
            break;
        }

        display++;
    }
}
Ejemplo n.º 3
0
void_isr(void)
   {
   itr += 1;
   if (itr==1){
output_b(num[d1]);
output_c(0);
output_c(1);
}
if (itr==2){
output_b(num[d2]);
output_c(0);
output_c(2);
}
if (itr==3){
output_b(num[d3]);
output_c(0);
output_c(4);
}
if (itr==4){
output_b(num[d4]);
output_c(0);
output_c(8);
itr=0;
con+=1;
}
   
   }
Ejemplo n.º 4
0
void driverDisplay( unsigned long int temp )
{
   unsigned char Ucount = 0;
   unsigned char Dcount = 0;
   unsigned char Ccount = 0;
   unsigned char display = 0;
   unsigned char input = 0;
    //Carrego os valores de dezena e unidade dos minutos e horas
	Ccount = temp/100;
    Dcount = ( temp - Ccount*100 );
	Dcount = Dcount/10;
    Ucount = ( temp - Ccount*100 ) - 10*Dcount;

    
    while( display < 3 )
    {
        switch( display )
        {
        case 0:
            //Carrego os dados da porta, para não mudar o estado do outro decoder( 2 )
            input = portc&0xF0;
            //Carrego para os 4 bits menos significativos o estado atual do decoder 1
            output_c( input |= bcdTable[ Ucount ] );
            break;

        case 1:
            //Carrego os dados da porta, para não mudar o estado do outro decoder
            input = portc&0x0F;
            //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 2
            output_c( input | ( bcdTable[ Dcount ]<<4 ) );
            break;

		case 2:
			//Carrego os dados da porta, para não mudar o estado do outro decoder( 3 )
            input = portd&0xF0;
            //Carrego para os 4 bits menos significativos o estado atual do decoder 4
            output_d( input |= bcdTable[ Ccount ] );
            break;



			break;


        }
		
        display++;
    }
}
struct _camel_search_words *
camel_search_words_split (const guchar *in)
{
	gint type = CAMEL_SEARCH_WORD_SIMPLE, all = 0;
	GString *w;
	struct _camel_search_words *words;
	GPtrArray *list = g_ptr_array_new ();
	guint32 c;
	gint inquote = 0;

	words = g_malloc0 (sizeof (*words));
	w = g_string_new("");

	do {
		c = camel_utf8_getc (&in);

		if (c == 0
		    || (inquote && c == '"')
		    || (!inquote && g_unichar_isspace (c))) {
			output_w (w, list, type);
			all |= type;
			type = CAMEL_SEARCH_WORD_SIMPLE;
			inquote = 0;
		} else {
			if (c == '\\') {
				c = camel_utf8_getc (&in);
				if (c)
					output_c (w, c, &type);
				else {
					output_w (w, list, type);
					all |= type;
				}
			} else if (c == '\"') {
				inquote = 1;
			} else {
				output_c (w, c, &type);
			}
		}
	} while (c);

	g_string_free (w, TRUE);
	words->len = list->len;
	words->words = (struct _camel_search_word **)list->pdata;
	words->type = all;
	g_ptr_array_free (list, FALSE);

	return words;
}
Ejemplo n.º 6
0
void driverDisplay( unsigned char velocidade )
{
    unsigned char Umin = 0;
    unsigned char Dmin = 0;
   unsigned char display = 0;
   unsigned char input = 0;
    //Carrego os valores de dezena e unidade dos minutos e horas
    Dmin = velocidade/10;
    Umin = velocidade - 10*Dmin;
    
    while( display < 2 )
    {
        switch( display )
        {
        case 0:
            //Carrego os dados da porta, para não mudar o estado do outro decoder( 2 )
            input = portc&0xF0;
            //Carrego para os 4 bits menos significativos o estado atual do decoder 1
            output_c( input |= bcdTable[ Umin ] );
            break;

        case 1:
            //Carrego os dados da porta, para não mudar o estado do outro decoder
            input = porta&0xF0;
            //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 2
			output_a( input |= bcdTable[ Dmin ] );            
            break;

        }

        display++;
    }
}
Ejemplo n.º 7
0
//                        ** Grundinitialisierung **
void coldstart () 
{   
    setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
   setup_comparator(NC_NC_NC_NC);
   output_a (0b00001000);
   output_b (0);
   output_c (0);
   output_d (0);
   output_e (0);
   set_tris_a (TRISA_INIT);               // Datenrichtung Port A
   set_tris_b (TRISB_INIT);               // Datenrichtung Port B
   set_tris_c (TRISC_INIT);
   set_tris_d (TRISD_INIT);
   set_tris_e (TRISE_INIT);
   port_b_pullups(TRUE);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_BIT);
                                    // Timer0 intern, Takt 20.00/4/64 = 78.125 KHz
                                       // Interrupt alle 256/15.625 = 3.2768 ms (305Hz)
                                       // Korrekturwert für 10 ms: 156 Timerclicks
                                       // -> Timer wird auf 256-156=100 vorgestellt 
      set_timer0 (Timerstartwert_K);            // Timerwert auf Startwert setzen
      enable_interrupts(INT_TIMER0);
   setup_timer_1(T1_DISABLED);               // Nur Timer0 Interrupt
   delay_ms (200);
}            
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
//PROGRAMA PRINCIPAL
void main ()
{
   int8 DisNumbs[10] = {   //Este arreglo guarda los códigos para la representación de los números en el display.
      0b00111111, //0
      0b00000110, //1
      0b01011011, //2
      0b01001111, //3
      0b01100110, //4
      0b01101101, //5
      0b01111101, //6
      0b00000111, //7
      0b01111111, //8
      0b01101111  //9
   };
//Parámetros de Timer0.
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
//Habilitación de interrupciones.
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
//Parámetros del ADC.
   setup_adc_ports(RA0_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);   //Se requiere un pequeño delay para estabilizar la señal al cambiar de canal.
//Puertos usados para displays en salida.
   set_tris_b(0x00);
   set_tris_c(0x00);
   set_tris_d(0x00);
   output_b(0x00);
   output_c(0x00);
   output_d(0x00);

   while (true) {
   //Se le da salida a los números calculados de acuerdo al display al que están conectados.
      if (readSens){
         readSens=false;
         ValAnalog = read_adc();   //Se lee y convierte el valor analógico a digital.
         Temperatura = (float)ValAnalog * (0.48875);   //Se convierte el valor digital a ºC
         Calcs();
      }
      output_b(DisNumbs[Decena]);
      output_c(DisNumbs[Unidad]);
      output_d(DisNumbs[Decimal]);
   }
}
Ejemplo n.º 10
0
void blinkLeds()
{
	if (alarmActived)
	{
		output_high(PIN_B1);
	}
	else
	{
		output_low(PIN_B1);
	}
	if (state == Normal)
	{
		output_low(PIN_B2);
		output_low(PIN_B3);
	}
	else if (state == ModeAlarmMin || state == ModeAlarmHour)
	{
		output_high(PIN_B3);
		output_low(PIN_B2);
	}
	else
	{
		output_high(PIN_B2);
		output_low(PIN_B3);
	}
	if (state != ModeAlarmMin && state != ModeAlarmHour)
	{
		output_c(getClockHour());
		output_d(getClockMin());
	}
	else
	{ 
		output_c(getAlarmHour());
		output_d(getAlarmMin());
	}
}
Ejemplo n.º 11
0
/**
 * Exibe tempo nos displays
 **/
void exibe_relogio(int horas, int minutos) {

    int hora_dezena_byte = 0;
    int hora_unidade_byte = 0;

    int minuto_dezena_byte = 0;
    int minuto_unidade_byte = 0;

    // mapear horas no array de bytes
    hora_dezena_byte = horas / 10; // ex.: 16 => (int)16/10 == 1 e 16%10 == 6
    hora_unidade_byte = horas % 10;
    output_c(dezena[hora_dezena_byte]|unidade[hora_unidade_byte]);
    
    // mapear minutos no array de bytes
    minuto_dezena_byte = minutos / 10;
    minuto_unidade_byte = minutos % 10;
    output_d(dezena[minuto_dezena_byte]|unidade[minuto_unidade_byte]);
}
Ejemplo n.º 12
0
void Portout (int Li_B,int Re_B)
{
   int Out_B = 0, I_B;
   
   for(I_B=0;I_B <=3;++I_B) Out_B  |= bit_test (Li_B,(3-I_B)) << I_B; // Bit0-3 auf 7-4
   swap (Out_B);
   swap (Re_B);
   for(I_B=0;I_B <=3;++I_B) Out_B  |= bit_test (Re_B,(I_B)) << I_B;
   Out_B ^= 255;
   output_d (Out_B);
   Out_B = 0;
   swap (Li_B);
   for(I_B=0;I_B <=3;++I_B) Out_B  |= bit_test (Li_B,(3-I_B)) << I_B;
   swap (Out_B);
   swap (Re_B);
   for(I_B=0;I_B <=3;++I_B) Out_B  |= bit_test (Re_B,(I_B)) << I_B;
   Out_B ^= 255;
   output_c (Out_B);
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
void main ()
{

set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);

output_c(0x00);
output_b(0x00);

setup_adc_ports(RA0_ANALOG);
set_adc_channel(0);
setup_adc(ADC_CLOCK_DIV_32);

enable_interrupts(int_rtcc);
enable_interrupts(GLOBAL);
set_timer0(0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);


while (true)
{
if(con==9){
cif = read_adc();
cif *= .488281;   //por que Vref / 1024 = 0.004882  x 100

aux=floor(cif); //floor me regresa el entero de cif en aux
dec=cif-aux;

d1=floor(aux/10);
aux-=d1*10;

d2=floor(aux);
d3=floor(dec/0.1);
d4=(floor(dec/0.01))-(d3*10);
con=0;
}

}

}
Ejemplo n.º 15
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;
   
}
Ejemplo n.º 16
0
/**
 *  Reseta display
 **/
void clean_displays() {
    output_c(dezena[0]|unidade[0]);
    output_d(dezena[0]|unidade[0]);
}
Ejemplo n.º 17
0
RTCC_isr() {
     char aux;
     int i;

     if (count ==  610) {
	  /* si entramos aqui ha pasado un segundo */
	  count = 0;
     
	  /* lectura del potenciometro */
	  valor_adc=read_adc() >> 2;
      
      
	  /* avanzamos un segundo a nuestra hora */
	  if (s == 59) {
	       s = 0;
	       if (m == 59) {
		    m = 0;
		    if (h == 23) {
			 h = 0;
		    }
		    else {
			 h++;
		    }
	       }
	       else {
		    m++;
	       }
	  } 
	  else {
	       s++;
	  }   


	  /* borrar la linea */
	  for(i=0; i<80; i++)       
	       printf("\b");

	  if(h<10)
	       printf("0%u",h);
	  else
	       printf("%u",h);
	  printf(":");
	  
	  if(m<10)
	       printf("0%u",m);
	  else
	       printf("%u",m);
      
	  printf(":");
      
	  if(s<10)
	       printf("0%u",s);
	  else
	       printf("%u",s);

	  /* valor del potenciometro */
	  printf("  AN0: %x   ",valor_adc);

	  /* y ahora el led, cero es apagado y 1 encendido */
	  if (led0 == 0) { 
		led0 = 1;
		output_c(input_c() | 0x01);	/* 00000001 */
	  }
	  else {
		led0 = 0;
		output_c(input_c() & 0xfe);	/* 11111110 */
	  }
     }
Ejemplo n.º 18
0
void pet_userport_joystick_adapter_device::update_port1()
{
	//printf( "update port1\n" );
	output_c(m_up1 && m_fire1);
	output_d(m_down1 && m_fire1);
}
Ejemplo n.º 19
0
Archivo: main.c Proyecto: kyluke/16F690
// Display the voltage
void display (int input)
{
	output_c(segment_numbers[input]);
}
Ejemplo n.º 20
0
void vt_out(int ch)
{
  static unsigned char last_ch;
  int f;
  unsigned char c;
  int go_on = 0;
  wchar_t wc;

  if (!ch)
    return;

  if (last_ch == '\n'
      && vt_line_timestamp != TIMESTAMP_LINE_OFF)
    {
      struct timeval tmstmp_now;
      static time_t tmstmp_last;
      char s[36];
      struct tm tmstmp_tm;

      gettimeofday(&tmstmp_now, NULL);
      if ((   vt_line_timestamp == TIMESTAMP_LINE_PER_SECOND
           && tmstmp_now.tv_sec != tmstmp_last)
          || vt_line_timestamp == TIMESTAMP_LINE_SIMPLE
          || vt_line_timestamp == TIMESTAMP_LINE_EXTENDED)
        {
          if (   localtime_r(&tmstmp_now.tv_sec, &tmstmp_tm)
              && strftime(s, sizeof(s), "[%F %T", &tmstmp_tm))
            {
              output_s(s);
              switch (vt_line_timestamp)
                {
                case TIMESTAMP_LINE_SIMPLE:
                  output_s("] ");
                  break;
                case TIMESTAMP_LINE_EXTENDED:
                  snprintf(s, sizeof(s), ".%03ld] ", tmstmp_now.tv_usec / 1000);
                  output_s(s);
                  break;
                case TIMESTAMP_LINE_PER_SECOND:
                  output_s("\r\n");
                  break;
                };
            }
          tmstmp_last = tmstmp_now.tv_sec;
        }
    }

  c = (unsigned char)ch;
  last_ch = c;

  if (vt_docap == 2) /* Literal. */
    fputc(c, capfp);

  /* Process <31 chars first, even in an escape sequence. */
  switch (c) {
    case 5: /* AnswerBack for vt100's */
      if (vt_type != VT100) {
        go_on = 1;
        break;
      }
      v_termout(P_ANSWERBACK, 0);
      break;
    case '\r': /* Carriage return */
      mc_wputc(vt_win, c);
      if (vt_addlf)
        output_c('\n');
      break;
    case '\t': /* Non - destructive TAB */
      /* Find next tab stop. */
      for (f = vt_win->curx + 1; f < 160; f++)
        if (vt_tabs[f / 32] & (1 << f % 32))
          break;
      if (f >= vt_win->xs)
        f = vt_win->xs - 1;
      mc_wlocate(vt_win, f, vt_win->cury);
      if (vt_docap == 1)
        fputc(c, capfp);
      break;
    case 013: /* Old Minix: CTRL-K = up */
      mc_wlocate(vt_win, vt_win->curx, vt_win->cury - 1);
      break;
    case '\f': /* Form feed: clear screen. */
      mc_winclr(vt_win);
      mc_wlocate(vt_win, 0, 0);
      break;
#if !TRANSLATE
    case 14:
    case 15:  /* Change character set. Not supported. */
      break;
#else
    case 14:
      vt_charset = 1;
      break;
    case 15:
      vt_charset = 0;
      break;
#endif
    case 24:
    case 26:  /* Cancel escape sequence. */
      esc_s = 0;
      break;
    case ESC: /* Begin escape sequence */
      esc_s = 1;
      break;
    case 128+ESC: /* Begin ESC [ sequence. */
      esc_s = 2;
      break;
    case '\n':
      if(vt_addcr)
        mc_wputc(vt_win, '\r');
      output_c(c);
	  break;
    case '\b':
    case 7: /* Bell */
      output_c(c);
      break;
    default:
      go_on = 1;
      break;
  }
  if (!go_on)
    return;

  /* Now see which state we are in. */
  switch (esc_s) {
    case 0: /* Normal character */
      if (vt_docap == 1)
        fputc(P_CONVCAP[0] == 'Y' ? vt_inmap[c] : c, capfp);
      if (!using_iconv()) {
        c = vt_inmap[c];    /* conversion 04.09.97 / jl */
#if TRANSLATE
        if (vt_type == VT100 && vt_trans[vt_charset] && vt_asis == 0)
          c = vt_trans[vt_charset][c];
#endif
      }
      /* FIXME: This is wrong, but making it right would require
       * removing all the 8-bit mapping features. Assuming the locale
       * is 8-bit, the character should not be changed by mapping to
       * wchar and back; if the locale is multibyte, there is no hope
       * of getting it right anyway. */
      if (!using_iconv()) {
        one_mbtowc (&wc, (char *)&c, 1); /* returns 1 */
        if (vt_insert)
          mc_winschar2(vt_win, wc, 1);
        else
          mc_wputc(vt_win, wc);
      } else {
        mc_wputc(vt_win, c);
      }
      break;
    case 1: /* ESC seen */
      state1(c);
      break;
    case 2: /* ESC [ ... seen */
      state2(c);
      break;
    case 3:
      state3(c);
      break;
    case 4:
      state4(c);
      break;
    case 5:
      state5(c);
      break;
    case 6:
      state6(c);
      break;
    case 7:
      state7(c);
      break;
  }

  /* Flush output to capture file so that all output is visible there
   * immediately. Causes a write syscall for every call though. */
  if (capfp)
    fflush(capfp);
}
Ejemplo n.º 21
0
int grib_ieee(unsigned char **sec, float *data, unsigned int ndata, FILE *out, FILE *head, FILE *tail, FILE *c) {

    int i;
    unsigned int n_defined, j;
//    int flag;
    unsigned long int size;
    unsigned char *p, *sec0, *sec1, *sec2, *sec3, *sec4, *sec5, *sec6, *sec7;
    unsigned char s[8];
    float *new_data;

    /* required passed sections */
    sec0 = sec[0];
    sec1 = sec[1];
    sec2 = sec[2];
    sec3 = sec[3];
    sec4 = sec[4];

    /* change scan mode */
//    flag = flag_table_3_4(sec);
//    set_order(sec, output_order);

    /* make a new section 6 */

    n_defined = ndata;
    sec6 = (unsigned char *) malloc(6);
    if (sec6 == NULL) fatal_error("grib_out ieee memory allocation sec6","");
    uint_char(6 * sizeof (unsigned char), sec6);
    sec6[4] = 6;			// section 5
    sec6[5] = 255;			// no bitmap

    
    /* data representation section */

    sec5 = (unsigned char *) malloc(12 * sizeof(unsigned char));
    if (sec5 == NULL) fatal_error("grib_out ieee memory allocation sec5","");
    uint_char(12 * sizeof (unsigned char), sec5);
    sec5[4] = 5;			// section 5
    uint_char(ndata, sec5+5);		// number of points
    uint2_char(4,sec5+9);		// data template 4
    sec5[11] = 1;			// precision: ieee 32-bit


    /* data section */

    new_data = (float *) malloc(n_defined * sizeof(float));
    if (new_data == NULL) fatal_error("grib_out ieee memory allocation data","");
    undo_output_order(data, new_data, n_defined);

    sec7 = (unsigned char *) malloc(5 + n_defined * 4);
    if (sec7 == NULL) fatal_error("grib_out ieee memory allocation sec7","");
    uint_char(5+n_defined*4, sec7);
    sec7[4] = 7;
    p = sec7 + 5;
    for (j = 0; j < n_defined; j++) {
	flt2ieee_nan(new_data[j], p);
	p += 4;
    }
    free(new_data);

    size = (unsigned long int) GB2_Sec0_size + GB2_Sec8_size +
         (sec1 ? uint4(sec1) : 0) +
         (sec2 ? uint4(sec2) : 0) +
         (sec3 ? uint4(sec3) : 0) +
         (sec4 ? uint4(sec4) : 0) +
         (sec5 ? uint4(sec5) : 0) +
         (sec6 ? uint4(sec6) : 0) +
         (sec7 ? uint4(sec7) : 0);

    fprintf(c,"unsigned char head[] = {");

    /* section 0 */
    fwrite((void *) sec0, sizeof(char), 8, out);
    fwrite((void *) sec0, sizeof(char), 8, head);
    output_c(c, sec0, 8);

    uint8_char(size, s);
    fwrite((void *) s, sizeof(char), 8, out);
    fwrite((void *) s, sizeof(char), 8, head);
    output_c(c, s, 8);

    fwrite((void *)sec1, sizeof(char), uint4(sec1), out);
    fwrite((void *)sec1, sizeof(char), uint4(sec1), head);
    output_c(c, sec1, uint4(sec1));

    if (sec2) fwrite((void *)sec2, sizeof(char), uint4(sec2), out);
    if (sec2) fwrite((void *)sec2, sizeof(char), uint4(sec2), head);
    if (sec2) output_c(c, sec2, uint4(sec2));

    if (sec3) fwrite((void *)sec3, sizeof(char), uint4(sec3), out);
    if (sec3) fwrite((void *)sec3, sizeof(char), uint4(sec3), head);
    if (sec3) output_c(c, sec3, uint4(sec3));

    if (sec4) fwrite((void *)sec4, sizeof(char), uint4(sec4), out);
    if (sec4) fwrite((void *)sec4, sizeof(char), uint4(sec4), head);
    if (sec4) output_c(c, sec4, uint4(sec4));

    if (sec5) fwrite((void *)sec5, sizeof(char), uint4(sec5), out);
    if (sec5) fwrite((void *)sec5, sizeof(char), uint4(sec5), head);
    if (sec5) output_c(c, sec5, uint4(sec5));

    if (sec6) fwrite((void *)sec6, sizeof(char), uint4(sec6), out);
    if (sec6) fwrite((void *)sec6, sizeof(char), uint4(sec6), head);
    if (sec6) output_c(c, sec6, uint4(sec6));

    if (sec7) fwrite((void *)sec7, sizeof(char), uint4(sec7), out);
    if (sec7) fwrite((void *)sec7, sizeof(char), 5, head);
    if (sec7) output_c(c, sec7, 5);
    fprintf(c,"};\n\n");

    s[0] = s[1] = s[2] = s[3] = 55; /* s = "7777" */
    fprintf(c,"unsigned char tail[4] = {55, 55, 55, 55};\n\n");
    fwrite((void *) s, sizeof(char), 4, out);
    fwrite((void *) s, sizeof(char), 4, tail);


    fprintf(c,"#define NDATA %u\n", ndata);

    i = 0;
    fprintf(c,"#define SEC0 0\n");
    fprintf(c,"#define DISCIPLINE %d\n",6);
    fprintf(c,"#define EDITION %d\n",7);

    i = 16;
    fprintf(c,"#define SEC1 %d\n",i);
    fprintf(c,"#define CENTER %d\n",i+5);
    fprintf(c,"#define SUBCENTER %d\n",i+7);
    fprintf(c,"#define MASTERTABLE %d\n",i+9);
    fprintf(c,"#define LOCALTABLE %d\n",i+9);
    fprintf(c,"#define YEAR %d\n",i+12);
    fprintf(c,"#define MONTH %d\n",i+14);
    fprintf(c,"#define DAY %d\n",i+15);
    fprintf(c,"#define HOUR %d\n",i+16);
    fprintf(c,"#define MINUTE %d\n",i+17);
    fprintf(c,"#define SECOND %d\n",i+18);

    i = i +  uint4(sec1);
    if (sec2) {
        fprintf(c,"#define SEC2 %d\n",i);
	i = i +  uint4(sec2);
    }

    if (sec3) {
        fprintf(c,"#define SEC3 %d\n",i);
	i = i +  uint4(sec3);
    }

    if (sec4) {
        fprintf(c,"#define SEC4 %d\n",i);
        fprintf(c,"#define PRODUCTDEFTEMPLATENUM %d\n",i+7);
        fprintf(c,"#define PRODUCTDEFTEMPLATE %d\n",i+9);
        fprintf(c,"#define PRODUCTCATEGORY %d\n",i+9);
        fprintf(c,"#define PRODUCTNUMBER %d\n",i+9);

	i = i +  uint4(sec4);
    }
    if (sec5) {
        fprintf(c,"#define SEC5 %d\n",i);
	i = i +  uint4(sec5);
    }
    if (sec6) {
        fprintf(c,"#define SEC6 %d\n",i);
	i = i +  uint4(sec6);
    }
    if (sec7) {
        fprintf(c,"#define SEC7 %d\n",i);
	i = i +  uint4(sec4);
    }

    free(sec5);
    free(sec6);
    free(sec7);

//    /* set scan mode to original order */
//    set_flag_table_3_4(sec, flag);
    
    return 0;
}
Ejemplo n.º 22
0
Archivo: main.c Proyecto: kyluke/16F690
// Display the voltage
void display (int input)
{
	int temp = 0;
	temp = segment[input/50];
    output_c(temp);
}