Rev 976 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 976 | Rev 977 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | #include "main.h" |
4 | #include "main.h" |
Line 5... | Line 5... | ||
5 | 5 | ||
6 | volatile unsigned char twi_state = 0; |
6 | volatile unsigned char twi_state = 0; |
7 | unsigned char motor = 0; |
7 | unsigned char motor = 0; |
8 | unsigned char motorread = 0; |
8 | unsigned char motorread = 0; |
Line 9... | Line 9... | ||
9 | unsigned char motor_rx[8]; |
9 | unsigned char motor_rx[MOTOR_COUNT*2]; |
10 | 10 | ||
11 | //############################################################################ |
11 | //############################################################################ |
12 | //Initzialisieren der I2C (TWI) Schnittstelle |
12 | //Initzialisieren der I2C (TWI) Schnittstelle |
Line 74... | Line 74... | ||
74 | { |
74 | { |
75 | case 0: |
75 | case 0: |
76 | i2c_write_byte(0x52+(motor*2)); |
76 | i2c_write_byte(0x52+(motor*2)); |
77 | break; |
77 | break; |
78 | case 1: |
78 | case 1: |
- | 79 | #ifdef HEXAKOPTER |
|
- | 80 | switch(motor++) |
|
- | 81 | { |
|
- | 82 | case 0: |
|
- | 83 | i2c_write_byte(Motor_VorneLinks); |
|
- | 84 | break; |
|
- | 85 | case 1: |
|
- | 86 | i2c_write_byte(Motor_HintenRechts); |
|
- | 87 | break; |
|
- | 88 | case 2: |
|
- | 89 | i2c_write_byte(Motor_VorneRechts); |
|
- | 90 | break; |
|
- | 91 | case 3: |
|
- | 92 | i2c_write_byte(Motor_HintenLinks); |
|
- | 93 | break; |
|
- | 94 | case 4: |
|
- | 95 | i2c_write_byte(Motor_Rechts); |
|
- | 96 | break; |
|
- | 97 | case 5: |
|
- | 98 | i2c_write_byte(Motor_Links); |
|
- | 99 | break; |
|
- | 100 | } |
|
- | 101 | #else |
|
79 | switch(motor++) |
102 | switch(motor++) |
80 | { |
103 | { |
81 | case 0: |
104 | case 0: |
82 | i2c_write_byte(Motor_Vorne); |
105 | i2c_write_byte(Motor_Vorne); |
83 | break; |
106 | break; |
Line 89... | Line 112... | ||
89 | break; |
112 | break; |
90 | case 3: |
113 | case 3: |
91 | i2c_write_byte(Motor_Links); |
114 | i2c_write_byte(Motor_Links); |
92 | break; |
115 | break; |
93 | } |
116 | } |
- | 117 | #endif |
|
94 | break; |
118 | break; |
95 | case 2: |
119 | case 2: |
96 | i2c_stop(); |
120 | i2c_stop(); |
97 | if (motor<4) twi_state = 0; |
121 | if (motor<MOTOR_COUNT) twi_state = 0; |
98 | else motor = 0; |
122 | else motor = 0; |
99 | i2c_start(); |
123 | i2c_start(); |
100 | break; |
124 | break; |
Line 101... | Line 125... | ||
101 | 125 | ||
102 | //Liest Daten von Motor |
126 | //Liest Daten von Motor |
103 | case 3: |
127 | case 3: |
104 | i2c_write_byte(0x53+(motorread*2)); |
128 | i2c_write_byte(0x53+(motorread*2)); |
105 | break; |
129 | break; |
106 | case 4: |
- | |
107 | switch(motorread) |
- | |
108 | { |
- | |
109 | case 0: |
- | |
110 | i2c_write_byte(Motor_Vorne); |
- | |
111 | break; |
- | |
112 | case 1: |
130 | case 4: |
113 | i2c_write_byte(Motor_Hinten); |
- | |
114 | break; |
- | |
115 | case 2: |
- | |
116 | i2c_write_byte(Motor_Rechts); |
- | |
117 | break; |
- | |
118 | case 3: |
- | |
119 | i2c_write_byte(Motor_Links); |
- | |
120 | break; |
- | |
121 | } |
131 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA); |
122 | break; |
132 | break; |
123 | case 5: //1 Byte vom Motor lesen |
133 | case 5: //1 Byte vom Motor lesen |
Line 124... | Line 134... | ||
124 | motor_rx[motorread] = TWDR; |
134 | motor_rx[motorread] = TWDR; |
125 | - | ||
126 | case 6: |
- | |
127 | switch(motorread) |
- | |
128 | { |
- | |
129 | case 0: |
- | |
130 | i2c_write_byte(Motor_Vorne); |
- | |
131 | break; |
135 | |
132 | case 1: |
- | |
133 | i2c_write_byte(Motor_Hinten); |
- | |
134 | break; |
- | |
135 | case 2: |
- | |
136 | i2c_write_byte(Motor_Rechts); |
- | |
137 | break; |
- | |
138 | case 3: |
- | |
139 | i2c_write_byte(Motor_Links); |
- | |
140 | break; |
136 | case 6: |
141 | } |
137 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE); |
142 | break; |
138 | break; |
143 | case 7: //2 Byte vom Motor lesen |
139 | case 7: //2 Byte vom Motor lesen |
144 | motor_rx[motorread+4] = TWDR; |
140 | motor_rx[motorread+MOTOR_COUNT] = TWDR; |
145 | motorread++; |
141 | motorread++; |
146 | if (motorread>3) motorread=0; |
142 | if (motorread>=MOTOR_COUNT) motorread=0; |
147 | i2c_stop(); |
143 | i2c_stop(); |
148 | I2CTimeout = 10; |
144 | I2CTimeout = 10; |
149 | twi_state = 0; |
145 | twi_state = 0; |