[ create a new paste ] login | about

Link: http://codepad.org/Lrmp6ryo    [ raw code | fork ]

C, pasted on May 6:
#include <avr/interrupt.h>
#include <avr/io.h>

void moving_forwards(void) {
  /* TODO: Configure motors to move forwards. */
  PORTA = _BV(PA0);
}

void moving_backwards(void) {
  /* TODO: Configure motors to move in reverse. */
  PORTA = _BV(PA1);
}

/* Front Bumper Interrupt */
ISR(INT0_vect) {
  moving_forwards();
}

/* Rear Bumper Interrupt */
ISR(INT1_vect) {
  moving_backwards();
}

void go(void) {
  for (;;) {
    /* Interrupts do all the work */
  }
}

void initialize_interrupt_registers(void) {
  /* Enable INT0 and INT1 */
  GICR |= _BV(INT0) | _BV(INT1);
  /* The rising edge of INT0 and INT1 generate interrupt requests */
  MCUCR |= _BV(ISC00) | _BV(ISC01) | _BV(ISC10) | _BV(ISC11) ;
  /* Set the Global Interrupt Enable bit */
  sei();
}

void initialize_io_registers(void) {
  /* TODO: configure I/O registers for motors. */
  DDRA = _BV(PA0) | _BV(PA1);
}

void initialize(void) {
  initialize_io_registers();
  initialize_interrupt_registers();
  /* Initial state */
  moving_forwards();
}

int main(void) {
  initialize();
  go();
  return 0;
}


Create a new paste based on this one


Comments: