Rev 743 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
// ********************************************************
// ** Spektrum DX7(se) Expander for 12 Channels at large **
// ********************************************************
// ** Target: Atmel ATtiny2313 with delivered standard **
// ** Fuses (internal RC-Oscillator @ 1 MHz) **
// ********************************************************
// ** It sends data from 6 additionally switches over **
// ** the tripole "FLAP" channel which the FlightControl **
// ** can decode "on the fly" :) **
// ********************************************************
// ** (c) 2009-0xFFFF Stefan Pendsa **
// ** License: don't know - use it and have fun **
// ********************************************************
#include <avr/io.h>
#define TX_High PORTA |= 1 << PORTA0 // Set TX-Pin High
#define TX_Low PORTA &= ~(1 << PORTA0) // Set TX-Pin Low
#define SYNC_High PORTA |= 1 << PORTA1 // Set Sync-Pin High
#define SYNC_Low PORTA &= ~(1 << PORTA1) // Set Sync-Pin Low
void Send(char sync, char data)
{
if (sync == 0) SYNC_High; else SYNC_Low; // Send Sync
if (data == 0) TX_High; else TX_Low; // Send Data
while ( PIND & (1<<PD5) ); // Wait for DX7-Sync goes low
while ( !(PIND & (1 << PD5)) ); // Wait for DX7-Sync goes high
}
int main(void)
{
char i,Parity; // Bit-Counter and Parity Bit
DDRA = 0b011; // PORT A INPUT: RESET; OUTPUT: Sync+Data
DDRB = 0b00000000; // PORT B INPUT: Jumper for Bypass
DDRD = 0b0000000; // PORT D INPUT: Switches + DX7-Sync
PORTA = 0b111; // Pull-Up for /RESET, High for Sync+Data
PORTB = 0b01000000; // Pull-Up for Jumper
PORTD = 0b1011111; // Pull-Up for Switches
while(1) // Main-Loop (Sending data all the time)
{
if (!(PINB & (1<<PINB6))) // By-Pass Mode
{
if (PIND & (1<<PIND0)) PORTA |= 1 << PORTA1; // A1=D0
else PORTA &= ~(1 << PORTA1);
if (PIND & (1<<PIND1)) PORTA |= 1 << PORTA0; // A0=D1
else PORTA &= ~(1 << PORTA0);
}
else // Normal Mode
{
Parity = 0; // Reset Parity Bit
Send(1,0); // Send SYNC Pulse
i=0;
while (i<7) // Encode PD0-PD4 + PD6
{
if (PIND & (1<<i)) // Check Pin #i
{
Send(0,0); // When High, Send Low (Switched to "0")
Parity = ~Parity; // and invert Parity Bit
}
else Send(0,1); // When Low, Send High (Switched to "1")
i++;
if (i == 5) i = 6; // Skip PD5
}
for (i=0;i<2;i++) // Encode PB0+PB1 (Hover Pitch)
{
if ((PINB & (1<<i))) // Check Pin #i
{
Send(0,0); // When High, Send Low (Switched to "0")
Parity = ~Parity; // and invert Parity Bit
}
else Send(0,1); // When Low, Send High (Switched to "1")
}
Send(0,Parity); // Send Parity Bit
}
}
}