Rev 541 | Rev 543 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 541 | Rev 542 | ||
---|---|---|---|
1 | // ******************************************************** |
1 | // ******************************************************** |
2 | // ** Spektrum DX7(se) Expander for 10 Channels at large ** |
2 | // ** Spektrum DX7(se) Expander for 10 Channels at large ** |
3 | // ******************************************************** |
3 | // ******************************************************** |
4 | // ** Target: Atmel ATtiny2313 with delivered standard ** |
4 | // ** Target: Atmel ATtiny2313 with delivered standard ** |
5 | // ** Fuses (internal RC-Oscillator @ 1 MHz) ** |
5 | // ** Fuses (internal RC-Oscillator @ 1 MHz) ** |
6 | // ******************************************************** |
6 | // ******************************************************** |
7 | // ** It sends data from 4 additionally switches over ** |
7 | // ** It sends data from 4 additionally switches over ** |
8 | // ** the tripole "FLAP" channel which the FlightControl ** |
8 | // ** the tripole "FLAP" channel which the FlightControl ** |
9 | // ** can decode "on the fly" :) ** |
9 | // ** can decode "on the fly" :) ** |
10 | // ******************************************************** |
10 | // ******************************************************** |
11 | // ** (c) 2009-0xFFFF Stefan Pendsa ** |
11 | // ** (c) 2009-0xFFFF Stefan Pendsa ** |
12 | // ** License: don't know - use it and have fun ** |
12 | // ** License: don't know - use it and have fun ** |
13 | // ******************************************************** |
13 | // ******************************************************** |
14 | 14 | ||
15 | 15 | ||
16 | #include <avr/io.h> |
16 | #include <avr/io.h> |
17 | 17 | ||
18 | #define TX_High PORTA |= 1 << PORTA0 // Set TX-Pin High |
18 | #define TX_High PORTA |= 1 << PORTA0 // Set TX-Pin High |
19 | #define TX_Low PORTA &= ~(1 << PORTA0) // Set TX-Pin Low |
19 | #define TX_Low PORTA &= ~(1 << PORTA0) // Set TX-Pin Low |
20 | #define SYNC_High PORTA |= 1 << PORTA1 // Set Sync-Pin High |
20 | #define SYNC_High PORTA |= 1 << PORTA1 // Set Sync-Pin High |
21 | #define SYNC_Low PORTA &= ~(1 << PORTA1) // Set Sync-Pin Low |
21 | #define SYNC_Low PORTA &= ~(1 << PORTA1) // Set Sync-Pin Low |
22 | 22 | ||
23 | 23 | ||
24 | 24 | ||
25 | void Send(char sync, char data) |
25 | void Send(char sync, char data) |
26 | { |
26 | { |
27 | if (sync == 0) SYNC_High; else SYNC_Low; // Send Sync |
27 | if (sync == 0) SYNC_High; else SYNC_Low; // Send Sync |
28 | if (data == 0) TX_High; else TX_Low; // Send Data |
28 | if (data == 0) TX_High; else TX_Low; // Send Data |
29 | while ( PIND & (1<<PD5) ); // Wait for DX7-Sync goes low |
29 | while ( PIND & (1<<PD5) ); // Wait for DX7-Sync goes low |
30 | while ( !(PIND & (1 << PD5)) ); // Wait for DX7-Sync goes high |
30 | while ( !(PIND & (1 << PD5)) ); // Wait for DX7-Sync goes high |
31 | } |
31 | } |
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | int main(void) |
35 | int main(void) |
36 | { |
36 | { |
37 | char i,Parity; // Bit-Counter and Parity Bit |
37 | char i,Parity; // Bit-Counter and Parity Bit |
38 | DDRA = 0b011; // PORT A INPUT: RESET; OUTPUT: Sync+Data |
38 | DDRA = 0b011; // PORT A INPUT: /RESET; OUTPUT: Sync+Data |
39 | DDRD = 0b0000000; // PORT D INPUT: Switches + DX7-Sync |
39 | DDRD = 0b0000000; // PORT D INPUT: Switches + DX7-Sync |
40 | PORTA = 0b111; // Pull-Up for /RESET, High for Sync+Data |
40 | PORTA = 0b111; // Pull-Up for /RESET, High for Sync+Data |
41 | PORTD = 0b0011111; // Pull-Up for Switches |
41 | PORTD = 0b0011111; // Pull-Up for Switches |
42 | 42 | ||
43 | while(1) // Main-Loop (Sending data all the time) |
43 | while(1) // Main-Loop (Sending data all the time) |
44 | { |
44 | { |
45 | Parity = 0; // Reset Parity Bit |
45 | Parity = 0; // Reset Parity Bit |
46 | Send(1,0); // Send SYNC Pulse |
46 | Send(1,0); // Send SYNC Pulse |
47 | 47 | ||
48 | for (i=0;i<5;i++) // Encode the first five Port Pins |
48 | for (i=0;i<5;i++) // Encode the first five Port Pins |
49 | { |
49 | { |
50 | if (PIND & (1<<i)) // Check Pin #i |
50 | if (PIND & (1<<i)) // Check Pin #i |
51 | { |
51 | { |
52 | Send(0,0); // When High, Send Low (Switched to "0") |
52 | Send(0,0); // When High, Send Low (Switched to "0") |
53 | Parity = ~Parity; // and invert Parity Bit |
53 | Parity = ~Parity; // and invert Parity Bit |
54 | } |
54 | } |
55 | else |
55 | else |
56 | { |
56 | { |
57 | Send(0,1); // When Low, Send High (Switched to "1") |
57 | Send(0,1); // When Low, Send High (Switched to "1") |
58 | } |
58 | } |
59 | } |
59 | } |
60 | 60 | ||
61 | Send(0,Parity); // Send Parity Bit |
61 | Send(0,Parity); // Send Parity Bit |
62 | } |
62 | } |
63 | 63 | ||
64 | } |
64 | } |
65 | 65 |