Hallo, ich bin neueinsteiger in avr und hab mir eine atmega32 16PU grundschaltung aufgebaut. Der uC steuert erfollgreich ein LCD an. Jedoch Spinnen die Pins?!?! Im Quellcod Schalte ich zum beispiel den PortA auf 0b0000001 jedoch gibt jetzt nicht nur PA0 2,5V sondern alle anderen auch eine geringe Spannung zwischen 0,8V-0,16V aus. Das sollte doch nicht so sein oder? Hier der Quellcode:
1 | int main(void) |
2 | {
|
3 | DDRA = 0b0000000; //Port D als Ausgang |
4 | DDRC = 0b0000000; //Port C als Ausgang |
5 | DDRD &=~ (0 << PD7); DDRD &=~ (0 << PD6); DDRD &=~ (0 << PD5); DDRD &=~ (0 << PD4); //PortD7-4 Ausgang |
6 | DDRD &=~ (1 << PD2); DDRD &=~ (1 << PD3);//PortD2-3 Eingang |
7 | |
8 | PORTA = 0b0000000;//Auf 0 |
9 | PORTC = 0b0000000;// Auf 0 |
10 | PORTD = (1 << PD7) | (0 << PD6) | (0 << PD5) | (0 << PD4); |
11 | PORTD |= (1 << PD2); PORTD |= (1 << PD3); |
12 | |
13 | lcd_init(LCD_DISP_ON); |
14 | for (;;) |
15 | {
|
16 | |
17 | PORTA = 0b0000001;//Auf 0 |
18 | out("A0000001"); |
19 | PORTA = 0b0000010;//Auf 0 |
20 | out("A0000010"); |
21 | PORTA = 0b0000100;//Auf 0 |
22 | out("A0000100"); |
23 | PORTA = 0b0001000;//Auf 0 |
24 | out("A0001000"); |
25 | PORTA = 0b0010000;//Auf 0 |
26 | out("A0010000"); |
27 | PORTA = 0b0100000;//Auf 0 |
28 | out("A0100000"); |
29 | PORTA = 0b1000000;//Auf 0 |
30 | out("A1000000"); |
31 | PORTA = 0b0000000; |
32 | |
33 | PORTB = 0b0000001;//Auf 0 |
34 | out("B0000001"); |
35 | PORTB = 0b0000010;//Auf 0 |
36 | out("B0000010"); |
37 | PORTB = 0b0000100;//Auf 0 |
38 | out("B0000100"); |
39 | PORTB = 0b0001000;//Auf 0 |
40 | out("B0001000"); |
41 | PORTB = 0b0010000;//Auf 0 |
42 | out("B0010000"); |
43 | PORTB = 0b0100000;//Auf 0 |
44 | out("B0100000"); |
45 | PORTB = 0b1000000;//Auf 0 |
46 | out("B1000000"); |
47 | PORTB = 0b0000000; |
48 | out("Ende"); |
49 | }
|
50 | }
|
51 | |
52 | |
53 | |
54 | void wait_until_key_pressed(void) |
55 | {
|
56 | unsigned char temp1, temp2; |
57 | unsigned int i; |
58 | |
59 | do { |
60 | temp1 = PIND; // read input |
61 | for(i=0;i<65535;i++); |
62 | temp2 = PIND; // read input |
63 | temp1 = (temp1 & temp2); // debounce input |
64 | } while ( temp1 & _BV(PIND2) ); |
65 | |
66 | loop_until_bit_is_set(PIND,PIND2); /* wait until key is released */ |
67 | }
|
68 | |
69 | void out (const char *s) |
70 | {
|
71 | lcd_clrscr(); |
72 | register char c; |
73 | |
74 | while ( (c = *s++) ) { |
75 | lcd_putc(c); |
76 | }
|
77 | wait_until_key_pressed(); |
78 | }
|
MfG Peter