1 | //ATMEGA32
|
2 | //Quarz 16MHz
|
3 | //WinAVR
|
4 |
|
5 |
|
6 | #include <avr/io.h>
|
7 | #include <avr/interrupt.h>
|
8 |
|
9 |
|
10 | typedef unsigned char BYTE;
|
11 | typedef unsigned short WORD;
|
12 |
|
13 |
|
14 | void Port_Initial(void); //Port als Ausgang initialsieren
|
15 | WORD ReadADPort(unsigned char port) ; //AD-Wandler lesen
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | int main(void)
|
21 | {
|
22 |
|
23 | typedef unsigned short WORD;
|
24 | WORD intADW0;
|
25 | WORD intADW1;
|
26 |
|
27 |
|
28 | Port_Initial();
|
29 |
|
30 |
|
31 | while (1)
|
32 | {
|
33 |
|
34 | intADW0 = ReadADPort(0);
|
35 | intADW1 = ReadADPort(1);
|
36 |
|
37 | PORTB = intADW0;
|
38 | }
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | void Port_Initial(void) //Ausgabeport wird konfiguriert
|
44 | {
|
45 | DDRB = 0xff; //Port B als Ausgang
|
46 | DDRA = 0x00; //Port A als Eingang
|
47 | }
|
48 |
|
49 |
|
50 | WORD ReadADPort(unsigned char port)
|
51 | {
|
52 |
|
53 | WORD intValHL;
|
54 |
|
55 | ADMUX = port;
|
56 | ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADIF); //Wandlung starten
|
57 | while ( ADCSRA & (1<<ADSC) );
|
58 |
|
59 |
|
60 | intValHL = ADC;
|
61 | return intValHL;
|
62 | }
|