コード例 #1
0
ファイル: PSD_test.c プロジェクト: JinhoAndyPark/AVR
//------------------------------------------------------------------------------
//     					===== main =====
//------------------------------------------------------------------------------
int main(void)
{
//	unsigned int Dis=0 ;

	main_init();
	
	unsigned char y;

	while(1)
	{   
	/*
	//	Uart_Putch(1,10);
		
		Read_ADC(0);
	//	Uart_U16Bit_PutNum(ADC);
		
		Dis = (( (11.65/((ADC/204.8) - 0.147) ) - 0.42 ) * 10)-4;
		Uart_U16Bit_PutNum(Dis);
		_delay_ms(1000);

		*/
		Read_ADC(2);
		_delay_ms(10);
		
		y = (706.6*pow(ADC, -0.1541))-146;
//	Uart_Putch(0,1);
		Uart_Putch(0,y);
	}



	return 0;
}
コード例 #2
0
ファイル: EX_ADMM.C プロジェクト: joristork/robots
main() {

    int i,value,min,max;

    printf("Sampling:");

    setup_port_a( ALL_ANALOG );
    setup_adc( ADC_CLOCK_INTERNAL );
    set_adc_channel( 0 );

    do {
        min=255;
        max=0;
        for(i=0; i<=30; ++i) {
            delay_ms(100);
            value = Read_ADC();
            if(value<min)
                min=value;
            if(value>max)
                max=value;
        }
        printf("\n\rMin: %2X  Max: %2X\r\n",min,max);

    } while (TRUE);

}
コード例 #3
0
ファイル: main.c プロジェクト: JinhoAndyPark/AVR
int main(void)
{
	Init_ADC();
	Init_Uart(0,9600);
	

	while(1)
	{
	//	Uart_Putch(0,2);
		_delay_ms(500);

		if( Instruction[0] == 1)
		{	
			Instruction[0] = 0;
			while(1)
			{	
				//Uart_Putch(0,1);
				
				Read_ADC(0);
				Dis = (( (11.65/(( ADC/204.8) - 0.147 )) - 0.42 ) * 10)-4;
				if(Dis < 65)
				{
					Uart_Putch(0,SIG_To1[0]); ////SIG TO 1
					break;
				}
			}
		}
		
	}
	return 0;
}
コード例 #4
0
ファイル: TMP35.c プロジェクト: Leboefi/Pinguino-JACSS
void temp_sensor(int8 j) 
{ 
 set_adc_channel(j); 
 delay_ms(5); 
 Vout = Read_ADC();  
 Temp = (((float)Vout*5)/1023) * 100.0; // div by 1024/5 (=204.8) for 10 bit 
 //Temp = (Temp - 32) * (0.55555); 
 printf(usbWrite,"V:%Lu T:%.2f     ",Vout, Temp);
 return;
}
コード例 #5
0
ファイル: adc.c プロジェクト: JinhoAndyPark/AVR
U16 ADC_Average( U08 Channel, U08 number )		//Average ADC
{
    U16 value = 0;
    U16 temp[number];

    for(U08 cnt=0; cnt<number; cnt++)
    {
        temp[cnt] = Read_ADC(Channel);
        value += temp[cnt];
    }
    value /= number;

    return value;
}
コード例 #6
0
ファイル: main.c プロジェクト: tgatomic/DirtyDawg
//################################################################# Main routine
int main(void)
{	 
  
	// Initiate the TWI for ATTiny
	cli();  // Disable interrupts
	usiTwiSlaveInit(SLAVE_ADDR_ATTINY);	// TWI slave init
	sei();  // Re-enable interrupts
	
	ADC_init();
	

	// The data you want to be sent to 328p is saved in txbuffer[]
	// Ex:

	
	while(1){
		txbuffer[0] = Read_ADC(3);
		_delay_ms(1000);

	}
} 
コード例 #7
0
void main(void) {

   int8 recibe[3];                  //declaramos variables
   int8 envia[1];

   setup_adc_ports( ALL_ANALOG );		//Configuramos el puerto a como analogo
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel( 0 );  

   LED_OFF(LEDV);                   //encendemos led rojo
   LED_ON(LEDR);

   usb_init();                      //inicializamos el USB

   usb_task();                      //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host

  LED_OFF(LEDR);
  LED_ON(LEDV);                    //encendemos led verde
    
  /* while(TRUE){
       envia[0] = (int8)Read_ADC();
       if (envia[0] > 0x7F){
              LED_ON(LEDR);
              LED_ON(LEDV);                    //encendemos led verde
         }else{
              LED_OFF(LEDR);
              LED_OFF(LEDV);  //otra acción
        }
   } 
*/
   while (TRUE)
   {
      if(usb_enumerated())          //si el PicUSB está configurado
      {
         if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
         {
            usb_get_packet(1, recibe, 3); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe

            if (modo == 0) // Modo_Suma
            {
              envia[0] = (int8)Read_ADC();
              usb_put_packet(1, envia, 1, USB_DTS_TOGGLE); //enviamos el paquete de tamaño 1byte del EP1 al PC
				if (envia[0] > 0x7F){
              LED_ON(LEDR);
              LED_ON(LEDV);                    //encendemos led verde
         	}else{
              LED_OFF(LEDR);
              LED_OFF(LEDV);  //otra acción
        }
            }

            if (modo == 1) // Modo_Led
            {
               if (param1 == 0) {LED_OFF(LEDV); LED_OFF(LEDR);} //apagamos los leds
               if (param1 == 1) {LED_ON(LEDV); LED_OFF(LEDR);} //encendemos led verde
               if (param1 == 2) {LED_OFF(LEDV); LED_ON(LEDR);} //encendemos led rojo
            }
         }
      }
   }
}