00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <msp430x44x.h>
00017 #include <msp430/basic_clock.h>
00018 #include <msp430/system_clock.h>
00019 #include <stdarg.h>
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <sys/types.h>
00024 #include "uart.h"
00025
00026
00027
00028
00029 void UART_init (void)
00030 {
00031
00032 U1TCTL = SSEL0;
00033 U1BR0 = 0x03;
00034 U1BR1 = 0x00;
00035 U1MCTL = 0x4a;
00036 U1CTL = CHAR;
00037 ME2 = UTXE1 | URXE1;
00038 P4SEL |= BIT0 | BIT1;
00039 P4DIR |= BIT0;
00040 P4DIR &= ~BIT1;
00041
00042
00043
00044 }
00045
00046
00047
00048
00049
00050
00051 void UART_putChar (char c)
00052 {
00053 while ((IFG2 & UTXIFG1) == 0);
00054 U1TXBUF = c;
00055 }
00056
00057
00058
00059
00060
00061
00062 char UART_getCharIsReady ()
00063 {
00064 return (IFG2 & URXIFG1) != 0;
00065 }
00066
00067
00068
00069
00070
00071
00072 char UART_getChar ()
00073 {
00074 while (!UART_getCharIsReady ());
00075 return U1RXBUF;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 void UART_write (const char *buf, int length)
00085 {
00086 int i;
00087 for (i = 0; i < length; i++)
00088 {
00089 UART_putChar (buf[i]);
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 void UART_printf (const char *fmt, ...)
00103 {
00104 static va_list valist;
00105 char buf[UART_PRINTF_BUF_SIZE];
00106
00107 va_start (valist, fmt);
00108 vsnprintf (buf, sizeof (buf), fmt, valist);
00109 va_end (valist);
00110 UART_write (buf, strlen (buf));
00111 }