Values are better.
[goodfet] / firmware / lib / atmega168.c
1 //! MSP430F1612/1611 clock and I/O definitions
2
3 #include "platform.h"
4
5 #include <avr/io.h>
6 #include <util/delay.h>
7
8 //! Receive a byte.
9 unsigned char serial0_rx(){
10   while( !(UCSR0A & (1 << RXC0)) );
11   return UDR0;
12 }
13
14 //! Receive a byte.
15 unsigned char serial1_rx(){
16   return 0;
17 }
18
19 //! Transmit a byte.
20 void serial0_tx(unsigned char x){
21   while (!(UCSR0A & (1<<UDRE0)) );
22   UDR0 = x;
23 }
24
25 //! Transmit a byte on the second UART.
26 void serial1_tx(unsigned char x){
27 }
28
29 //! Set the baud rate.
30 void setbaud0(unsigned char rate){
31   //TODO support multiple rates.
32   #define SPEED 9600
33   
34   
35   switch(rate){
36   case 1://9600 baud
37     
38     break;
39   case 2://19200 baud
40     
41     break;
42   case 3://38400 baud
43     
44     break;
45   case 4://57600 baud
46     
47     break;
48   default:
49   case 5://115200 baud
50     
51     break;
52   }
53   
54 #define F_CPU 8000000L
55 #define BAUD 115200L
56 #include <util/setbaud.h>
57   UBRR0H = UBRRH_VALUE;
58   UBRR0L = UBRRL_VALUE;
59   
60   UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
61   UCSR0B = _BV(RXEN0) | _BV(TXEN0);
62   return;
63   
64 }
65
66 //! Set the baud rate of the second uart.
67 void setbaud1(unsigned char rate){
68   //http://mspgcc.sourceforge.net/baudrate.html
69   switch(rate){
70   case 1://9600 baud
71     
72     break;
73   case 2://19200 baud
74     
75     break;
76   case 3://38400 baud
77     
78     break;
79   case 4://57600 baud
80     
81     break;
82   default:
83   case 5://115200 baud
84     
85     break;
86   }
87 }
88
89
90 void avr_init_uart0(){
91   setbaud0(0);
92 }
93
94
95 void avr_init_uart1(){
96 }
97
98
99