summaryrefslogtreecommitdiff
path: root/n/avr/adc/test_adc.c
blob: 11a551d800d468d5ec9bba17dd7db8316a414ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* test_adc.c */
/*  {{{
 *
 * Copyright (C) 2005 Thomas Burg
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Contact :
 *      Email: <burg@efrei.fr>
 * }}} */
#include <n/avr/proto/proto.h>
#include <n/avr/rs232/rs232.h>
#include <n/avr/utils/utils.h>

#include "adc.h"

/* +AutoDec */
/* -AutoDec */

uint8_t go;

void
proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
{
    switch (cmd)
    {
	case 'z':
	    reset ();
	    break;
	case 'm':
	    go = 1;
	    break;
    }
    proto_send (cmd, size, args);
}

void
proto_putc (uint8_t c)
{
    rs232_putc (c);
}

int
main (void)
{
    uint16_t adc0 =0 ;
    uint16_t adc1 =0 ;
    uint16_t adc2 =0 ;
    go = 0;
    rs232_init ();
    proto_send0 ('z');

    while (!go)
    {
	if (rs232_poll ())
	    proto_accept (rs232_getc ());
    }
   
    adc_init();
    while (1)
      {
        delay_ms (100L);
	/* D�marre une acquisition de mesure sur l'adc 0 */
	adc_start(0x00);
	
	/* Attente active sur adc jusqu'a ce que la valeur soit disponible
	 * */
	while (adc_checkf() !=0)
	  {
	    rs232_putc ('0');
	  }
	/*lit l'adc 
	 */
	adc0 = adc_read();

	
	/* D�marre une acquisition de mesure sur l'adc 1 */
	adc_start(0x01);
	
	/* Attente active sur adc jusqu'a ce que la valeur soit disponible
	 * */
	while (adc_checkf() !=0)
	  {
	    rs232_putc ('1');
	  }
	
	adc1 = adc_read();
	/* D�marre une acquisition de mesure sur l'adc 2 */
	adc_start(0x02);
	
	/* Attente active sur adc jusqu'a ce que la valeur soit disponible
	 * */
	while (adc_checkf() !=0)
	  {
	    rs232_putc ('2');
	  }
	adc2 = adc_read();
	
	/*Lit la valeur puis l'envoit */
	proto_send3w('m',adc0,adc1,adc2);
	if (rs232_poll ())
	    proto_accept (rs232_getc ());
      }
    
    return 0;
}