• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

uart.c

Go to the documentation of this file.
00001 /*@{*//*@}*/
00016 
00017 /******************************************************************************/
00018 /* Includes (#include)                                                        */
00019 #include <avr/io.h>
00020 
00021 /* Own header files */
00022 #include "xtypes.h"
00023 #include "global.h"
00024 
00025 #define EXPORT
00026   #include "uart.h"
00027 #undef EXPORT
00028 
00029 /******************************************************************************/
00030 /* Constants (#define)                *//*@{*/
00031 
00033 #define BAUD_RATE 9600
00034 
00035 #if defined (__AVR_ATmega88__)
00036   #define USR   UCSR0A
00037   #define UCR   UCSR0B
00038   #define UBRR  UBRR0L
00039   #define UDRE  UDRE0
00040   #define UDR   UDR0
00041   #define RXC   RXC0
00042 #endif
00043 
00044 /* End: Constants (#define)                                             *//*@}*/
00045 /******************************************************************************/
00046 
00047 /******************************************************************************/
00048 /* Macro definitions (#define)           *//*@{*/
00049 /* End: Macro definitions (#define)                                     *//*@}*/
00050 /******************************************************************************/
00051 
00052 /******************************************************************************/
00053 /* Basic types (typedef)                 *//*@{*/
00054 /* End: Basic types (typedef)                                           *//*@}*/
00055 /******************************************************************************/
00056 
00057 /******************************************************************************/
00058 /* Local constants (const)     *//*@{*/
00059 /* End: Local constants (const)                                         *//*@}*/
00060 /******************************************************************************/
00061 
00062 /******************************************************************************/
00063 /* Local variables              *//*@{*/
00064 /* End: Local variables                                                 *//*@}*/
00065 /******************************************************************************/
00066 
00067 /******************************************************************************/
00068 /* Global variables           *//*@{*/
00069 /* End: Global variables                                                *//*@}*/
00070 /******************************************************************************/
00071 
00072 /******************************************************************************/
00073 /* Prototype declarations                                                     */
00074 /* End: Prototype declarations                                                */
00075 /******************************************************************************/
00076 
00077 /******************************************************************************/
00078 /* Local functions             *//*@{*/
00079 /* End: Local functions                                                 *//*@}*/
00080 /******************************************************************************/
00081 
00082 /******************************************************************************/
00083 /* Global functions          *//*@{*/
00084 
00085 
00086 /* ****************************************************************************/
00092 /* ****************************************************************************/
00093 void uart_PutChar (CHAR c)
00094 {
00095 #ifndef BOOTLOADER
00096   if('\n' == c)
00097   {
00098     uart_PutChar('\r');
00099   }
00100 #endif
00101   /* wait until ready to send */
00102   loop_until_bit_is_set(USR, UDRE);
00103   
00104   /* send char */
00105   UDR = c;
00106 }
00107 
00108 
00109 #if 0
00110 /* ****************************************************************************/
00116 /* ****************************************************************************/
00117 void uart_PutStr(CHAR* string)
00118 {
00119   while (*string != 0U)
00120   {
00121     uart_PutChar(*string);
00122     string++;
00123   }
00124 }
00125 #endif
00126 
00127 
00128 /* ****************************************************************************/
00134 /* ****************************************************************************/
00135 CHAR uart_GetChar(void)
00136 {
00137   CHAR c;
00138   
00139   loop_until_bit_is_set(USR, RXC);
00140   c = UDR;
00141   return (c);
00142 }
00143 
00144 
00145 /* ****************************************************************************/
00153 /* ****************************************************************************/
00154 void uart_Init (void)
00155 {
00156   RXD_DDR   &= ~(1U << RXD_BIT);  /* set RXD as input pin */
00157   TXD_DDR   |=  (1U << TXD_BIT);  /* set TXD as output pin */
00158   RXD_PORT  |=  (1U << RXD_BIT);  /* activate RXD pull-up resistor */
00159 
00160   /* Enable TXEN and RXEN in register UCR */
00161   UCR   = (1 << TXEN0)|(1 << RXEN0);
00162   
00163   /* set baudrate prescaler */
00164   UBRR  = (F_CPU / (BAUD_RATE * 16L) - 1U);
00165 }
00166 
00167 /* End: Global functions                                                *//*@}*/
00168 /******************************************************************************/
00169 
00170 /**** Last line of code                                                    ****/
00171 
00172 

Generated on Sun Jan 23 2011 14:05:40 for ULA replacement firmware by  doxygen 1.7.2