/* * Soft_UART_Timer1.h * * Software UART for ATmega328p using Timer1 * * Now only tranmission, no receiving */ #ifndef SOFTUARTTIMER1_H_ #define SOFTUARTTIMER1_H_ ////////////////////////////////////////////////////////////////////////// // Usage (in your .c file): // 1. define Tx pin: DDR register, PORT register, PIN number: // #define Soft_UART_TX_PORT PORTD // #define Soft_UART_TX_DDR DDRD // #define Soft_UART_TX_PIN 3 // 2. define UART speed // #define Soft_UART_Baud 9600 // 3. include .h file: // #include "Soft_UART_Timer1.h" // 3. initialize software UART, required to call before usage other functions: // static void Soft_UART_init(void); // 4. send byte // static void Soft_UART_send_byte(char byte); // this function send byte in background, // only one byte in background, other will wait. ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // From this line begins code to the end of file. // All code written in .h file for better inline optimization. // Try to include this file only once per project. ////////////////////////////////////////////////////////////////////////// volatile char Soft_UART_busy_flag=0; char Soft_UART_next_byte=0; ////////////////////////////////////////////////////////////////////////// // Initialization software UART, required to call before usage ////////////////////////////////////////////////////////////////////////// static void Soft_UART_init(void) { // Pin init bit_set(Soft_UART_TX_DDR,Soft_UART_TX_PIN); bit_set(Soft_UART_TX_PORT,Soft_UART_TX_PIN); // Timer1 init TCCR1A=(0<