Rev 743 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
535 | form | 1 | // ******************************************************** |
769 | - | 2 | // ** Spektrum DX7(se) Expander for 12 Channels at large ** |
535 | form | 3 | // ******************************************************** |
4 | // ** Target: Atmel ATtiny2313 with delivered standard ** |
||
5 | // ** Fuses (internal RC-Oscillator @ 1 MHz) ** |
||
6 | // ******************************************************** |
||
769 | - | 7 | // ** It sends data from 6 additionally switches over ** |
535 | form | 8 | // ** the tripole "FLAP" channel which the FlightControl ** |
9 | // ** can decode "on the fly" :) ** |
||
10 | // ******************************************************** |
||
11 | // ** (c) 2009-0xFFFF Stefan Pendsa ** |
||
12 | // ** License: don't know - use it and have fun ** |
||
13 | // ******************************************************** |
||
14 | |||
15 | |||
16 | #include <avr/io.h> |
||
17 | |||
18 | #define TX_High PORTA |= 1 << PORTA0 // Set TX-Pin High |
||
19 | #define TX_Low PORTA &= ~(1 << PORTA0) // Set TX-Pin Low |
||
20 | #define SYNC_High PORTA |= 1 << PORTA1 // Set Sync-Pin High |
||
21 | #define SYNC_Low PORTA &= ~(1 << PORTA1) // Set Sync-Pin Low |
||
22 | |||
23 | |||
24 | |||
25 | void Send(char sync, char data) |
||
26 | { |
||
27 | if (sync == 0) SYNC_High; else SYNC_Low; // Send Sync |
||
28 | if (data == 0) TX_High; else TX_Low; // Send Data |
||
541 | form | 29 | while ( PIND & (1<<PD5) ); // Wait for DX7-Sync goes low |
30 | while ( !(PIND & (1 << PD5)) ); // Wait for DX7-Sync goes high |
||
31 | } |
||
535 | form | 32 | |
33 | |||
34 | |||
35 | int main(void) |
||
36 | { |
||
37 | char i,Parity; // Bit-Counter and Parity Bit |
||
723 | form | 38 | DDRA = 0b011; // PORT A INPUT: RESET; OUTPUT: Sync+Data |
39 | DDRB = 0b00000000; // PORT B INPUT: Jumper for Bypass |
||
541 | form | 40 | DDRD = 0b0000000; // PORT D INPUT: Switches + DX7-Sync |
723 | form | 41 | PORTA = 0b111; // Pull-Up for /RESET, High for Sync+Data |
42 | PORTB = 0b01000000; // Pull-Up for Jumper |
||
769 | - | 43 | PORTD = 0b1011111; // Pull-Up for Switches |
535 | form | 44 | |
45 | while(1) // Main-Loop (Sending data all the time) |
||
46 | { |
||
723 | form | 47 | if (!(PINB & (1<<PINB6))) // By-Pass Mode |
48 | { |
||
49 | if (PIND & (1<<PIND0)) PORTA |= 1 << PORTA1; // A1=D0 |
||
50 | else PORTA &= ~(1 << PORTA1); |
||
535 | form | 51 | |
723 | form | 52 | if (PIND & (1<<PIND1)) PORTA |= 1 << PORTA0; // A0=D1 |
53 | else PORTA &= ~(1 << PORTA0); |
||
54 | } |
||
55 | else // Normal Mode |
||
535 | form | 56 | { |
723 | form | 57 | Parity = 0; // Reset Parity Bit |
58 | Send(1,0); // Send SYNC Pulse |
||
59 | |||
769 | - | 60 | i=0; |
61 | while (i<7) // Encode PD0-PD4 + PD6 |
||
535 | form | 62 | { |
723 | form | 63 | if (PIND & (1<<i)) // Check Pin #i |
64 | { |
||
65 | Send(0,0); // When High, Send Low (Switched to "0") |
||
66 | Parity = ~Parity; // and invert Parity Bit |
||
67 | } |
||
769 | - | 68 | else Send(0,1); // When Low, Send High (Switched to "1") |
69 | i++; |
||
70 | if (i == 5) i = 6; // Skip PD5 |
||
71 | } |
||
72 | |||
73 | for (i=0;i<2;i++) // Encode PB0+PB1 (Hover Pitch) |
||
74 | { |
||
75 | if ((PINB & (1<<i))) // Check Pin #i |
||
723 | form | 76 | { |
769 | - | 77 | Send(0,0); // When High, Send Low (Switched to "0") |
78 | Parity = ~Parity; // and invert Parity Bit |
||
723 | form | 79 | } |
769 | - | 80 | else Send(0,1); // When Low, Send High (Switched to "1") |
535 | form | 81 | } |
723 | form | 82 | |
83 | Send(0,Parity); // Send Parity Bit |
||
535 | form | 84 | } |
85 | } |
||
86 | } |