/* Title: SerialCom.c Date Created: 6/9/2009 Last Modified: 6/9/2009 Target: Atmel ATmega168 Environment: AVR-GCC Note: the makefile is expecting a '168 with a 16 MHz crystal. Adapted from the Arduino sketch "Serial Call and Response," by Tom Igoe. // This program sends an ASCII A (byte of value 65) on startup // and repeats that until it gets some data in. // Then it waits for a byte in the serial port, and // sends three (faked) sensor values whenever it gets a byte in. Written by Windell Oskay, http://www.evilmadscientist.com/ Copyright 2009 Windell H. Oskay Distributed under the terms of the GNU General Public License, please see below. Additional license terms may be available; please contact us for more information. More information about this project is at http://www.evilmadscientist.com/article.php/peggy */ #include #define F_CPU 16000000 // 16 MHz oscillator. #define BaudRate 9600 #define MYUBRR (F_CPU / 16 / BaudRate ) - 1 void delayLong() { unsigned int delayvar; delayvar = 0; while (delayvar <= 65500U) { asm("nop"); delayvar++; } } unsigned char serialCheckRxComplete(void) { return( UCSR0A & (1<>8); UBRR0L = (unsigned char) MYUBRR; /* Enable receiver and transmitter */ UCSR0B = (1<