29.08.2013 Views

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Bluetooth.c – LED­kontrollern<br />

// Grundkod av Johan Egneblad<br />

// 2010-03-02<br />

#define F_CPU 8000000 // Define the processor clock frequency<br />

#define BAUD 9138 // No crystal is used FCPU is approximate. The baud rate<br />

(bits per second) of the communication<br />

#define BAUD_REG F_CPU/16/BAUD-1 // The settings for the usart register<br />

#define BUFFER_SIZE 32 // Maximum message length<br />

#include "reciever.h"<br />

#include <br />

#include <br />

#include <br />

// Global variables for RX buffering<br />

volatile char rx_buffer[BUFFER_SIZE]; // A text buffer for incoming text<br />

volatile unsigned char rx_recieved_bytes; // A byte counter for the incomming<br />

text<br />

volatile unsigned char rx_eol; // An "end of line" indicator that is set to<br />

one ones a full line is read<br />

// Interrupt vector for USART Recieve Complete<br />

ISR(USART_RXC_vect) {<br />

unsigned char data;<br />

// Read the USART buffer<br />

data = UDR;<br />

// Check if the old msg has been read (rx_eol should be cleared)<br />

/*if (rx_eol == 0) {<br />

rx_buffer[rx_recieved_bytes] = data;<br />

rx_recieved_bytes++;<br />

// If there is a line break or null character<br />

if (data==0x0d || data==0x0a || data==0x00 || rx_recieved_bytes >=<br />

(BUFFER_SIZE-1)) {<br />

rx_eol = 1; // Tell the end of line is reached<br />

rx_buffer[rx_recieved_bytes] = 0; // Terminate the string<br />

correctly<br />

rx_recieved_bytes = 0; // Clear the received bytes counter<br />

}<br />

}*/<br />

dataRecieved((unsigned char)data);<br />

}<br />

// Initialization function for usart<br />

// inputs:<br />

// ubrr - (unsigned int) the future contents of the UBRR register<br />

void usart_init(unsigned int ubrr) {<br />

// Set the communication speed register UBRR<br />

UBRRH = (unsigned char)(ubrr>>8); // the most significant byte<br />

UBRRL = (unsigned char)ubrr; // the least significant byte<br />

// Clear the usart status register

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!