main.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00027 #include "single_wire_UART.h"
00028 #include <ioavr.h>
00029 #include <inavr.h>
00030 
00031 #define RECEIVED_DATA_SIZE  8
00032 
00033 void Print_String(char* str);
00034 
00042 void Print_String(char* str)
00043 {
00044   while( *str != '\0' )
00045   {
00046     if( !READ_FLAG(SW_UART_status, SW_UART_TX_BUFFER_FULL) )
00047     {
00048       SW_UART_Transmit((uint8_t) *str++);
00049     }
00050     if( READ_FLAG(SW_UART_status, SW_UART_FRAME_ERROR) )
00051     {
00052       PORTB = 0xF0;
00053       for(;;){}
00054     }
00055   }
00056 }
00057 
00065 int main( void )
00066 {
00067   __enable_interrupt();   
00068   SW_UART_Enable();
00069   DDRB = 0xFF;
00070   PORTB = 0xFF;
00071   uint8_t received_data[RECEIVED_DATA_SIZE];
00072   uint8_t i;
00073   for(i=0;i<RECEIVED_DATA_SIZE;i++)
00074   {
00075     received_data[i] = 0; 
00076   }
00077   i=0;
00078 
00079   //Print_String("Test Program\n\r");
00080   for(;;)
00081   {
00082     if( READ_FLAG(SW_UART_status, SW_UART_RX_BUFFER_OVERFLOW))      
00083     {
00084       PORTB = 0x0F;
00085       for(;;){}
00086     }
00087     if( READ_FLAG(SW_UART_status, SW_UART_FRAME_ERROR) )
00088     {
00089       PORTB = 0xF0;
00090       for(;;){}
00091     }
00092     while( (!READ_FLAG(SW_UART_status, SW_UART_RX_BUFFER_FULL)) ){} 
00093       
00094     received_data[i] = SW_UART_Receive();
00095     i++;
00096     if( (i >= RECEIVED_DATA_SIZE-1) || (received_data[i-1] == 0x0D) ) 
00097     {
00098       received_data[i] = '\0';
00099       Print_String(((char *) received_data));    
00100       i = 0;
00101     } 
00102   }
00103 }

Generated on Mon Apr 23 10:13:57 2007 for AVR274: Single-wire Software UART by  doxygen 1.5.1-p1