Hallo,
das Programm soll dazu dienen die Mittelstellung von 2 Servos zu finden.
Dabei soll mit Taster 1 der OCR1B Wert für Servo 1 erhöht werden und mit
Taster2 soll der OCR1B Wert für das 2. Servo erhöht werden.
Es soll nur ein Timer verwendet werden.
Der Wert soll dann auf dem LCD Display ausgegeben werden.
Das Problem ist jedoch das ich garnix auf dem Display sehe außer halt
den schwarzen Balken.
Bin mir auch nicht sicher ob das Programm ansonsten funktioniert.
1 | #include <avr/io.h>
|
2 | #include "lcd-routines.h"
|
3 | #include <stdlib.h>
|
4 | #include <avr/interrupt.h>
|
5 | #define F_CPU 8000000
|
6 | #include <util/delay.h>
|
7 |
|
8 |
|
9 | int Wert1;
|
10 | int Wert2;
|
11 | #define AnzSer 2
|
12 | #define cycl 20000/ AnzSer
|
13 | #define min 750
|
14 | #define max 2100
|
15 | uint16_t ServoSpeed = (min+max)/2;
|
16 | uint16_t ServoSpeed2 = (min+max)/3;
|
17 | uint8_t z;
|
18 |
|
19 |
|
20 | void init (void)
|
21 | {
|
22 | DDRD = 0b00000001;
|
23 | PORTD = 0b11111110;
|
24 |
|
25 | DDRC = 0b00000001;
|
26 |
|
27 |
|
28 | TCCR1B = (1<<CS11) | (1<<WGM12);
|
29 | OCR1A = cycl;
|
30 |
|
31 | TIMSK = (1<<OCIE1A) | (1<< OCIE1B);
|
32 |
|
33 | sei();
|
34 |
|
35 | }
|
36 |
|
37 |
|
38 | ISR(TIMER1_COMPA_vect)
|
39 | {
|
40 | if (z == 1)
|
41 | {
|
42 | PORTD |= (1<<PD0);
|
43 | OCR1B = ServoSpeed;
|
44 | Wert1 = OCR1B;
|
45 | }
|
46 |
|
47 |
|
48 | if (z == 2)
|
49 | {
|
50 | PORTC |= (1<<PC0);
|
51 | OCR1B = ServoSpeed2;
|
52 | Wert2 = OCR1B;
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | ISR(TIMER1_COMPB_vect)
|
60 | {
|
61 | PORTD &= ~(1<<PD0);
|
62 | PORTC &= ~(1<<PC0);
|
63 |
|
64 | z ++;
|
65 |
|
66 | if (z>AnzSer)
|
67 | {
|
68 | z=1;
|
69 | }
|
70 | }
|
71 |
|
72 |
|
73 | int main (void)
|
74 | {
|
75 | init();
|
76 |
|
77 | while (1)
|
78 | {
|
79 |
|
80 | if (!(PIND & (1<<PD2)))
|
81 | {
|
82 | ServoSpeed ++;
|
83 | _delay_ms(1);
|
84 |
|
85 | }
|
86 |
|
87 |
|
88 | if (!(PIND & (1<<PD3)))
|
89 | {
|
90 | ServoSpeed2 ++;
|
91 | _delay_ms(1);
|
92 | }
|
93 |
|
94 |
|
95 | set_cursor(0,1);
|
96 | lcd_string("Ser.1 = ");
|
97 |
|
98 | set_cursor(9,1);
|
99 |
|
100 |
|
101 | {
|
102 | char Buffer[20];
|
103 | itoa( Wert1, Buffer, 10 );
|
104 |
|
105 | lcd_string( Buffer );
|
106 | }
|
107 |
|
108 |
|
109 | set_cursor(0,2);
|
110 | lcd_string("Ser.2 = ");
|
111 |
|
112 | set_cursor(9,2);
|
113 |
|
114 |
|
115 | {
|
116 | char Buffer[20];
|
117 | itoa( Wert2, Buffer, 10 );
|
118 |
|
119 | lcd_string( Buffer );
|
120 | }
|
121 |
|
122 | }
|
123 |
|
124 | return 0;
|
125 | }
|
PS: Soll ich das Programm das nächste Mal als Anhang machen oder ist das
so ok?