/*************************************************************************
Function: init_wyvern()
Purpose:  Runs all initialization functions
		  Enables interrupts
Input:    None
Returns:  None
**************************************************************************/
void init_wyvern(void){
	// Setup Wyvern Systems
	init_uc();		//UC
	init_uart();	// Serial  Communication
	//init_pwm();		// Motor PWM Control
	init_adc();			// ADC
	// Setup Wyvern RF
	RFsetup(local,max(sizeof(packet_com_t),sizeof(packet_inf_t)));
	set(PCICR,PCIE0); // enable pin-change interrupts
	PCMSK0 =0x00;
	set(PCMSK0, PCINT4); // demask PCINT4
	
	//clear(TCCR0B,CS02);
	//set(TCCR0B,CS01);
	//clear(TCCR0B,CS00);	// Timer0 Clock = System Clock/1024
	//set(TIMSK0,TOIE0);	// Enable Timer0 Overflow Interrupt

	// Enable Global Interrupts
	sei();

	// Force RF Interrupt (Pin Change Interrupt Channel 4) to run once
	clear(PORTB,4);
	if(RFRXdataReady()){
     	RFreceive((char*) &incoming);
	}

	incoming.battery = 150;
}
コード例 #2
0
ファイル: main.c プロジェクト: hebron/enc28j60_experiments
/*---------------------------------------------------------------------------*/
static
PT_THREAD(temperature_thread(struct pt *pt))
{
    PT_BEGIN(pt);

    init_adc(5);
    disable_digital_buffer(5);

    while(1)
    {
        cli();
        
        temperature_counter = 0;
        
        sei();

        PT_WAIT_UNTIL(pt,temperature_counter > 750);

        temp_result = 0;
        temp_sampl_cnt = 0;
     
        for(temp_sampl_cnt = 0; temp_sampl_cnt < 64; temp_sampl_cnt++)
        {    
            start_conversion();
        
            PT_WAIT_UNTIL(pt,!is_adc_busy());

            temp_result += read_adc();
        }        

        dbg(PSTR("> ADC result: %u\r\n"),temp_result >> 6);
    }

    PT_END(pt);
}
コード例 #3
0
ファイル: magctrl.c プロジェクト: whowechina/magcontrol
/* Main routine */
void main(void)
{
    /* Initialize everything */

    init_port();   
    init_devices(); 
    init_adc();

    /* fading(); */
    /* adctest(); */
    
    /* Phase 1: use full power level */
    const_power(POWER_FULL, 1500, LED_ON, NO_DETECT_LV);
    
    /* Phase 2: transit from full level to holding level*/
    transit_power(POWER_FULL, POWER_HOLD, 1);
    
    /* Phase 3: Hold on holding level */
    if (const_power(POWER_HOLD, DEADLOOP, LED_BLINK, DETECT_LV) < 0)
    {
        /* Recommended steps: 
           const_power(POWER_ZERO); 
           delay(sometime, e.g.50ms);
           const_power(max); */
        const_power(POWER_HOLD, DEADLOOP, LED_OFF, NO_DETECT_LV);
    }
}
コード例 #4
0
int main( void )
{
	init_timer();
	init_uart();
	init_adc();

	/* Turn on interrupts */
	sei();

	while(1)
	{
		int i;
		put_uint16_t( time() );

		for( i=0 ; i < 8 ; i++ )
		{
			putc( ' ' );
			put_uint16_t( volts_sum[i] );
		}

		puts( "\r\n" );

		msleep( 1024 );
	}

	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: LuckySunny/loochi-hardware
int main(void)
{
	/* Use the hardware (Timer1) to generate a fast (125kHz) pwm
	 * that will drive the buck converter on/off.
	 * 
	 * Initialize the PWM value *before*.
	 */
	redcpwm = 0x00;
	greencpwm = 0x00;
	bluecpwm= 0xFF; /* inverted */
	init_current_loop();
	
	/* Initializes the ADC */
	init_adc();
	
	/* Run a much slower (122Hz) PWM (based on Timer0 interrupts) */
	init_timer0();
	
	/* Initializes the serial port and prepare to receive data */
	init_serial();

	/* Enable interrupts and let the show begin! */
	sei();

	while(1) {
	}
}
コード例 #6
0
ファイル: solution_4.c プロジェクト: rolfz/Revox_B77_Remote
void main()
{
	u8 resultat;

	init_picstar();
// 1 solution
// port d en sortie pour affichier un resultat
	LATD=0;
	TRISD=0;
	
	init_adc(); // code de l'exercise 2

	// initialiser le pwm sur RC2
	init_pwm(); // code a développer
	
	while(1)
	{
	u8 tmp;

#ifdef ACTIVE_MOTEUR
	resultat=get_adc0();
	set_pwm(1,resultat); // pwm duty = potentiometre
#else
	if((resultat+=PLIMITE)>255)resultat=255;
	set_freq(1,resultat);
#endif

	LATD=resultat;   // affiche la vitesse du moteur en binaire sur les LED's                  
	delay_ms(10);
	} // end while
}// fin of program
コード例 #7
0
ファイル: alert.c プロジェクト: wuzhiguo1989/PRO_SHU
void init_io_alert()
{
	init_io_feed_lack();
	init_adc();
	// P24|23
	push_pull(2, 0x18);
}
コード例 #8
0
/*---------------------------------------------------------------------------*/
int main()
{
    uint8_t i;
    uint16_t temp;    
    uint16_t rval;
    uint16_t getDataCounter;

    init_hardware();    

    while(1)
    {                                
        /* power up the temperature sensor */
        pinMode(A,2,OUTPUT);
        digitalWrite(A,2,HIGH);

        /* prepare reading the 1st ADC channel */
        init_adc(0x01);
        _delay_us(750);

        /* take multiple readings and divide later */
        rval = 0;
        for (i = 0; i < 8; ++i)
        {
            temp = read_adc_sleepy();
            
            /* store each sample seperatly */
            data_array[(2*i)+2] = temp >> 8;
            data_array[(2*i)+3] = temp & 0xFF;        
            
            rval += temp;
        }
        rval = rval >> 3;

        /* Store the averages */
        data_array[0] = rval >> 8;
        data_array[1] = rval & 0xFF;

        /* reset ADC registers */
        ADCSRA = 0x00;
        ADMUX = 0x00;

        /* power down the temperature sensor */
        digitalWrite(A,2,LOW);
        pinMode(A,2,INPUT);                                          

        /* automatically goes to TX mode */
        nrf24_send(data_array);        

        /* be wise ... */
        sleep_during_transmisson();        

        /* parameter for this function determines how long does it wait for a message */
        check_bootloader_message(10);

        /* parameter for this function is WDT overflow count */
        sleep_for(25);
    }

    return 0;
}
コード例 #9
0
/*
 * main.c
 */
void main() {
	init_pins();
	init_button();
	init_adc();
	init_wdt();
	WDT_delay = CURRENT_DELAY;

 	BCSCTL1 = CALBC1_8MHZ;
	DCOCTL =  CALDCO_8MHZ;

	LCD_setup();
	_bis_SR_register(GIE);	// enable interrupts
	// initialize LCD and say hello a few times :-)
	LCD_init();

	LCD_send_string((char*)msg);

	while(1){
		LCD_put(0x80+40); // cursor to line 2, first position
		snprintf(hex, 20, HEX, (int)colourArray[1], (int)colourArray[2], (int)colourArray[0]);
		LCD_send_string(hex);
	}

	_bis_SR_register(LPM0_bits);

	//delay(0); // maximum delay



}
コード例 #10
0
ファイル: main.c プロジェクト: Someone101/aleph
// control / network / logic init
static void init_ctl(void) {
  // disable interrupts
  cpu_irq_disable();

  // intialize the event queue
  init_events();
  print_dbg("\r\n init_events");

  // intialize encoders
  print_dbg("\r\n init_encoders");
  init_encoders();

  // send ADC config
  print_dbg("\r\n init_adc");
  init_adc();

  // start timers
  print_dbg("\r\n init_sys_timers");
  init_sys_timers();
  //  init_app_timers();

  // enable interrupts
  cpu_irq_enable();

}
コード例 #11
0
ファイル: SGH.c プロジェクト: mass/illini-motorsports
void main(void){
  init_general();// Set general runtime configuration bits
  init_gpio_pins(); // Set all I/O pins to low outputs
  init_oscillator(0);// Initialize oscillator configuration bits
  init_timer2();// Initialize timer2 (millis)
  init_adc(NULL); // Initialize ADC module
  init_termination(NOT_TERMINATING);
  init_adcs();// Initialize all of the ADC's
  init_can(); // Initialize CAN

  canAnalogMillis = canDiagMillis = 0;
  ADCCON3bits.GSWTRG = 1; // Initial ADC Conversion?
  STI();// Enable interrupts


  while(1){
    update_analog_channels();
    strain_calc();

    if(millis - canAnalogMillis >= CAN_ANALOG_INTV){
      CANAnalogChannels();
      canAnalogMillis = millis;
    }

    if(millis - canDiagMillis >= CAN_DIAG_INTV){
      CANdiag();
      canDiagMillis = millis;
    }

    sample_temp(); // Sample internal and external temperature sensors

  }
}
コード例 #12
0
ファイル: wsmodule.c プロジェクト: ve3wwg/avr
int
main() {
	static const int dcount = 3000;
	int x;

	// Output pins
	DDRB = _BV(DDB1)|_BV(DDB2)|_BV(DDB3)|_BV(DDB4)|_BV(DDB5);
	DDRD = _BV(DDD4)|_BV(DDD3)|_BV(DDD2)|_BV(DDD1);

	// Pullups
	MCUCR &= ~PUD;		// Make sure pullups not disabled
	PORTB |= _BV(PORTB0);
	PORTD |= _BV(PORTD7)|_BV(PORTD6)|_BV(PORTD5);

	// CPU clock to 8 MHz (vs default 1 MHz)
	CLKPR = _BV(CLKPCE);	// Enable divisor change
	CLKPR = 0b00000000;	// Divisor = 1

	init_adc();
	init_timer();
	start_adc();

	for (;;) {
		PORTB |= _BV(PORTB1);
		for ( x=0; x<dcount; ++x )
			keys();

		PORTB &= ~_BV(PORTB1);
		for ( x=0; x<dcount; ++x )
			keys();
	}
}
コード例 #13
0
ファイル: main.c プロジェクト: Muriukidavid/z8_64k
//board bring-up
void init_system(){
	init_uart(0);//configure uart, check uart.h
	init_uart(1);//configure uart, check uart.h
	init_adc();//initialize ADC, check adc.h
	init_lcd();//init lcd
	init_relays();//init toggle relays
}
コード例 #14
0
int main(void)
{
	DDRC |= (1 << DDRC7);
	PORTC |= (1 << PORTC7);
	_delay_ms(2);
	PORTC &= ~(1 << PORTC7);
	
 	init_power();
 	init_timeout_timer();
	init_switch();
	init_ref_clock();
	init_spi(2);
	init_buttons();
	init_serial(2400);
	init_adc();
	init_i2c();
	//Turn on interrupts
	sei();
	play_sounds();
	//Debug: Never Gets here
    while(1)
    {
		_delay_ms(1000);
		get_POT_set_TWIPOT();
	}
}
コード例 #15
0
ファイル: main.c プロジェクト: TeamBarrel/Gregory
void init()
{
	start.pressed = FALSE;														/* Initialise all push buttons to not being pressed */
	start.released = TRUE;														/* but rather released                              */
	eepromSerial.pressed = FALSE;
	eepromSerial.released = TRUE;
	
	init_adc();
	lcd_init();
	
	TRISB = 0b00000011; 																	/* PORTB I/O designation */

	//timer0
	OPTION_REG = 0b00000100;
	//enable timer0 interrupt
	TMR0IE = 1;
	SSPSTAT = 0b01000000;																	/* Transmit on active -> idle state, sample input at middle of output */
	SSPCON = 0b00100010;																	/* Enable serial port, Fosc/64                                        */
	TRISC = 0b10010000;																		/* RX and SPI_SDI inputs, rest outputs                                */
	PORTC = 0b00000000;																		/* No module selected, no SM pulse, etc.                              */
	
	//Enable all interrupts
	PEIE = 1;	
	GIE  = 1;

	ser_init(); 																			//initialize UART
	initIRobot();
	initSongs();
}
コード例 #16
0
void main(){

	WDTCTL = WDTPW + WDTHOLD;       // Stop watchdog timer
	BCSCTL1 = CALBC1_8MHZ;			// 8Mhz calibration for clock
  	DCOCTL  = CALDCO_8MHZ;

  	adc_val = 0;   // most recent result is stored in photo.whole_int
  	updates=0; 		//update counter for debugger
  	last_updates=0; // initialize last_update to 0 like updates value
  	data_send = 0;
  	counter = COUNTER_VAL;
  	low = 29;
  	med = 46;
  	high = 53;
  	light_range = high - low;
  	light_to_pot_factor = (double)light_range / 128.0;
  	state = high_state;
  	beat_count = 0;
  	reached_high = 0;	// set to false
  	reached_low = 0;	// set to false

  	init_spi();
  	init_wdt();
  	init_adc();
  	init_timer();

  	start_conversion();		// do a conversion so that updates > last_updates
  	TACCTL0 |= OUTMOD_4; // turn on speaker
 	_bis_SR_register(GIE+LPM0_bits);

}
コード例 #17
0
ファイル: mouse_task.c プロジェクト: epsil/tunge
//! This function initializes the hardware/software resources required for mouse task.
//!
void mouse_task_init(void)
{
   // Init SOF
   g_u8_cpt_sof=0;
   Usb_enable_sof_interrupt();

   // Init interface board
   Joy_init();
   Hwb_button_init();
   Leds_init();
   Led1_on();
   Led0_off();
#if (TARGET_BOARD==STK525)
   init_adc();
   g_u16_pos_scroll=Get_adc_pot_val();
#endif

   // Send a ack report at startup
   g_b_send_report      = FALSE;
   g_b_send_ack_report  = TRUE;

   // Set first zerovalue for calibrating sensor reading
   U8 i = 0;
   for(i = ADC_START_CHANNEL; i <= ADC_END_CHANNEL; i++) {
      if(i != 3) {
         Zerovalue[i] = adc_reader(i);
      }
   }
}
コード例 #18
0
ファイル: sensor.c プロジェクト: MaxGekk/ZigZag
void event_handler( event_type_t event_type, unidata_t unidata ) 
   { 
    result_t err;
    uint64_t cur_time;
    static uint64_t last_detect_time = 0;
    
    DBG("call event_handler");
    switch(event_type)
    {
    case TIMER_EVENT:
       if((stage == STAGE_IDLE) )
       {
          stage = STAGE_PYRO; 
          init_adc();
       }
       err = stimer_set(TIMER_0, SHOT_PERIOD );
       if( ENOERR != err ) DBG("FAIL: start timer");
       break;
    case ADC12_EVENT:
       switch(stage)
       {
       case STAGE_PYRO:
          cur_time = sys_time();
          unidata <<= 4;
          if((unidata < MOTION_LO_TH) || (unidata > MOTION_HI_TH))
          {
             // Motion is detected
             if(cur_MotionState == MOTION_STATE_QUIET)
             {
                uint16_t attr = 0;
                attr_write(0xE2, &attr);
             }
             cur_MotionState = MOTION_STATE_ALARM;
             last_detect_time = cur_time;
          }
          else if(cur_MotionState == MOTION_STATE_ALARM)
          {
             if((cur_time - last_detect_time) > QUIET_MSG_TIMEOUT)
             {
                uint16_t attr = 1;
                attr_write(0xE2, &attr);
                cur_MotionState = MOTION_STATE_QUIET;
             }
          }
          middle_point += (unidata - middle_point) >> 8;
          //unidata = ((uint32_t)3000 * (uint32_t)unidata) / 4095; // Calculation of voltage 
          break;
       default:
          stage = STAGE_PYRO;

       }
       break;
    default:
       DBG("UNKNOW EVENT");
    }

    DBG("return event_handler");
    return;
   }
コード例 #19
0
ファイル: readADC.c プロジェクト: david-AGSGeo/Aldnoah.Zero
//functions
void init()
{
	//adc
	init_adc();

	//PortB all outputs
	TRISB = 0x00;
	PORTB = 0b00000000;
}
コード例 #20
0
ファイル: main.c プロジェクト: voandrew/seniorproject
int main(void) {

    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	init_adc();
	__bis_SR_register(LPM3_bits + GIE);

	while(1) {
	}
}
コード例 #21
0
//Initialisation de la fonction de mesure de la position du ballast
void init_ballast_position(void)
{
//Pour le U_BOAT utilisation de l'adc
#ifdef U_BOAT
	init_adc();
#else
//Pour le nouveau sous-marin, on utilise la fourche optique en comptant le nombre d'impulsion
	init_external_interrupt();
#endif
}
コード例 #22
0
ファイル: oversampling.c プロジェクト: AndreyMostovov/asf
/**
 * \brief Main application routine
 *  - Initializes the board and LCD display
 *  - Initialize ADC ,to read ADC offset and configure for oversampling
 *  - If number of sample Reached to  total number of oversample required,
 *    call function to start process on oversampled ADC readings
 */
int main( void )
{
	/*
	 * Initialize basic features for the AVR XMEGA family.
	 *  - PMIC is needed to enable all interrupt levels.
	 *  - Board init for setting up GPIO and board specific features.
	 *  - Sysclk init for configuring clock speed and turning off unused
	 *    peripherals.
	 *  - Sleepmgr init for setting up the basics for the sleep manager,
	 */

	board_init();
	sysclk_init();
	pmic_init();
	sleepmgr_init();

	/* Initialize ST7565R controller and LCD display */
	gfx_mono_init();

	/* Display headings on LCD for oversampled result */
	gfx_mono_draw_string("Oversampled", 0, 0, &sysfont);

	/* Display headings on LCD for normal result */
	gfx_mono_draw_string("Normal", 80, 0, &sysfont);

	/* Initialize ADC ,to read ADC offset and configure ADC for oversampling
	**/
	init_adc();

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Switch ON LCD back light */
	ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT);

	/* Set LCD contrast */
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	/* Continuous Execution Loop */
	while (1) {
		/*
		 * Check if number of sample reached to  total Number of
		 * oversample required by checking status of
		 * adc_oversampled_flag
		 */
		if (adc_oversampled_flag == true) {
			/* Reset the adc_oversampled_flag */
			adc_oversampled_flag = false;

			/* Process all received ADC samples and calculate analog
			 * input */
			adc_oversampled();
		}
	}
}
コード例 #23
0
ファイル: adc_to_pwm.c プロジェクト: djpnewton/davr
int main(void)
{
    init_pwm();
    init_adc();


    while(1)  // Loop Forever
    {
        sleep_mode();
    }
} 
コード例 #24
0
ファイル: main.c プロジェクト: pdNor/Matlab-Arduino
int main (void)
{
	sysclk_init();
	board_init();
	uart_config((uint32_t)UART_BAUDRATE);
	init_adc();
	pwm_setup();
	dac_setup();
	start_coms();					//Run state machine
	
	
}
コード例 #25
0
ファイル: use_adc.cpp プロジェクト: creator83/MK02FN128
int main()
{
	init_adc ();
	display.set_position(0,2);
	display.send_string("Adc value:");
	while (1)
	{
		display.set_position(1,0);
		val.pars(conv_adc(adc_ch));
		display.send_string(4, val.getArray());
		delay_ms(200);
	}
}
コード例 #26
0
ファイル: 2_servi.c プロジェクト: Edewin/OldCode
void main(void)
{
    unsigned char x,y;
    x=0;
    init();
    init_adc();
    init_eccp();
    for(;;)
    {


    }
}
コード例 #27
0
ファイル: arduino.c プロジェクト: ChrisMicro/OpenLasp
uint16_t analogRead(uint8_t channel )
{
	static uint8_t initFlags=0;

	uint16_t value=0;

	if((initFlags&(1<<channel))==0)
	{
		init_adc(channel);
		initFlags|=1<<channel;
	}

	return 	read_adc(channel);
}
コード例 #28
0
ファイル: com_1.c プロジェクト: wuzhiguo1989/PRO_SHU
void require_delay_init() {
	set_push_pull_output_on1(IO_LED3);
	set_push_pull_output_on5(IO_LED1);
	set_push_pull_output_on5(IO_LED2);

	//set_push_pull_output_on1(IO_AMP);
//	set_quasi_bidirectional_on1(IO_AMP);
	set_input_only_on1(IO_SENSOR);
	set_input_only_on1(IO_ADC);
	set_input_only_on3(IO_INT);
	set_input_only_on3(IO_CODE);

//	init_adc_amplifier();
	init_adc();
}
コード例 #29
0
ファイル: nxt_bluetooth_usart.c プロジェクト: Julia117/embox
static int nxt_bluetooth_init(void) {
	struct sys_timer *ntx_bt_timer;

	data_pack = NULL;

	irq_attach(CONFIG_NXT_BT_US_IRQ,
		nxt_bt_us_handler, 0, NULL, "nxt bt reader");
	// TODO error handling?

	init_usart();
	init_control_pins();
	init_adc();

	//TODO may be it must set when bt has been connected?
	return timer_set(&ntx_bt_timer, TIMER_PERIODIC, 200, nxt_bt_timer_handler, NULL);
}
コード例 #30
0
ファイル: lichtsensor.c プロジェクト: fromeijn/Robotica
int main(void)
{
	char str[256];
	init_adc();
	init_uart(&uartD0, &USARTD0, F_CPU, D0_BAUD, D0_CLK2X);
	PMIC.CTRL = PMIC_LOLVLEN_bm;
	sei();
	
	while(1)
	{
		uint16_t ch0_value = ADCA.CH0.RES;	
		sprintf(str, "%d\r\n", ch0_value);
		uart_puts(&uartD0, str);
		_delay_ms(50);
	}
}