Beispiel #1
0
int8 in_read_charlieplex_inputs()
{
	int8 switches;

	output_drive(PI_CHARLIEPLEX_SWITCH_1_PIN);
	switches = input_state(PI_CHARLIEPLEX_SWITCH_3_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_1_PIN);

	output_drive(PI_CHARLIEPLEX_SWITCH_2_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_3_PIN);	
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_2_PIN);

	//Note: In this block charliplex1 must be read before charliplex2
	// just to charliplex2 has enough time to recover because charliplex2 was 
	// low in previous block. This avoid to put a delay here.
	output_drive(PI_CHARLIEPLEX_SWITCH_3_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN);
	switches <<= 1;
	switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_high(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_3_PIN);

	return ~switches;
}
Beispiel #2
0
void onewire_reset()  // OK if just using a single permanently connected device 
{ 
 output_low(ONE_WIRE_PIN); 
 delay_us( 500 ); // pull 1-wire low for reset pulse 
 output_float(ONE_WIRE_PIN); // float 1-wire high 
 delay_us( 500 ); // wait-out remaining initialisation window. 
 output_float(ONE_WIRE_PIN); 
} 
Beispiel #3
0
sl_def(t_main, void)
{
  double x = slr_get(x)[0];
  double t1 = tgamma(x);
  float t2 = tgammaf(x);
  output_float(x, 1, 4);
  output_char(' ', 1);
  output_float(t1, 1, 4);
  output_char(' ', 1);
  output_float(t2, 1, 4);
  output_char('\n', 1);
}
Beispiel #4
0
sl_enddef

// 2009-04-02: FIXME: we acknowledge that muTC-ptl
// does not support this construct fully yet; but
// we want slc's testsuite to properly succeed. So
// we mark the test to ignore the output on muTC-ptl:
// XIGNORE: ptl*:D

sl_def(t_main, void)
{
  int busy;
  sl_create(,,,,,,,
	    foo, sl_shfarg(double, a));
  // FIXME: for ptl here we should find a way to
  // force a context switch, otherwise the problem
  // is not demonstrated. In the previous version
  // of this test, a call was done to the C library's
  // putc() function, but we can't do this in SL
  // because putc is a thread function and we cannot
  // nest creates.
  for (busy = 0; busy < 10000; ++busy) nop();
  sl_seta(a, 42.0);
  sl_sync();

  output_float(sl_geta(a), 1, 2);
  output_char('\n', 1);
}
Beispiel #5
0
//-----------------------------------------------------------------------
//	read_data()
//-----------------------------------------------------------------------
//
long read_data()
{
	int i;
	int data;
	
// Tri-state the SDIO pin
	output_float(SDIO);

// Minium delay between address and reading data
	delay_us(100);
	
// Read data
	for(i=0; i < DATA_BITS; i++){

	// Leading edge of serial clock (data is clocked out ADNS-2051)
		output_low(SCLK);
		
	// Some extra delay before read
		delay_us(25);
		
	// put here code to shift data in on 
		shift_left(&data, 1, input(SDIO) );
		
	// Trailling edge of serial clock 
		output_high(SCLK);
	}
		return data;
}
Beispiel #6
0
void WriteFSKbyte(int8 DATA)
{
	int8 	RGIT = 0;
	int16 	temp = 0xB800;
	
	output_float(_SDO);
	output_low(_SCK);

	temp|= DATA;

Loop:	SCK = false;

	RF_EN	= false;
	output_low(_SDA);
	SCK		= true;
	RGIT 	= (SDO==true); //Polling SDO
	SCK		= false;
	output_high(_SDA);
	RF_EN	= true;

	if (RGIT==0){
		goto Loop;
	} else {
		RGIT=false;
		WriteCMD(temp);
	}
}
Beispiel #7
0
// SHT1x Address & Command Mode with address=000 
int SHTWrite(int Data) 
{ 
   int i; 
   
   for (i=0x80;i>0;i/=2)        //shift bit for masking data
   { 
      if(i&Data)
      output_high(SHT1xDATA); 
      else  
      output_low(SHT1xDATA); 
      
      delay_us(2);               //Snend Clock each bit 
      output_high(SHT1xSCK); 
      delay_us(2); 
      output_low(SHT1xSCK); 
   } 
   
   output_float(SHT1xDATA);     //Change DATA Line to Input 
   delay_us(2); 
   
   output_high(SHT1xSCK);       //Clock for Acknowledge 
   delay_us(2); 
   
   i= input(SHT1xDATA);         //Get Acknowledge
   
   output_low(SHT1xSCK); 
   delay_ms(250);
   return (i);
} 
Beispiel #8
0
BYTE lcd_read_byte(void)
{
   BYTE low,high;

 #if defined(__PCB__)
   set_tris_lcd(LCD_INPUT_MAP);
 #else
  #if (defined(LCD_DATA4) && defined(LCD_DATA5) && defined(LCD_DATA6) && defined(LCD_DATA7))
   output_float(LCD_DATA4);
   output_float(LCD_DATA5);
   output_float(LCD_DATA6);
   output_float(LCD_DATA7);
  #else
   lcdtris.data = 0xF;
  #endif
 #endif
        
   lcd_output_rw(1);
   delay_cycles(1);
   lcd_output_enable(1);
   delay_cycles(1);
   high = lcd_read_nibble();
      
   lcd_output_enable(0);
   delay_cycles(1);
   lcd_output_enable(1);
   delay_us(1);
   low = lcd_read_nibble();
      
   lcd_output_enable(0);

 #if defined(__PCB__)
   set_tris_lcd(LCD_INPUT_MAP);
 #else
  #if (defined(LCD_DATA4) && defined(LCD_DATA5) && defined(LCD_DATA6) && defined(LCD_DATA7))
   output_drive(LCD_DATA4);
   output_drive(LCD_DATA5);
   output_drive(LCD_DATA6);
   output_drive(LCD_DATA7);
  #else
   lcdtris.data = 0x0;
  #endif
 #endif

   return( (high<<4) | low);
}
Beispiel #9
0
void onewire_write(int data) 
{ 
 int count; 

 for (count=0; count<8; ++count) 
 { 
  output_low(ONE_WIRE_PIN); 
  delay_us( 2 ); // pull 1-wire low to initiate write time-slot. 
  output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire 
  delay_us( 60 ); // wait until end of write slot. 
  output_float(ONE_WIRE_PIN); // set 1-wire high again, 
  delay_us( 2 ); // for more than 1us minimum. 
 } 
} 
Beispiel #10
0
void in_init()
{
	output_low(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_ENCODER_A_PIN);
	output_float(PI_ENCODER_B_PIN);

	RBPU = 0; //Enable pull-up resistors on PORT B
	WPUB = PI_BUTTON_PULLUP_RESISTORS; //Enable pull-ups for buttons
	
	//At 4Mhz instruction frequency (ClockF=16Mhz/4): it increments every 4us
	//	With post scaler: generate an interrupt every 16 periods:
	//		Resolution: 64us
	//		Min period: 64us (15.625 KHz) 
	//		Max period: 255*64us = 16.320 ms (61Hz)
	//	For 30 counts period, it interrupts every ~ 2ms
	setup_timer_2( T2_DIV_BY_16, (IN_ENCODER_SCAN_PERIOD_US/64)-1, 16 );
	enable_interrupts(INT_TIMER2);
}
Beispiel #11
0
int onewire_read() 
{ 
 int count, data; 

 for (count=0; count<8; ++count) 
 { 
  output_low(ONE_WIRE_PIN); 
  delay_us( 2 ); // pull 1-wire low to initiate read time-slot. 
  output_float(ONE_WIRE_PIN); // now let 1-wire float high, 
  delay_us( 8 ); // let device state stabilise, 
  shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result. 
  delay_us( 120 ); // wait until end of read slot. 
 } 

 return( data ); 
} 
Beispiel #12
0
//Read data from SHT1x
long SHTRead(void) 
{ 
   int i; 
   long lTmp,lVal1,lVal2,lValue; 
   
   lVal1=0;
   lVal2=0; 
   
   //get MSB from SHT1x 
   for (i=0; i<8; i++) 
   { 
      lVal1<<=1; 
      output_high(SHT1xSCK);          //Send Clock Hight
      lTmp = input(SHT1xDATA);        //Read Data Bit 
      output_low(SHT1xSCK);           //Send Clock Low
      
      if(lTmp) 
         lVal1|=1;                      //store in lVal1
      } 
   
   //Acknowledge routine for Next byte
   output_low(SHT1xDATA); 
   output_high(SHT1xSCK); 
   
   output_float(SHT1xDATA);         //Change to Input
   output_low(SHT1xSCK); 
   
   //get LSB from SHT1x 
   for (i=0; i<8; i++) 
   { 
      lVal2<<=1; 
      output_high(SHT1xSCK);          //Send Clock Hight 
      lTmp = input(SHT1xDATA);        //Read Data Bit  
      //delay_us(2); 
      output_low(SHT1xSCK);           //Send Clock Low
      //delay_us(2); 
      
      if(lTmp) 
         lVal2|=1;                     //store in lVal2
   }    
   
   lValue = make16(lVal1,lVal2);    //Makes a 16 bit number out of two 8 bit numbers.
   return(lValue); 
} 
inline void print(
    orthotope<T> const& A
  , std::string const& name
    )
{
    BOOST_ASSERT(2 == A.order());

    for (std::size_t i = 0; i < A.extent(0); ++i)
    {
        if (i == 0)
            std::cout << (boost::format("%- 8s = [ ") % name);
        else
            std::cout << (boost::format("%|11T |[ "));

        for (std::size_t j = 0; j < A.extent(1); ++j)
            output_float(A(i, j));

        std::cout << "]\n";
    }

    std::cout << "\n";
}
Beispiel #14
0
void init_ext_eeprom()
{
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);

}
Beispiel #15
0
static void
write_float (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
{
  GFC_REAL_LARGEST n;
  int nb =0, res, save_scale_factor;
  char * p, fin;
  fnode *f2 = NULL;

  n = extract_real (source, len);

  if (f->format != FMT_B && f->format != FMT_O && f->format != FMT_Z)
    {
      res = isfinite (n); 
      if (res == 0)
	{
	  nb =  f->u.real.w;
	  
	  /* If the field width is zero, the processor must select a width 
	     not zero.  4 is chosen to allow output of '-Inf' or '+Inf' */
	     
	  if (nb == 0) nb = 4;
	  p = write_block (dtp, nb);
          if (p == NULL)
            return;
	  if (nb < 3)
	    {
	      memset (p, '*',nb);
	      return;
	    }

	  memset(p, ' ', nb);
	  res = !isnan (n);
	  if (res != 0)
	    {
	      if (signbit(n))
	        {
	        
	          /* If the sign is negative and the width is 3, there is
	             insufficient room to output '-Inf', so output asterisks */
	             
	          if (nb == 3)
	            {
	              memset (p, '*',nb);
	              return;
	            }
	            
	          /* The negative sign is mandatory */
	            
	          fin = '-';
		}    
	      else
	      
	          /* The positive sign is optional, but we output it for
	             consistency */
	             
		  fin = '+';

	      if (nb > 8)
	      
	        /* We have room, so output 'Infinity' */
	        
		memcpy(p + nb - 8, "Infinity", 8);
	      else
	      
	        /* For the case of width equals 8, there is not enough room
	           for the sign and 'Infinity' so we go with 'Inf' */
	            
		memcpy(p + nb - 3, "Inf", 3);
	      if (nb < 9 && nb > 3)
		p[nb - 4] = fin;  /* Put the sign in front of Inf */
	      else if (nb > 8)
		p[nb - 9] = fin;  /* Put the sign in front of Infinity */
	    }
	  else
	    memcpy(p + nb - 3, "NaN", 3);
	  return;
	}
    }

  if (f->format != FMT_G)
    output_float (dtp, f, n);
  else
    {
      save_scale_factor = dtp->u.p.scale_factor;
      f2 = calculate_G_format (dtp, f, n, &nb);
      output_float (dtp, f2, n);
      dtp->u.p.scale_factor = save_scale_factor;
      if (f2 != NULL)
        free_mem(f2);

      if (nb > 0)
        {
	  p = write_block (dtp, nb);
          if (p == NULL)
            return;
          memset (p, ' ', nb);
        }
    }
}
Beispiel #16
0
void seta_saida_1w (void)
// coloca a saída em la impedância
{
	output_float (pino_1w);
}
Beispiel #17
0
void init_ext_eeprom() {
   output_float(eeprom_scl);
   output_float(eeprom_sda);
}
Beispiel #18
0
sl_def(t_main, void)
{
  double x = foo(3, .14);
  output_float(x, 1, 3); 
  output_char('\n', 1);
}
Beispiel #19
0
sl_def(t_main, void)
{
  float x = foo();
  output_float(x, 1, 3); 
  output_char('\n', 1);
}
Beispiel #20
0
void init_e() {
   output_float(SDA_EEPROM);   
   output_float(SCL_EEPROM);
   
}
Beispiel #21
0
sl_enddef

// XIGNORE: mts*:D
// SLT_RUN: -f TEST.d1
// SLT_RUN: -f TEST.d2

int main(int argc, char **argv)
{
  int j;
  double x = .42;
  int n = 42;

  assert(fibre_tag(0) == 2 && fibre_rank(0) == 0);
  assert(fibre_tag(1) == 0 && fibre_rank(1) == 0);
  x = *(double*)fibre_data(0);
  n = *(long*)fibre_data(1);

  for(j = 0; j < MAX_TESTS; ++j) {
    values[j].desc = 0;
    values[j].f = values[j].d = x;
    values[j].i = values[j].l = values[j].ll = n;
  }

  sl_create(,,,,,,, do_test);
  sl_sync();

  double_t xd = x;
  float_t xf = x;
  output_string("dot forty two, d: ", 1);
  output_float(xd, 1, 4);
  output_char('\n', 1);
  output_string("dot forty two, f: ", 1);
  output_float(xf, 1, 4);
  output_char('\n', 1);
  output_string("HUGE_VAL: ", 1);
  output_float(HUGE_VAL, 1, 4);
  output_char('\n', 1);
  output_string("HUGE_VALF: ", 1);
  output_float(HUGE_VALF, 1, 4);
  output_char('\n', 1);
  output_string("INFINITY: ", 1);
  output_float(INFINITY, 1, 4);
  output_char('\n', 1);
  output_string("NAN: ", 1);
  output_float(NAN, 1, 4);
  output_char('\n', 1);
  output_string("FP_ILOGB0 // ilogb(0): ", 1);
  output_int(FP_ILOGB0 == ilogb(0), 1);
  output_char('\n', 1);
  output_string("FP_ILOGBNAN // ilogb(NAN): ", 1);
  output_int(FP_ILOGBNAN == ilogb(NAN), 1);
  output_char('\n', 1);
  output_string("M_2: ", 1);
  output_float(M_E, 1, 4);
  output_char('\n', 1);
  output_string("M_LOG2E: ", 1);
  output_float(M_LOG2E, 1, 4);
  output_char('\n', 1);
  output_string("M_LOG10E: ", 1);
  output_float(M_LOG10E, 1, 4);
  output_char('\n', 1);
  output_string("M_LN2: ", 1);
  output_float(M_LN2, 1, 4);
  output_char('\n', 1);
  output_string("M_LN10: ", 1);
  output_float(M_LN10, 1, 4);
  output_char('\n', 1);
  output_string("M_PI: ", 1);
  output_float(M_PI, 1, 4);
  output_char('\n', 1);
  output_string("M_PI_2: ", 1);
  output_float(M_PI_2, 1, 4);
  output_char('\n', 1);
  output_string("M_PI_4: ", 1);
  output_float(M_PI_4, 1, 4);
  output_char('\n', 1);
  output_string("M_1_PI: ", 1);
  output_float(M_1_PI, 1, 4);
  output_char('\n', 1);
  output_string("M_2_PI: ", 1);
  output_float(M_2_PI, 1, 4);
  output_char('\n', 1);
  output_string("M_2_SQRTPI: ", 1);
  output_float(M_2_SQRTPI, 1, 4);
  output_char('\n', 1);
  output_string("M_SQRT2: ", 1);
  output_float(M_SQRT2, 1, 4);
  output_char('\n', 1);
  output_string("M_SQRT1_2: ", 1);
  output_float(M_SQRT1_2, 1, 4);
  output_char('\n', 1);

  for (j = 0; j < p; ++j)
    {
      const char *d = 	   values[j].desc ? values[j].desc : ".";
      output_string(d, 1); output_char(' ', 1);
      output_float(values[j].d, 1, 4); output_char(' ', 1);
      output_float(values[j].f, 1, 4); output_char(' ', 1);
      output_int(values[j].i, 1); output_char(' ', 1);
      output_int(values[j].l, 1); output_char(' ', 1);
      output_int(values[j].ll, 1); output_char('\n', 1);
    }

  return 0;
}
void encender_led(int led_numero)
{
 if (led_numero==0)
  {
   output_low(PIN_C0);
   output_low(PIN_C1);
   output_low(PIN_D3);
   output_low(PIN_C2);
  }
  if (led_numero==1)
  {
   output_low(PIN_C0);
   output_high(PIN_C1);
   output_float(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==2)
  {
   output_float(PIN_C0);
   output_low(PIN_C1);
   output_high(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==3)
  {
   output_float(PIN_C0);
   output_float(PIN_C1);
   output_low(PIN_D3);
   output_high(PIN_C2);
  }
 /* if (led_numero==4)
  {
   output_high(PIN_C0);
   output_low(PIN_C1);
   output_float(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==5)
  {
   output_float(PIN_C0);
   output_high(PIN_C1);
   output_low(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==6)
  {
   output_float(PIN_C0);
   output_float(PIN_C1);
   output_high(PIN_D3);
   output_low(PIN_C2);
  }
  if (led_numero==7)
  {
   output_high(PIN_C0);
   output_float(PIN_C1);
   output_low(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==8)
  {
   output_low(PIN_C0);
   output_float(PIN_C1);
   output_high(PIN_D3);
   output_float(PIN_C2);
  }
  if (led_numero==9)
  {
   output_float(PIN_C0);
   output_low(PIN_C1);
   output_float(PIN_D3);
   output_high(PIN_C2);
  }
  if (led_numero==10)
  {
   output_float(PIN_C0);
   output_high(PIN_C1);
   output_float(PIN_D3);
   output_low(PIN_C2);
  }
  if (led_numero==11)
  {
   output_low(PIN_C0);
   output_float(PIN_C1);
   output_float(PIN_D3);
   output_high(PIN_C2);
  }
  if (led_numero==12)
  {
   output_high(PIN_C0);
   output_float(PIN_C1);
   output_float(PIN_D3);
   output_low(PIN_C2);
  } */
}
Beispiel #23
0
//programa principal      
void main()
{
   set_tris_A(0x00);/* 0000 0000
      RA0   LED1   PIN   02
      RA1   LED2   PIN   03
      RA2   LED3   PIN   04
      RA3   LED4   PIN   05
      RA4   LED5   PIN   06
      RA5   LED6   PIN   07
   */
   set_tris_B(0x00);/* (0000 0000)
      RB0   LED7    PIN   40
      RB1   LED8    PIN   39
      RB2   LED9    PIN   38
      RB3   LED10   PIN   37
      RB4   LED11   PIN   36
      RB5   LED12   PIN   35
      RB6   LED13   PIN   34
      RB7   LED14   PIN   33
   */

   set_tris_C(0X00);/*
      
      RC0   -----   PIN   15
      RC1   -----   PIN   16   
      RC2   -----   PIN   17
      RC6   LED15   PIN   25
      RC7   LED16   PIN   26
   */

   // Configuración de Leds 17 hasta 20 y Pulsadores 1 y 2   
   set_tris_D(0X00);/*
      RD0   SW01    PIN   19 --->Pulsador 1
      RD1   SW02    PIN   20 --->Pulsador 2
      RD2   -----   PIN   21
      RD3   -----   PIN   22
      RD4   LED17   PIN   27
      RD5   LED18   PIN   28
      RD6   LED19   PIN   29
      RD7   LED20   PIN   30
   */

   
   set_tris_E(0x00);/* bits(**** 0000)
      RE0   -----   PIN   08 
      RE1   -----   PIN   09
      RE2   -----   PIN   10
      RE3   -----   PIN   01
   */

   //Habilitando y deshabilitando modulos...
   setup_timer_1(T1_disabled);
   setup_timer_2(T2_disabled,0,1);
   setup_timer_3(T3_disabled);
   setup_ccp1(CCP_OFF);
   setup_ADC(ADC_OFF);
   setup_VREF(FALSE);//no voltaje de referencia
   setup_COMPARATOR(NO_ANALOGS);//
   
   //limpie los puertos
   OUTPUT_A(0x00);
   OUTPUT_B(0x00);
   OUTPUT_C(0X00);
   OUTPUT_D(0X00);

   //limpiar registros, probar limpiar todos los registros en assembler con =0
   //#ZERO_RAM 
   limpiarRegistros();

   /*condicional para lanzar secuencia cuando
     el pulsador esté presionado. */
   output_float(SW01);
   output_float(SW02);
   while(TRUE)
   {
      if (input_state(SW01) == 1 && input_state(SW02) == 1)
      {
         secuencia1();
      }else if (input_state(SW01) == 0 && input_state(SW02) == 1)
      {
         secuencia2();
      }else if (input_state(SW01) == 1 && input_state(SW02) == 0)
      {
         secuencia4();
      }else
      {
      }
   }
   //vuelva a inicio y vuelva y arranque
   reset_cpu();
}