Ejemplo n.º 1
0
void timer2_wait_ms(unsigned short t)
{
    timeout2=t;
	cnt_dir=0;//向下计数
    timer2_start();
    while(timeout2);
}
Ejemplo n.º 2
0
/// Blocks for a specified number of milliseconds
void wait_ms(unsigned int time_val) {
	//Seting OC value for time requested
	OCR2=250; 				//Clock is 16 MHz. At a prescaler of 64, 250 timer ticks = 1ms.
	timer2_tick=0;
	timer2_start(0);

	//Waiting for time
	while(timer2_tick < time_val);

	timer2_stop();
}
Ejemplo n.º 3
0
uint16_t MPU6000::init()
{
    if (_initialised) return _product_id;
    _initialised = true;
    SPI.begin();
    SPI.setClockDivider (SPI_CLOCK_DIV16); // 1MHZ SPI rate  
    
    // we need to stop the barometer from holding the SPI bus
    pinMode (40, OUTPUT);
    digitalWrite (40, HIGH);
     
    hardware_init();
    timer2_init ();
    timer2_start ();
    return _product_id;
}
Ejemplo n.º 4
0
void timer2_init(void)
{
	/* 设置时钟源 */
	TCFG0 &= ~(0xff<<8);
	TCFG0 |= (1<<8);
	TCFG1  &= ~(0xf<<8);  
	                             /* Timer2 input clock Frequency = PCLK / ( {prescaler value + 1} ) / {divider value} 
	                    *      = 66500000 / (1+1) / 1
	                    *      = 33250000
	                    */

	/* 设置TCMPB2, TCNTB2 */
	TCNTB2 = 3325;   /* 倒数到0时,耗时0.1ms */							

	TCON |= (1<<15);    /* auto-reload */

	VIC0VECTADDR25 = timer2_irq;
	VIC0INTENABLE    |= (1<<25);

	timer2_start();
}
Ejemplo n.º 5
0
int main() {
	pButtonCallback redLed, greenLed;
	pTimerCallback timer1Callback, timer2Callback;

//initialization
	led_redInit();
	led_greenInit();
	led_yellowInit();
	button_init(true); //timer1_start is called there

//	timer1_start();
	timer2_start();

	count1 = 0;
	count2 = 0;

	redLed = &led_redToggle;
	greenLed = &led_greenToggle;

//	timer1Callback = &test_timer1;
	timer2Callback = &softwareTimer;

//pass function
	button_setRotaryButtonCallback(redLed);
	button_setJoystickButtonCallback(greenLed);

//if button_init(false) then we have to set a callback function.
//when button_init(true), the debouncing function is set as callback function
//which has been done in the button.c

//	timer1_setCallback(timer1Callback);
	timer2_setCallback(timer2Callback);

	sei();

	while (1) {
	}

}
Ejemplo n.º 6
0
int main(void) {
    uint16_t adc_data = 0;
    
    sei(); // Enable interrupts
    fosc_cal(); // Set calibrated 1MHz system clock
    portb_init(); // Set up port B
    usart_init(); // Set up the USART
    timer2_init();  // Set up, stop, and reset timer2
    timer0_init();
    usart_puts("Initialize ADC\r\n");
    adc_init();
    usart_puts("Initialize LCD\r\n");
    lcd_init(); // From LDC_driver
    usart_puts("Start main loop\r\n");
    lcd_puts("Hello",0); // From LCD_functions
    timer2_start(); // Start stimulus
    adc_mux(1); // Switch to the voltage reader at J407
    for(;;) {
        adc_read(&adc_data);
        adc_report(adc_data);
        OCR0A = (uint8_t)(adc_data);
    }// end main for loop
} // end main
Ejemplo n.º 7
0
void scheduler_init() {

	timer2_start();
	timer2_setCallback(scheduler_update);
}
Ejemplo n.º 8
0
inline void sendData(bool askforStatus,RF24 & radio){
	reportBuffer.reportid=askforStatus?1:0;
	bool ok = radio.write( &reportBuffer, sizeof(report_t) );

	if (ok){
		//status led off
		PORTD	&= ~(1<<LED1);
	}
	else{
		//status led on
		PORTD	|= (1<<LED1);
#ifdef DEBUG
		print_string("pa error\n");
#endif
		radio.startListening();
		radio.stopListening();
		return;
	}

	radio.startListening();

	if (askforStatus){

		// Wait here until we get a response, or timeout (250ms)
		bool timeout = false;
		timer2_start();
		while ( ! radio.available() && ! timeout ){
			if (timer2_gettick() > 200 )
				timeout = true;
		}

		// Describe the results
		if ( timeout )
		{
			//status led on
			PORTD	|= (1<<LED1);
#ifdef DEBUG
			print_string("Failed, response timed out.\n\r");
#endif
		}
		else
		{
			uint8_t response;
			radio.read( &response, sizeof(uint8_t) );
			//status led off
			PORTD	&= ~(1<<LED1);

			if (response){
				//battery led on
#ifdef DEBUG
				print_string("led on\n");
#endif
				PORTD	|= (1<<LED2);
			}else{
				//battery led off
				PORTD	&= ~(1<<LED2);
#ifdef DEBUG
				print_string("led off\n");
#endif
			}
		}

		timer2_stop();
	}

	radio.stopListening();
}
Ejemplo n.º 9
0
int main() {

    char i = 0x00;
    
    ADCTRIS |= ADCPIN;
    i = 0;
    SNSTRIS |= LVLONE|LVLTWO;
    LEDTRIS &= ~(POWLED|ALMLED);
    ALMTRIS &= ~(LGTOUT|ALMOUT);

    
    init_sensor(&levelSensors[0]);
    init_sensor(&levelSensors[1]);



    timer0_init();
    timer1_init();
    timer2_init();
    adc_init_CH0();
   
    LEDPORT |= POWLED;
    ALMPORT &= ~(ALMOUT|LGTOUT);

    timer0_start(); //Blinking Timer
    timer2_start(); //Start Timer Counting  TODO: Shutoff if Both Sensors dont use
    
    
   while(1)
   {
       levelSensors[0].sensorRead = (SNSPORT & LVLONE);
       levelSensors[1].sensorRead = (SNSPORT & LVLTWO);

       for(i = 0; i < 2;i++)
       {
           checkTankStatus(&levelSensors[i]);

       checkSensorState(&levelSensors[i]);

       checkAlarmState(&levelSensors[i], &theAlarm);
       }
       

//       checkTankStatus(&levelSensors[0]);
//       checkTankStatus(&levelSensors[1]);
//
//       checkSensorState(&levelSensors[0]);
//       checkSensorState(&levelSensors[1]);
//
//       checkAlarmState(&levelSensors[0], &theAlarm);
//       checkAlarmState(&levelSensors[1], &theAlarm);

       blinkLed(&(levelSensors[0].LEVEL_STATE), &(levelSensors[1].LEVEL_STATE), &(theAlarm.ALARM_STATE), &blinkState);

    }


    //NOT A GOOD SIGNAL!! ERROR!

    while(1)
    {
        LEDPORT^=POWLED;
        for(int i=0;i<10000;i++);

    }
    return (EXIT_SUCCESS);
}