Hallo mal eine Frage, wenn ich den ADC des ATmega 16 verwendne möchte und der Debugger zurückgibt, dass das Register ADCSRA nicht gefunden wird, kann das daran liegen, dass ich PortA nicht als Eingang (0x00) definiert habe? Ist das notwendig oder warum wird das Register nicht erkannt: Hier der C-Code fehlt da noch was?
1 | #define F_CPU 4000000UL
|
2 | #include <avr/io.h> |
3 | #include <stdio.h> |
4 | #include <avr/interrupt.h> |
5 | #include <util/delay.h> |
6 | |
7 | |
8 | int main(void) |
9 | {
|
10 | |
11 | DDRB = 0xFF; |
12 | unsigned char i; |
13 | |
14 | LCD_init(); |
15 | |
16 | |
17 | //Configure ADC
|
18 | //Enable interrupts function in ADC
|
19 | //8-Bit or 10-Bit results
|
20 | //1,000,000/50,000 =100/5=20 1,000,000/200,000 = 10/2 =5
|
21 | ADCSRA |= 1<<ADPS2; |
22 | ADMUX |= 1<<ADLAR; |
23 | ADCSRA |= 1<<ADIE; |
24 | ADMUX |= 1<<REFS0; |
25 | //Enable a prescaler-determine by the internal/external clock
|
26 | |
27 | //Turn on the ADC feature
|
28 | ADCSAR |= 1<<ADEN; |
29 | //Enable the global interrupts
|
30 | sei(); |
31 | //Start the first conversion
|
32 | |
33 | ADCSRA |= 1<<ADSC; |
34 | |
35 | |
36 | |
37 | while(1) |
38 | {
|
39 | //for(i=0;i<2;i++)
|
40 | LCD_blink(); |
41 | |
42 | //PORTB = 0xFF;
|
43 | //_delay_us(1000);
|
44 | //PORTB = 0x00;
|
45 | //_delay_us(1000);
|
46 | |
47 | //for(i=0;i<15;i++)
|
48 | //LCD_scroll(0);
|
49 | |
50 | //for(i=0;i<4;i++)
|
51 | //LCD_scroll(1);
|
52 | |
53 | //for(i=0;i<2;i++)
|
54 | //LCD_scroll(0);
|
55 | }
|
56 | }
|
57 | |
58 | |
59 | // Add the interrupt routine and display the results
|
60 | ISR(ADC_vect) |
61 | {
|
62 | //LCD String variable declaration
|
63 | char adcResult[4]; |
64 | itoa(ADCH, adcResult, 10); |
65 | |
66 | |
67 | //Convert the ADC Conversion result
|
68 | //Select a location on the LCD to display the number
|
69 | LCD_goto(1,1); |
70 | //Display the string on the LCD
|
71 | //LCD_send_string(adcResult);
|
72 | LCD_send_command(adcResult); |
73 | |
74 | |
75 | ADCSRA |= 1<<ADSC; |
76 | |
77 | }
|
78 | void LCD_init() |
79 | {
|
80 | LCD_CNTRL_DDR = 0xFF; |
81 | LCD_CNTRL_PORT = 0x00; |
82 | LCD_DATA_DDR = 0xFF; |
83 | LCD_DATA_PORT = 0x00; |
84 | |
85 | _delay_ms(50); |
86 | //LCD_send_command(0x38);
|
87 | //LCD_send_command(0x0C);
|
88 | LCD_send_command(0x01); |
89 | //LCD_send_command(0x0E);
|
90 | _delay_ms(1000); |
91 | LCD_send_command(0x14); |
92 | LCD_send_command(0x0F); |
93 | //LCD_send_command(0x01);
|
94 | //_delay_ms(10);
|
95 | LCD_send_command(0xFF); |
96 | |
97 | //LCD_send_command(0x06);
|
98 | |
99 | }
|
100 | |
101 | void LCD_goto(unsigned char y, unsigned char x) |
102 | {
|
103 | unsigned char firstAddress[] = {0x80,0xC0,0x94,0xD4}; |
104 | |
105 | LCD_send_command(firstAddress[y-1] + x-1); |
106 | _delay_ms(10); |
107 | }
|