hostsim test
[aversive.git] / modules / comm / uart / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: main.c,v 1.15.10.5 2008-12-27 16:29:08 zer0 Exp $
19  *
20  */
21 #include <uart.h>
22 #include <aversive/wait.h>
23
24 #include <stdio.h>
25
26 #include <avr/io.h>
27 #include <avr/pgmspace.h>
28
29 /*
30  * This code sends a counter value to uart.
31  */
32 int main(void)
33 {  
34         int i;
35
36         /* initialize uart with the default parameters ( see
37          * uart_config.h ) */
38         uart_init();  
39  
40         /* enable interrupts */
41         sei();
42
43         /* send some single characters */
44         for (i=0; i<10; i++) {
45                 uart_send(0, 'x');
46                 uart_send(0, '0' + i);
47                 wait_ms(100);
48         }
49         uart_send(0, '\n');
50   
51         /* now we want to do a printf : we must register the
52          * uart0_send as stdout. Here no receive function is
53          * specified. */
54         fdevopen(uart0_dev_send, NULL);
55   
56         /** ready to do a nice printf on the uart */
57         printf("Uart is cool !!\n");
58   
59         /* one drawback of the previous printf is that the format
60          * chain is srored in RAM and this can take a huge size if
61          * there are many printf. To avoid this problem, please use
62          * printf_P together with PSTR, like in the next example. */ 
63         while (1) {
64                 printf_P(PSTR("This format string takes no RAM "
65                               "space. %i\n"), i++);
66                 wait_ms(1000);
67         }
68   
69         return 0;
70 }