Rev Author Line No. Line
1145 kaklik 1 //*****************************************************************************
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 DDRC = 0x00;
51 // make sure pull-up resistors are turned off
52 PORTC = 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 u08 c=0;
72 u08 n;
73 char radka[100];
74  
75 for(n=0;n<100;n++) radka[n]=0;
76  
77 n=0;
78 while(uartReceiveByte(&c))
79 {
80 radka[n]=c;
81 n++;
82 }
83  
84 n=0;
85 while (0!=radka[n])
86 {
87 uartSendByte(radka[n]);
88 n++;
89 timerPause(31);
90 }
91  
92 /* // sample all a2d channels and print them to the terminal
93 vt100SetCursorPos(2,1);
94 for(i=0; i<6; i++)
95 {
96 rprintf("Channel %d: %d \r\n", i, a2dConvert8bit(i));
97 timerPause(1000);
98 }
99 // print the sample number so far
100 rprintf("Sample # : %d \r\n", a++);*/
101 }
102  
103 return 0;
104 }