Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | //***************************************************************************** |
2 | // File Name : a2dtest.c |
||
3 | // |
||
4 | // Title : example usage of some avr library functions |
||
5 | // Revision : 1.0 |
||
6 | // Notes : |
||
7 | // Target MCU : Atmel AVR series |
||
8 | // Editor Tabs : 4 |
||
9 | // |
||
10 | // Revision History: |
||
11 | // When Who Description of change |
||
12 | // ----------- ----------- ----------------------- |
||
13 | // 20-Oct-2002 pstang Created the program |
||
14 | //***************************************************************************** |
||
15 | |||
16 | //----- Include Files --------------------------------------------------------- |
||
17 | #include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
||
18 | #include <avr/interrupt.h> // include interrupt support |
||
19 | |||
20 | #include "global.h" // include our global settings |
||
21 | #include "uart.h" // include uart function library |
||
22 | #include "rprintf.h" // include printf function library |
||
23 | #include "timer.h" // include timer function library (timing, PWM, etc) |
||
24 | #include "a2d.h" // include A/D converter function library |
||
25 | #include "vt100.h" // include VT100 terminal support |
||
26 | |||
27 | //----- Begin Code ------------------------------------------------------------ |
||
28 | int main(void) |
||
29 | { |
||
30 | u16 a=0; |
||
31 | u08 i=0; |
||
32 | |||
33 | // initialize our libraries |
||
34 | // initialize the UART (serial port) |
||
35 | uartInit(); |
||
36 | // make all rprintf statements use uart for output |
||
37 | rprintfInit(uartSendByte); |
||
38 | // initialize the timer system |
||
39 | timerInit(); |
||
40 | // turn on and initialize A/D converter |
||
41 | a2dInit(); |
||
42 | |||
43 | // print a little intro message so we know things are working |
||
44 | vt100ClearScreen(); |
||
45 | vt100SetCursorPos(1,1); |
||
46 | rprintf("Welcome to the a2d test!\r\n"); |
||
47 | |||
48 | // configure a2d port (PORTA) as input |
||
49 | // so we can receive analog signals |
||
50 | DDRA = 0x00; |
||
51 | // make sure pull-up resistors are turned off |
||
52 | PORTA = 0x00; |
||
53 | |||
54 | // set the a2d prescaler (clock division ratio) |
||
55 | // - a lower prescale setting will make the a2d converter go faster |
||
56 | // - a higher setting will make it go slower but the measurements |
||
57 | // will be more accurate |
||
58 | // - other allowed prescale values can be found in a2d.h |
||
59 | a2dSetPrescaler(ADC_PRESCALE_DIV32); |
||
60 | |||
61 | // set the a2d reference |
||
62 | // - the reference is the voltage against which a2d measurements are made |
||
63 | // - other allowed reference values can be found in a2d.h |
||
64 | a2dSetReference(ADC_REFERENCE_AVCC); |
||
65 | |||
66 | // use a2dConvert8bit(channel#) to get an 8bit a2d reading |
||
67 | // use a2dConvert10bit(channel#) to get a 10bit a2d reading |
||
68 | |||
69 | while(1) |
||
70 | { |
||
71 | // sample all a2d channels and print them to the terminal |
||
72 | vt100SetCursorPos(2,1); |
||
73 | for(i=0; i<8; i++) |
||
74 | { |
||
75 | rprintf("Channel %d: %d \r\n", i, a2dConvert8bit(i)); |
||
76 | } |
||
77 | // print the sample number so far |
||
78 | rprintf("Sample # : %d \r\n", a++); |
||
79 | } |
||
80 | |||
81 | return 0; |
||
82 | } |
Powered by WebSVN v2.8.3