Ejemplo n.º 1
0
// function to initialize UART
void uart_init(uint32_t Desired_Baudrate) {
    // If its not already set, calculate the baud rate dynamically,
    // based on current microcontroller speed and user specified
    // desired baudrate.
#ifndef UBBR
#define UBBR ((F_CPU)/(Desired_Baudrate*8UL)-1)
#endif

    // Set to double speed mode.
    SS_UCSRnA |= (1 << SS_U2Xn);

    // Set baud rate.
    SS_UBRRnH = (uint8_t)(UBBR >> 8);
    SS_UBRRnL = (uint8_t)UBBR;
    // Enable receiver, transmitter, and RxComplete interrupt
    SS_UCSRnB = (1 << SS_RXENn) | (1 << SS_TXENn) | (1 << SS_RXCIEn);
    // Set frame format: 8data, 1 stop bit
    SS_UCSRnC = (1 << SS_USBSn) | (1 << SS_UCSZn0) | (1 << SS_UCSZn1);
    // Enable the Global Interrupt Enbl flag to process interrupts

    DIGITAL_SET_OUT(SS_UART_TXE);  // Set nRX enable and TX enable as outputs
    DIGITAL_SET_OUT(SS_UART_nRXE);
    DIGITAL_SET_LOW(SS_UART_TXE);  // Set nRX enable and TX enable to 0
    DIGITAL_SET_LOW(SS_UART_nRXE);  // Enable RX and disable TX

    DIGITAL_PULLUP_ON(SS_UART_RX);

    sei();  // Enable interrupts
}
Ejemplo n.º 2
0
// Public functions called from main.c
void initDigital() {
  DIGITAL_PULLUP_ON(IN0);
  DIGITAL_SET_HIGH(IN1);
  DIGITAL_SET_LOW(IN2);
  DIGITAL_SET_LOW(IN3);

  // TODO(tobinsarah): allow configuration as input/output for each relevant pin
  DIGITAL_SET_IN(IN0);
  DIGITAL_SET_OUT(IN1);
  DIGITAL_SET_OUT(IN2);
  DIGITAL_SET_OUT(IN3);
}