当前位置: 首页>>代码示例>>C++>>正文


C++ HardwareTimer::attachInterrupt方法代码示例

本文整理汇总了C++中HardwareTimer::attachInterrupt方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwareTimer::attachInterrupt方法的具体用法?C++ HardwareTimer::attachInterrupt怎么用?C++ HardwareTimer::attachInterrupt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HardwareTimer的用法示例。


在下文中一共展示了HardwareTimer::attachInterrupt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setup

void setup() {
    // Setup our pins
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(VGA_R, OUTPUT);
    pinMode(VGA_G, OUTPUT);
    pinMode(VGA_B, OUTPUT);
    pinMode(VGA_V, OUTPUT);
    pinMode(VGA_H, OUTPUT);
    digitalWrite(VGA_R, LOW);
    digitalWrite(VGA_G, LOW);
    digitalWrite(VGA_B, LOW);
    digitalWrite(VGA_H, HIGH);
    digitalWrite(VGA_V, HIGH);

    // Fill the logo array with color patterns corresponding to its
    // truth value.  Note that we could get more tricky here, since
    // there are 3 bits of color.
    for (int y = 0; y < y_max; y++) {
        for (int x = 0; x < x_max; x++) {
            logo[y][x] = logo[y][x] ? ON_COLOR : OFF_COLOR;
        }
    }

    // This gets rid of the majority of the interrupt artifacts;
    // there's still a glitch for low values of y, but let's not worry
    // about that. (Probably due to the hackish way vsync is done).
    SerialUSB.end();
    systick_disable();

    // Configure
    timer.pause(); // while we configure
    timer.setPrescaleFactor(1);     // Full speed
    timer.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
    timer.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE);
    timer.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE);
    timer.setMode(TIMER_CH4, TIMER_OUTPUT_COMPARE);
    timer.setOverflow(2287);   // Total line time

    timer.setCompare(TIMER_CH1, 200);
    timer.attachInterrupt(TIMER_CH1, isr_porch);
    timer.setCompare(TIMER_CH2, 300);
    timer.attachInterrupt(TIMER_CH2, isr_start);
    timer.setCompare(TIMER_CH3, 2170);
    timer.attachInterrupt(TIMER_CH3, isr_stop);
    timer.setCompare(TIMER_CH4, 1);      // Could be zero, I guess
    timer.attachInterrupt(TIMER_CH4, isr_update);

    timer.setCount(0);         // Ready...
    timer.resume();            // Go!
}
开发者ID:DuinoPilot,项目名称:openstm32sw,代码行数:50,代码来源:vga-leaf.cpp

示例2: begin

void Dynamixel::begin(int baud) {
	//TxDString("[DXL]start begin\r\n");

	afio_remap(AFIO_REMAP_USART1);//USART1 -> DXL
	afio_cfg_debug_ports(AFIO_DEBUG_FULL_SWJ_NO_NJRST);
#ifdef BOARD_CM900  //Engineering version case

	 gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP);
	 gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable
	 gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable
#else
	 gpio_set_mode(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, GPIO_OUTPUT_PP);
	 gpio_write_bit(PORT_TXRX_DIRECTION, PIN_TXRX_DIRECTION, 0 );// RX Enable
#endif
	/* timer_set_mode(TIMER2, TIMER_CH1, TIMER_OUTPUT_COMPARE);

	 timer_pause(TIMER2);

	 uint16 ovf = timer_get_reload(TIMER2);
	 timer_set_count(TIMER2, min(0, ovf));

	 timer_set_reload(TIMER2, 10000);//set overflow

	 ovf = timer_get_reload(TIMER2);
	 timer_set_compare(TIMER2, TIMER_CH1, min(1000, ovf));

	 timer_attach_interrupt(TIMER2, TIMER_CH1, TIM2_IRQHandler);

	 timer_generate_update(TIMER2);
	 //timer_resume(TIMER2);*/

	/*
	 * Timer Configuation for Dynamixel bus
	 * 2013-04-03 ROBOTIS Changed it as the below codes
	 * Dynamixel bus used timer 2(channel 1) to check timeout for receiving data from the bus.
	 * So, don't use time 2(channel 1) in other parts.
	 * */
	// Pause the timer while we're configuring it
	timer.pause();

	// Set up period
	timer.setPeriod(1); // in microseconds

	// Set up an interrupt on channel 1
	timer.setMode(TIMER_CH1,TIMER_OUTPUT_COMPARE);
	timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
	timer.attachInterrupt(TIMER_CH1,TIM2_IRQHandler);

	// Refresh the timer's count, prescale, and overflow
	timer.refresh();

	// Start the timer counting
	//timer.resume();
	 dxl_initialize(0, baud);
}
开发者ID:planius,项目名称:ROBOTIS_CM9_Series,代码行数:56,代码来源:Dynamixel.cpp

示例3: init

void FLYMAPLEScheduler::init(void* machtnichts)
{
    delay_us(2000000); // Wait for startup so we have time to connect a new USB console
    // 1kHz interrupts from systick for normal timers
    systick_attach_callback(_timer_procs_timer_event);

    // Set up Maple hardware timer for 1khz failsafe timer
    // ref: http://leaflabs.com/docs/lang/api/hardwaretimer.html#lang-hardwaretimer
    _failsafe_timer.pause();
    _failsafe_timer.setPeriod(1000); // 1000us = 1kHz
    _failsafe_timer.setChannelMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);// Set up an interrupt on channel 1
    _failsafe_timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
    _failsafe_timer.attachInterrupt(TIMER_CH1, _failsafe_timer_event);
    _failsafe_timer.refresh();// Refresh the timer's count, prescale, and overflow
    _failsafe_timer.resume(); // Start the timer counting
    // We run this timer at a higher priority, so that a broken timer handler (ie one that hangs)
    // will not prevent the failsafe timer interrupt.
    // Caution: the timer number must agree with the HardwareTimer number
    nvic_irq_set_priority(NVIC_TIMER2, 0x14);
}
开发者ID:Checkie,项目名称:ardupilot,代码行数:20,代码来源:Scheduler.cpp

示例4: setup

void setup( void )
{
    hardwareSetup();
    // Setup the LED to steady on
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN, HIGH);
    
    // Setup the button as input
    pinMode(BOARD_BUTTON_PIN, INPUT);
    digitalWrite(BOARD_BUTTON_PIN, HIGH);
    
    // Setup the sensor pin as an analog input
    pinMode(sensor_pin,INPUT_ANALOG);
    
    setupKeywords();
    registerAction(_DIR_, &DIRaction);
    registerAction(_TYP_, &TYPaction);
    setupRadioModule();
    
    timer.pause();
    
    // Set up period
    timer.setPeriod(1000); // in microseconds
    
    // Set up an interrupt on channel 1
    timer.setMode(TIMER_CH1,TIMER_OUTPUT_COMPARE);
    timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
    timer.attachInterrupt(TIMER_CH1,ledTask);
    
    
    // Refresh the timer's count, prescale, and overflow
    timer.refresh();
    
    // Start the timer counting
    timer.resume();
    setupRadioModule();
    
}
开发者ID:suspect-devices,项目名称:cache-and-carry,代码行数:38,代码来源:datalogger.cpp


注:本文中的HardwareTimer::attachInterrupt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。